]> Pileus Git - ~andy/linux/blobdiff - drivers/staging/hv/NetVsc.c
Staging: hv: test return value of osd_WaitEventCreate()
[~andy/linux] / drivers / staging / hv / NetVsc.c
index 1c717f9a554ef36cc1dd43725f54989b99db5b9f..d3154e711776a6087027e14e77b0b631846c44b4 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/mm.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <linux/slab.h>
 #include "osd.h"
 #include "logging.h"
 #include "NetVsc.h"
@@ -166,7 +167,7 @@ static struct netvsc_device *ReleaseInboundNetDevice(struct hv_device *Device)
        return netDevice;
 }
 
-/**
+/*
  * NetVscInitialize - Main entry point
  */
 int NetVscInitialize(struct hv_driver *drv)
@@ -704,7 +705,7 @@ static void NetVscDisconnectFromVsp(struct netvsc_device *NetDevice)
        DPRINT_EXIT(NETVSC);
 }
 
-/**
+/*
  * NetVscOnDeviceAdd - Callback when the device belonging to this driver is added
  */
 static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
@@ -748,6 +749,10 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
                              &netDevice->ReceivePacketList);
        }
        netDevice->ChannelInitEvent = osd_WaitEventCreate();
+       if (!netDevice->ChannelInitEvent) {
+               ret = -ENOMEM;
+               goto Cleanup;
+       }
 
        /* Open the channel */
        ret = Device->Driver->VmbusChannelInterface.Open(Device,
@@ -806,7 +811,7 @@ Cleanup:
        return ret;
 }
 
-/**
+/*
  * NetVscOnDeviceRemove - Callback when the root bus device is removed
  */
 static int NetVscOnDeviceRemove(struct hv_device *Device)
@@ -863,7 +868,7 @@ static int NetVscOnDeviceRemove(struct hv_device *Device)
        return 0;
 }
 
-/**
+/*
  * NetVscOnCleanup - Perform any cleanup when the driver is removed
  */
 static void NetVscOnCleanup(struct hv_driver *drv)
@@ -1086,7 +1091,7 @@ static void NetVscOnReceive(struct hv_device *Device,
        }
 
        /* Remove the 1st packet to represent the xfer page packet itself */
-       xferpagePacket = (struct xferpage_packet*)listHead.next;
+       xferpagePacket = (struct xferpage_packet *)listHead.next;
        list_del(&xferpagePacket->ListEntry);
 
        /* This is how much we can satisfy */
@@ -1102,7 +1107,7 @@ static void NetVscOnReceive(struct hv_device *Device,
 
        /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */
        for (i = 0; i < (count - 1); i++) {
-               netvscPacket = (struct hv_netvsc_packet*)listHead.next;
+               netvscPacket = (struct hv_netvsc_packet *)listHead.next;
                list_del(&netvscPacket->ListEntry);
 
                /* Initialize the netvsc packet */
@@ -1285,30 +1290,35 @@ static void NetVscOnReceiveCompletion(void *Context)
        DPRINT_EXIT(NETVSC);
 }
 
-void NetVscOnChannelCallback(void *Context)
+static void NetVscOnChannelCallback(void *Context)
 {
-       const int netPacketSize = 2048;
        int ret;
        struct hv_device *device = Context;
        struct netvsc_device *netDevice;
        u32 bytesRecvd;
        u64 requestId;
-       unsigned char packet[netPacketSize];
+       unsigned char *packet;
        struct vmpacket_descriptor *desc;
-       unsigned char *buffer = packet;
-       int bufferlen = netPacketSize;
+       unsigned char *buffer;
+       int bufferlen = NETVSC_PACKET_SIZE;
 
 
        DPRINT_ENTER(NETVSC);
 
        ASSERT(device);
 
+       packet = kzalloc(NETVSC_PACKET_SIZE * sizeof(unsigned char),
+                        GFP_KERNEL);
+       if (!packet)
+               return;
+       buffer = packet;
+
        netDevice = GetInboundNetDevice(device);
        if (!netDevice) {
                DPRINT_ERR(NETVSC, "net device (%p) shutting down..."
                           "ignoring inbound packets", netDevice);
                DPRINT_EXIT(NETVSC);
-               return;
+               goto out;
        }
 
        do {
@@ -1340,17 +1350,17 @@ void NetVscOnChannelCallback(void *Context)
                                }
 
                                /* reset */
-                               if (bufferlen > netPacketSize) {
+                               if (bufferlen > NETVSC_PACKET_SIZE) {
                                        kfree(buffer);
                                        buffer = packet;
-                                       bufferlen = netPacketSize;
+                                       bufferlen = NETVSC_PACKET_SIZE;
                                }
                        } else {
                                /* reset */
-                               if (bufferlen > netPacketSize) {
+                               if (bufferlen > NETVSC_PACKET_SIZE) {
                                        kfree(buffer);
                                        buffer = packet;
-                                       bufferlen = netPacketSize;
+                                       bufferlen = NETVSC_PACKET_SIZE;
                                }
 
                                break;
@@ -1374,5 +1384,7 @@ void NetVscOnChannelCallback(void *Context)
 
        PutNetDevice(device);
        DPRINT_EXIT(NETVSC);
+out:
+       kfree(buffer);
        return;
 }