Commit 234ad182 authored by Dan Carpenter's avatar Dan Carpenter Committed by Greg Kroah-Hartman

staging: gdm7240: fix error handling of probe()

The error handling is messy and not in kernel style.  On some paths it
frees "mux_dev" twice.
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 35b7b91a
...@@ -509,11 +509,11 @@ static int init_usb(struct mux_dev *mux_dev) ...@@ -509,11 +509,11 @@ static int init_usb(struct mux_dev *mux_dev)
static int gdm_mux_probe(struct usb_interface *intf, const struct usb_device_id *id) static int gdm_mux_probe(struct usb_interface *intf, const struct usb_device_id *id)
{ {
struct mux_dev *mux_dev = NULL; struct mux_dev *mux_dev;
struct tty_dev *tty_dev = NULL; struct tty_dev *tty_dev;
u16 idVendor, idProduct; u16 idVendor, idProduct;
int bInterfaceNumber; int bInterfaceNumber;
int ret = 0; int ret;
int i; int i;
struct usb_device *usbdev = interface_to_usbdev(intf); struct usb_device *usbdev = interface_to_usbdev(intf);
bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber; bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
...@@ -523,61 +523,54 @@ static int gdm_mux_probe(struct usb_interface *intf, const struct usb_device_id ...@@ -523,61 +523,54 @@ static int gdm_mux_probe(struct usb_interface *intf, const struct usb_device_id
pr_info("mux vid = 0x%04x pid = 0x%04x\n", idVendor, idProduct); pr_info("mux vid = 0x%04x pid = 0x%04x\n", idVendor, idProduct);
if (bInterfaceNumber != 2) { if (bInterfaceNumber != 2)
ret = -ENODEV; return -ENODEV;
goto out;
}
mux_dev = kzalloc(sizeof(struct mux_dev), GFP_KERNEL); mux_dev = kzalloc(sizeof(struct mux_dev), GFP_KERNEL);
if (!mux_dev) { if (!mux_dev)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
tty_dev = kzalloc(sizeof(struct tty_dev), GFP_KERNEL); tty_dev = kzalloc(sizeof(struct tty_dev), GFP_KERNEL);
if (!tty_dev) { if (!tty_dev) {
kfree(mux_dev);
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto err_free_mux;
} }
mux_dev->usbdev = usbdev; mux_dev->usbdev = usbdev;
mux_dev->control_intf = intf; mux_dev->control_intf = intf;
ret = init_usb(mux_dev); ret = init_usb(mux_dev);
if (ret < 0) if (ret)
goto out; goto err_free_tty;
tty_dev->priv_dev = (void *)mux_dev; tty_dev->priv_dev = (void *)mux_dev;
tty_dev->send_func = gdm_mux_send; tty_dev->send_func = gdm_mux_send;
tty_dev->recv_func = gdm_mux_recv; tty_dev->recv_func = gdm_mux_recv;
tty_dev->send_control = gdm_mux_send_control; tty_dev->send_control = gdm_mux_send_control;
if (register_lte_tty_device(tty_dev, &intf->dev) < 0) { ret = register_lte_tty_device(tty_dev, &intf->dev);
unregister_lte_tty_device(tty_dev); if (ret)
mux_dev = tty_dev->priv_dev; goto err_unregister_tty;
ret = -1;
goto out;
}
for (i = 0; i < TTY_MAX_COUNT; i++) for (i = 0; i < TTY_MAX_COUNT; i++)
mux_dev->tty_dev = tty_dev; mux_dev->tty_dev = tty_dev;
out: mux_dev->intf = intf;
if (ret < 0) { mux_dev->usb_state = PM_NORMAL;
kfree(tty_dev);
if (mux_dev) {
release_usb(mux_dev);
kfree(mux_dev);
}
} else {
mux_dev->intf = intf;
mux_dev->usb_state = PM_NORMAL;
}
usb_get_dev(usbdev); usb_get_dev(usbdev);
usb_set_intfdata(intf, tty_dev); usb_set_intfdata(intf, tty_dev);
return 0;
err_unregister_tty:
unregister_lte_tty_device(tty_dev);
release_usb(mux_dev);
err_free_tty:
kfree(tty_dev);
err_free_mux:
kfree(mux_dev);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment