Patchwork [2/4] VSOCK: Return VMCI_ERROR_NO_MEM when fails to allocate skb

login
register
mail settings
Submitter Asias He
Date June 20, 2013, 9:20 a.m.
Message ID <1371720033-19714-3-git-send-email-asias@redhat.com>
Download mbox | patch
Permalink /patch/252830/
State Accepted
Delegated to: David Miller
Headers show

Comments

Asias He - June 20, 2013, 9:20 a.m.
vmci_transport_recv_dgram_cb always return VMCI_SUCESS even if we fail
to allocate skb, return VMCI_ERROR_NO_MEM instead.

Signed-off-by: Asias He <asias@redhat.com>
---
 net/vmw_vsock/vmci_transport.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
Andy King - June 20, 2013, 3:15 p.m.
> vmci_transport_recv_dgram_cb always return VMCI_SUCESS even if we fail
> to allocate skb, return VMCI_ERROR_NO_MEM instead.
> 
> Signed-off-by: Asias He <asias@redhat.com>

Acked-by: Andy King <acking@vmware.com>

Thanks!
- Andy
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c
index daff752..99b511d 100644
--- a/net/vmw_vsock/vmci_transport.c
+++ b/net/vmw_vsock/vmci_transport.c
@@ -625,13 +625,14 @@  static int vmci_transport_recv_dgram_cb(void *data, struct vmci_datagram *dg)
 
 	/* Attach the packet to the socket's receive queue as an sk_buff. */
 	skb = alloc_skb(size, GFP_ATOMIC);
-	if (skb) {
-		/* sk_receive_skb() will do a sock_put(), so hold here. */
-		sock_hold(sk);
-		skb_put(skb, size);
-		memcpy(skb->data, dg, size);
-		sk_receive_skb(sk, skb, 0);
-	}
+	if (!skb)
+		return VMCI_ERROR_NO_MEM;
+
+	/* sk_receive_skb() will do a sock_put(), so hold here. */
+	sock_hold(sk);
+	skb_put(skb, size);
+	memcpy(skb->data, dg, size);
+	sk_receive_skb(sk, skb, 0);
 
 	return VMCI_SUCCESS;
 }