Commit 7e11d502 authored by Markus Elfring's avatar Markus Elfring Committed by Mauro Carvalho Chehab

media: tm6000: cleanup trival coding style issues

- Delete seven error messages for a failed memory allocation
- Adjust seven checks for null pointers
- Use common error handling code in tm6000_usb_probe()
- Adjust jump targets so that the function "kfree" will be always called
  with a non-null pointer.
- Delete an initialisation for the local variable "dev"
  which became unnecessary with this refactoring.
Signed-off-by: default avatarMarkus Elfring <elfring@users.sourceforge.net>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent 5bf24e08
...@@ -1184,7 +1184,7 @@ static int tm6000_usb_probe(struct usb_interface *interface, ...@@ -1184,7 +1184,7 @@ static int tm6000_usb_probe(struct usb_interface *interface,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct usb_device *usbdev; struct usb_device *usbdev;
struct tm6000_core *dev = NULL; struct tm6000_core *dev;
int i, rc = 0; int i, rc = 0;
int nr = 0; int nr = 0;
char *speed; char *speed;
...@@ -1194,22 +1194,21 @@ static int tm6000_usb_probe(struct usb_interface *interface, ...@@ -1194,22 +1194,21 @@ static int tm6000_usb_probe(struct usb_interface *interface,
/* Selects the proper interface */ /* Selects the proper interface */
rc = usb_set_interface(usbdev, 0, 1); rc = usb_set_interface(usbdev, 0, 1);
if (rc < 0) if (rc < 0)
goto err; goto report_failure;
/* Check to see next free device and mark as used */ /* Check to see next free device and mark as used */
nr = find_first_zero_bit(&tm6000_devused, TM6000_MAXBOARDS); nr = find_first_zero_bit(&tm6000_devused, TM6000_MAXBOARDS);
if (nr >= TM6000_MAXBOARDS) { if (nr >= TM6000_MAXBOARDS) {
printk(KERN_ERR "tm6000: Supports only %i tm60xx boards.\n", TM6000_MAXBOARDS); printk(KERN_ERR "tm6000: Supports only %i tm60xx boards.\n", TM6000_MAXBOARDS);
usb_put_dev(usbdev); rc = -ENOMEM;
return -ENOMEM; goto put_device;
} }
/* Create and initialize dev struct */ /* Create and initialize dev struct */
dev = kzalloc(sizeof(*dev), GFP_KERNEL); dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (dev == NULL) { if (!dev) {
printk(KERN_ERR "tm6000" ": out of memory!\n"); rc = -ENOMEM;
usb_put_dev(usbdev); goto put_device;
return -ENOMEM;
} }
spin_lock_init(&dev->slock); spin_lock_init(&dev->slock);
mutex_init(&dev->usb_lock); mutex_init(&dev->usb_lock);
...@@ -1313,8 +1312,7 @@ static int tm6000_usb_probe(struct usb_interface *interface, ...@@ -1313,8 +1312,7 @@ static int tm6000_usb_probe(struct usb_interface *interface,
if (!dev->isoc_in.endp) { if (!dev->isoc_in.endp) {
printk(KERN_ERR "tm6000: probing error: no IN ISOC endpoint!\n"); printk(KERN_ERR "tm6000: probing error: no IN ISOC endpoint!\n");
rc = -ENODEV; rc = -ENODEV;
goto free_device;
goto err;
} }
/* save our data pointer in this interface device */ /* save our data pointer in this interface device */
...@@ -1324,17 +1322,18 @@ static int tm6000_usb_probe(struct usb_interface *interface, ...@@ -1324,17 +1322,18 @@ static int tm6000_usb_probe(struct usb_interface *interface,
rc = tm6000_init_dev(dev); rc = tm6000_init_dev(dev);
if (rc < 0) if (rc < 0)
goto err; goto free_device;
return 0; return 0;
err: free_device:
kfree(dev);
report_failure:
printk(KERN_ERR "tm6000: Error %d while registering\n", rc); printk(KERN_ERR "tm6000: Error %d while registering\n", rc);
clear_bit(nr, &tm6000_devused); clear_bit(nr, &tm6000_devused);
put_device:
usb_put_dev(usbdev); usb_put_dev(usbdev);
kfree(dev);
return rc; return rc;
} }
......
...@@ -123,7 +123,7 @@ static int tm6000_start_stream(struct tm6000_core *dev) ...@@ -123,7 +123,7 @@ static int tm6000_start_stream(struct tm6000_core *dev)
} }
dvb->bulk_urb = usb_alloc_urb(0, GFP_KERNEL); dvb->bulk_urb = usb_alloc_urb(0, GFP_KERNEL);
if (dvb->bulk_urb == NULL) if (!dvb->bulk_urb)
return -ENOMEM; return -ENOMEM;
pipe = usb_rcvbulkpipe(dev->udev, dev->bulk_in.endp->desc.bEndpointAddress pipe = usb_rcvbulkpipe(dev->udev, dev->bulk_in.endp->desc.bEndpointAddress
...@@ -133,9 +133,8 @@ static int tm6000_start_stream(struct tm6000_core *dev) ...@@ -133,9 +133,8 @@ static int tm6000_start_stream(struct tm6000_core *dev)
size = size * 15; /* 512 x 8 or 12 or 15 */ size = size * 15; /* 512 x 8 or 12 or 15 */
dvb->bulk_urb->transfer_buffer = kzalloc(size, GFP_KERNEL); dvb->bulk_urb->transfer_buffer = kzalloc(size, GFP_KERNEL);
if (dvb->bulk_urb->transfer_buffer == NULL) { if (!dvb->bulk_urb->transfer_buffer) {
usb_free_urb(dvb->bulk_urb); usb_free_urb(dvb->bulk_urb);
printk(KERN_ERR "tm6000: couldn't allocate transfer buffer!\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -361,7 +360,7 @@ static void unregister_dvb(struct tm6000_core *dev) ...@@ -361,7 +360,7 @@ static void unregister_dvb(struct tm6000_core *dev)
{ {
struct tm6000_dvb *dvb = dev->dvb; struct tm6000_dvb *dvb = dev->dvb;
if (dvb->bulk_urb != NULL) { if (dvb->bulk_urb) {
struct urb *bulk_urb = dvb->bulk_urb; struct urb *bulk_urb = dvb->bulk_urb;
kfree(bulk_urb->transfer_buffer); kfree(bulk_urb->transfer_buffer);
...@@ -400,10 +399,8 @@ static int dvb_init(struct tm6000_core *dev) ...@@ -400,10 +399,8 @@ static int dvb_init(struct tm6000_core *dev)
} }
dvb = kzalloc(sizeof(struct tm6000_dvb), GFP_KERNEL); dvb = kzalloc(sizeof(struct tm6000_dvb), GFP_KERNEL);
if (!dvb) { if (!dvb)
printk(KERN_INFO "Cannot allocate memory\n");
return -ENOMEM; return -ENOMEM;
}
dev->dvb = dvb; dev->dvb = dvb;
......
...@@ -352,7 +352,7 @@ static int __tm6000_ir_int_start(struct rc_dev *rc) ...@@ -352,7 +352,7 @@ static int __tm6000_ir_int_start(struct rc_dev *rc)
dprintk(1, "IR max size: %d\n", size); dprintk(1, "IR max size: %d\n", size);
ir->int_urb->transfer_buffer = kzalloc(size, GFP_ATOMIC); ir->int_urb->transfer_buffer = kzalloc(size, GFP_ATOMIC);
if (ir->int_urb->transfer_buffer == NULL) { if (!ir->int_urb->transfer_buffer) {
usb_free_urb(ir->int_urb); usb_free_urb(ir->int_urb);
return err; return err;
} }
......
...@@ -470,20 +470,16 @@ static int tm6000_alloc_urb_buffers(struct tm6000_core *dev) ...@@ -470,20 +470,16 @@ static int tm6000_alloc_urb_buffers(struct tm6000_core *dev)
int num_bufs = TM6000_NUM_URB_BUF; int num_bufs = TM6000_NUM_URB_BUF;
int i; int i;
if (dev->urb_buffer != NULL) if (dev->urb_buffer)
return 0; return 0;
dev->urb_buffer = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL); dev->urb_buffer = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
if (!dev->urb_buffer) { if (!dev->urb_buffer)
tm6000_err("cannot allocate memory for urb buffers\n");
return -ENOMEM; return -ENOMEM;
}
dev->urb_dma = kmalloc(sizeof(dma_addr_t *)*num_bufs, GFP_KERNEL); dev->urb_dma = kmalloc(sizeof(dma_addr_t *)*num_bufs, GFP_KERNEL);
if (!dev->urb_dma) { if (!dev->urb_dma)
tm6000_err("cannot allocate memory for urb dma pointers\n");
return -ENOMEM; return -ENOMEM;
}
for (i = 0; i < num_bufs; i++) { for (i = 0; i < num_bufs; i++) {
dev->urb_buffer[i] = usb_alloc_coherent( dev->urb_buffer[i] = usb_alloc_coherent(
...@@ -507,7 +503,7 @@ static int tm6000_free_urb_buffers(struct tm6000_core *dev) ...@@ -507,7 +503,7 @@ static int tm6000_free_urb_buffers(struct tm6000_core *dev)
{ {
int i; int i;
if (dev->urb_buffer == NULL) if (!dev->urb_buffer)
return 0; return 0;
for (i = 0; i < TM6000_NUM_URB_BUF; i++) { for (i = 0; i < TM6000_NUM_URB_BUF; i++) {
...@@ -598,15 +594,12 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev) ...@@ -598,15 +594,12 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)
dev->isoc_ctl.num_bufs = num_bufs; dev->isoc_ctl.num_bufs = num_bufs;
dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL); dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
if (!dev->isoc_ctl.urb) { if (!dev->isoc_ctl.urb)
tm6000_err("cannot alloc memory for usb buffers\n");
return -ENOMEM; return -ENOMEM;
}
dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs, dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs,
GFP_KERNEL); GFP_KERNEL);
if (!dev->isoc_ctl.transfer_buffer) { if (!dev->isoc_ctl.transfer_buffer) {
tm6000_err("cannot allocate memory for usbtransfer\n");
kfree(dev->isoc_ctl.urb); kfree(dev->isoc_ctl.urb);
return -ENOMEM; return -ENOMEM;
} }
......
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