Kaynağa Gözat

can: gs_usb: check for kzalloc allocation failure

smatch detected the following issue:
drivers/net/can/usb/gs_usb.c:904 gs_usb_probe() error:
   potential null dereference 'dev'.  (kzalloc returns null)

Add a check for null return from kzalloc and return -ENOMEM

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Colin Ian King 10 yıl önce
ebeveyn
işleme
37920a74ab
1 değiştirilmiş dosya ile 2 ekleme ve 0 silme
  1. 2 0
      drivers/net/can/usb/gs_usb.c

+ 2 - 0
drivers/net/can/usb/gs_usb.c

@@ -901,6 +901,8 @@ static int gs_usb_probe(struct usb_interface *intf, const struct usb_device_id *
 	}
 
 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
 	init_usb_anchor(&dev->rx_submitted);
 
 	atomic_set(&dev->active_channels, 0);