Skip to content

Commit

Permalink
lan78xx: Fix memory allocation bug
Browse files Browse the repository at this point in the history
Fix memory allocation that fails to check for NULL return.

Signed-off-by: John Efstathiades <john.efstathiades@pebblebay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
John Efstathiades authored and David S. Miller committed Nov 18, 2021
1 parent d091ec9 commit a6df95c
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions drivers/net/usb/lan78xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -4106,39 +4106,41 @@ static int lan78xx_probe(struct usb_interface *intf,
period = ep_intr->desc.bInterval;
maxp = usb_maxpacket(dev->udev, dev->pipe_intr, 0);
buf = kmalloc(maxp, GFP_KERNEL);
if (buf) {
dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL);
if (!dev->urb_intr) {
ret = -ENOMEM;
kfree(buf);
goto out3;
} else {
usb_fill_int_urb(dev->urb_intr, dev->udev,
dev->pipe_intr, buf, maxp,
intr_complete, dev, period);
dev->urb_intr->transfer_flags |= URB_FREE_BUFFER;
}
if (!buf) {
ret = -ENOMEM;
goto out3;
}

dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL);
if (!dev->urb_intr) {
ret = -ENOMEM;
goto out4;
} else {
usb_fill_int_urb(dev->urb_intr, dev->udev,
dev->pipe_intr, buf, maxp,
intr_complete, dev, period);
dev->urb_intr->transfer_flags |= URB_FREE_BUFFER;
}

dev->maxpacket = usb_maxpacket(dev->udev, dev->pipe_out, 1);

/* Reject broken descriptors. */
if (dev->maxpacket == 0) {
ret = -ENODEV;
goto out4;
goto out5;
}

/* driver requires remote-wakeup capability during autosuspend. */
intf->needs_remote_wakeup = 1;

ret = lan78xx_phy_init(dev);
if (ret < 0)
goto out4;
goto out5;

ret = register_netdev(netdev);
if (ret != 0) {
netif_err(dev, probe, netdev, "couldn't register the device\n");
goto out5;
goto out6;
}

usb_set_intfdata(intf, dev);
Expand All @@ -4153,10 +4155,12 @@ static int lan78xx_probe(struct usb_interface *intf,

return 0;

out5:
out6:
phy_disconnect(netdev->phydev);
out4:
out5:
usb_free_urb(dev->urb_intr);
out4:
kfree(buf);
out3:
lan78xx_unbind(dev, intf);
out2:
Expand Down

0 comments on commit a6df95c

Please sign in to comment.