Skip to content

Commit 29e8e65

Browse files
liuhangbindavem330
authored andcommitted
net/packet: fix packet_sock xmit return value checking
packet_sock xmit could be dev_queue_xmit, which also returns negative errors. So only checking positive errors is not enough, or userspace sendmsg may return success while packet is not send out. Move the net_xmit_errno() assignment in the braces as checkpatch.pl said do not use assignment in if condition. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Flavio Leitner <[email protected]> Signed-off-by: Hangbin Liu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1a74e99 commit 29e8e65

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

net/packet/af_packet.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,8 +2858,9 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
28582858

28592859
status = TP_STATUS_SEND_REQUEST;
28602860
err = po->xmit(skb);
2861-
if (unlikely(err > 0)) {
2862-
err = net_xmit_errno(err);
2861+
if (unlikely(err != 0)) {
2862+
if (err > 0)
2863+
err = net_xmit_errno(err);
28632864
if (err && __packet_get_status(po, ph) ==
28642865
TP_STATUS_AVAILABLE) {
28652866
/* skb was destructed already */
@@ -3060,8 +3061,12 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
30603061
skb->no_fcs = 1;
30613062

30623063
err = po->xmit(skb);
3063-
if (err > 0 && (err = net_xmit_errno(err)) != 0)
3064-
goto out_unlock;
3064+
if (unlikely(err != 0)) {
3065+
if (err > 0)
3066+
err = net_xmit_errno(err);
3067+
if (err)
3068+
goto out_unlock;
3069+
}
30653070

30663071
dev_put(dev);
30673072

0 commit comments

Comments
 (0)