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)
static int gdm_mux_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
struct mux_dev *mux_dev = NULL;
struct tty_dev *tty_dev = NULL;
struct mux_dev *mux_dev;
struct tty_dev *tty_dev;
u16 idVendor, idProduct;
int bInterfaceNumber;
int ret = 0;
int ret;
int i;
struct usb_device *usbdev = interface_to_usbdev(intf);
bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
......@@ -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);
if (bInterfaceNumber != 2) {
ret = -ENODEV;
goto out;
}
if (bInterfaceNumber != 2)
return -ENODEV;
mux_dev = kzalloc(sizeof(struct mux_dev), GFP_KERNEL);
if (!mux_dev) {
ret = -ENOMEM;
goto out;
}
if (!mux_dev)
return -ENOMEM;
tty_dev = kzalloc(sizeof(struct tty_dev), GFP_KERNEL);
if (!tty_dev) {
kfree(mux_dev);
ret = -ENOMEM;
goto out;
goto err_free_mux;
}
mux_dev->usbdev = usbdev;
mux_dev->control_intf = intf;
ret = init_usb(mux_dev);
if (ret < 0)
goto out;
if (ret)
goto err_free_tty;
tty_dev->priv_dev = (void *)mux_dev;
tty_dev->send_func = gdm_mux_send;
tty_dev->recv_func = gdm_mux_recv;
tty_dev->send_control = gdm_mux_send_control;
if (register_lte_tty_device(tty_dev, &intf->dev) < 0) {
unregister_lte_tty_device(tty_dev);
mux_dev = tty_dev->priv_dev;
ret = register_lte_tty_device(tty_dev, &intf->dev);
if (ret)
goto err_unregister_tty;
ret = -1;
goto out;
}
for (i = 0; i < TTY_MAX_COUNT; i++)
mux_dev->tty_dev = tty_dev;
out:
if (ret < 0) {
kfree(tty_dev);
if (mux_dev) {
release_usb(mux_dev);
kfree(mux_dev);
}
} else {
mux_dev->intf = intf;
mux_dev->usb_state = PM_NORMAL;
}
mux_dev->intf = intf;
mux_dev->usb_state = PM_NORMAL;
usb_get_dev(usbdev);
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;
}
......
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