Commit 6c03e38b authored by Chris Rankin's avatar Chris Rankin Committed by Mauro Carvalho Chehab

[media] em28xx: clean up resources should init fail

This patch ensures that the em28xx_init_dev() function cleans up after itself,
in the event that it fails. This isimportant because the struct em28xx will be
deallocated if em28xx_init_dev() returns an error.

[mchehab@redhat.com: Fix merge conflicts and simplify the goto labels]
Signed-off-by: default avatarChris Rankin <rankincj@yahoo.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 38b61eb2
...@@ -2806,7 +2806,6 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, ...@@ -2806,7 +2806,6 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
{ {
struct em28xx *dev = *devhandle; struct em28xx *dev = *devhandle;
int retval; int retval;
int errCode;
dev->udev = udev; dev->udev = udev;
mutex_init(&dev->ctrl_urb_lock); mutex_init(&dev->ctrl_urb_lock);
...@@ -2883,8 +2882,8 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, ...@@ -2883,8 +2882,8 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
} }
if (dev->is_audio_only) { if (dev->is_audio_only) {
errCode = em28xx_audio_setup(dev); retval = em28xx_audio_setup(dev);
if (errCode) if (retval)
return -ENODEV; return -ENODEV;
em28xx_add_into_devlist(dev); em28xx_add_into_devlist(dev);
em28xx_init_extension(dev); em28xx_init_extension(dev);
...@@ -2903,7 +2902,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, ...@@ -2903,7 +2902,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
/* Resets I2C speed */ /* Resets I2C speed */
em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed); em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed);
if (retval < 0) { if (retval < 0) {
em28xx_errdev("%s: em28xx_write_regs_req failed!" em28xx_errdev("%s: em28xx_write_reg failed!"
" retval [%d]\n", " retval [%d]\n",
__func__, retval); __func__, retval);
return retval; return retval;
...@@ -2917,12 +2916,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, ...@@ -2917,12 +2916,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
} }
/* register i2c bus */ /* register i2c bus */
errCode = em28xx_i2c_register(dev); retval = em28xx_i2c_register(dev);
if (errCode < 0) { if (retval < 0) {
v4l2_device_unregister(&dev->v4l2_dev); em28xx_errdev("%s: em28xx_i2c_register - error [%d]!\n",
em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n", __func__, retval);
__func__, errCode); goto unregister_dev;
return errCode;
} }
/* /*
...@@ -2936,11 +2934,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, ...@@ -2936,11 +2934,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
em28xx_card_setup(dev); em28xx_card_setup(dev);
/* Configure audio */ /* Configure audio */
errCode = em28xx_audio_setup(dev); retval = em28xx_audio_setup(dev);
if (errCode < 0) { if (retval < 0) {
v4l2_device_unregister(&dev->v4l2_dev); em28xx_errdev("%s: Error while setting audio - error [%d]!\n",
em28xx_errdev("%s: Error while setting audio - errCode [%d]!\n", __func__, retval);
__func__, errCode); goto fail;
} }
/* wake i2c devices */ /* wake i2c devices */
...@@ -2954,31 +2952,28 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, ...@@ -2954,31 +2952,28 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
if (dev->board.has_msp34xx) { if (dev->board.has_msp34xx) {
/* Send a reset to other chips via gpio */ /* Send a reset to other chips via gpio */
errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7); retval = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7);
if (errCode < 0) { if (retval < 0) {
em28xx_errdev("%s: em28xx_write_regs_req - " em28xx_errdev("%s: em28xx_write_reg - "
"msp34xx(1) failed! errCode [%d]\n", "msp34xx(1) failed! error [%d]\n",
__func__, errCode); __func__, retval);
return errCode; goto fail;
} }
msleep(3); msleep(3);
errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff); retval = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff);
if (errCode < 0) { if (retval < 0) {
em28xx_errdev("%s: em28xx_write_regs_req - " em28xx_errdev("%s: em28xx_write_reg - "
"msp34xx(2) failed! errCode [%d]\n", "msp34xx(2) failed! error [%d]\n",
__func__, errCode); __func__, retval);
return errCode; goto fail;
} }
msleep(3); msleep(3);
} }
em28xx_add_into_devlist(dev);
retval = em28xx_register_analog_devices(dev); retval = em28xx_register_analog_devices(dev);
if (retval < 0) { if (retval < 0) {
em28xx_release_resources(dev); goto fail;
goto fail_reg_devices;
} }
em28xx_init_extension(dev); em28xx_init_extension(dev);
...@@ -2988,7 +2983,12 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev, ...@@ -2988,7 +2983,12 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
return 0; return 0;
fail_reg_devices: fail:
em28xx_i2c_unregister(dev);
unregister_dev:
v4l2_device_unregister(&dev->v4l2_dev);
return retval; return retval;
} }
......
...@@ -1195,13 +1195,6 @@ void em28xx_remove_from_devlist(struct em28xx *dev) ...@@ -1195,13 +1195,6 @@ void em28xx_remove_from_devlist(struct em28xx *dev)
mutex_unlock(&em28xx_devlist_mutex); mutex_unlock(&em28xx_devlist_mutex);
}; };
void em28xx_add_into_devlist(struct em28xx *dev)
{
mutex_lock(&em28xx_devlist_mutex);
list_add_tail(&dev->devlist, &em28xx_devlist);
mutex_unlock(&em28xx_devlist_mutex);
};
/* /*
* Extension interface * Extension interface
*/ */
...@@ -1239,14 +1232,13 @@ EXPORT_SYMBOL(em28xx_unregister_extension); ...@@ -1239,14 +1232,13 @@ EXPORT_SYMBOL(em28xx_unregister_extension);
void em28xx_init_extension(struct em28xx *dev) void em28xx_init_extension(struct em28xx *dev)
{ {
struct em28xx_ops *ops = NULL; const struct em28xx_ops *ops = NULL;
mutex_lock(&em28xx_devlist_mutex); mutex_lock(&em28xx_devlist_mutex);
if (!list_empty(&em28xx_extension_devlist)) { list_add_tail(&dev->devlist, &em28xx_devlist);
list_for_each_entry(ops, &em28xx_extension_devlist, next) { list_for_each_entry(ops, &em28xx_extension_devlist, next) {
if (ops->init) if (ops->init)
ops->init(dev); ops->init(dev);
}
} }
mutex_unlock(&em28xx_devlist_mutex); mutex_unlock(&em28xx_devlist_mutex);
} }
......
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