TM6000: Adjustments for some function implementations
Subsystems (2)
cover TM6000: Adjustments for some function implementations
From: Markus Elfring <[email protected]>
Date: Fri, 15 Sep 2017 08:24:56 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (9):
Delete seven error messages for a failed memory allocation Adjust seven checks for null pointers
Use common error handling code in tm6000_usb_probe()
One function call less in tm6000_usb_probe() after error detection Delete an unnecessary variable initialisation in tm6000_usb_probe() Use common error handling code in tm6000_cards_setup() Improve a size determination in dvb_init()
Use common error handling code in tm6000_start_stream() Use common error handling code in tm6000_prepare_isoc()
drivers/media/usb/tm6000/tm6000-cards.c | 36 ++++++++++++++++----------------- drivers/media/usb/tm6000/tm6000-dvb.c | 24 +++++++++++----------- drivers/media/usb/tm6000/tm6000-input.c | 2 +- drivers/media/usb/tm6000/tm6000-video.c | 30 +++++++++++---------------- 4 files changed, 42 insertions(+), 50 deletions(-)
Signature · 1 line
2.14.1
PATCH 1/9 tm6000: Delete seven error messages for a failed memory allocation
From: Markus Elfring <[email protected]>
Date: Thu, 14 Sep 2017 14:34:39 +0200
Omit extra messages for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
--- drivers/media/usb/tm6000/tm6000-cards.c | 1 - drivers/media/usb/tm6000/tm6000-dvb.c | 5 +---- drivers/media/usb/tm6000/tm6000-video.c | 13 +++---------- 3 files changed, 4 insertions(+), 15 deletions(-)
drivers/media/usb/tm6000/tm6000-cards.c +0 -1
@@ -1210,4 +1210,3 @@ static int tm6000_usb_probe(struct usb_interface *interface, -printk (KERN_ERR "tm6000" ": out of memory!\n" );usb_put_dev (usbdev);return -ENOMEM ; }
drivers/media/usb/tm6000/tm6000-dvb.c +1 -4
@@ -137,5 +137,4 @@ static int tm6000_start_stream(struct tm6000_core *dev)usb_free_urb (dvb->bulk_urb); -printk (KERN_ERR "tm6000: couldn't allocate transfer buffer!\n" );return -ENOMEM ; }
@@ -403,7 +402,5 @@ static int dvb_init(struct tm6000_core *dev) -if (!dvb) { -printk (KERN_INFO "Cannot allocate memory\n" ); +if (!dvb)return -ENOMEM ; - } dev->dvb = dvb;
drivers/media/usb/tm6000/tm6000-video.c +3 -10
@@ -477,13 +477,9 @@ static int tm6000_alloc_urb_buffers(struct tm6000_core *dev) -if (!dev->urb_buffer) { -tm6000_err ("cannot allocate memory for urb buffers\n" ); +if (!dev->urb_buffer)return -ENOMEM ; - } dev->urb_dma =kmalloc (sizeof (dma_addr_t *)*num_bufs,GFP_KERNEL ); -if (!dev->urb_dma) { -tm6000_err ("cannot allocate memory for urb dma pointers\n" ); +if (!dev->urb_dma)return -ENOMEM ; - }for (i =0 ; i < num_bufs; i++) { dev->urb_buffer[i] = usb_alloc_coherent(
@@ -601,12 +597,9 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev) -if (!dev->isoc_ctl.urb) { -tm6000_err ("cannot alloc memory for usb buffers\n" ); +if (!dev->isoc_ctl.urb)return -ENOMEM ; - } dev->isoc_ctl.transfer_buffer =kmalloc (sizeof (void *)*num_bufs,GFP_KERNEL );if (!dev->isoc_ctl.transfer_buffer) { -tm6000_err ("cannot allocate memory for usbtransfer\n" );kfree (dev->isoc_ctl.urb);return -ENOMEM ; }
Signature · 1 line
2.14.1
PATCH 2/9 tm6000: Adjust seven checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 14 Sep 2017 14:51:15 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written …
Thus fix the affected source code places.
--- drivers/media/usb/tm6000/tm6000-cards.c | 2 +- drivers/media/usb/tm6000/tm6000-dvb.c | 6 +++--- drivers/media/usb/tm6000/tm6000-input.c | 2 +- drivers/media/usb/tm6000/tm6000-video.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-)
drivers/media/usb/tm6000/tm6000-cards.c +1 -1
@@ -1206,7 +1206,7 @@ static int tm6000_usb_probe(struct usb_interface *interface,/* Create and initialize dev struct */ dev =kzalloc (sizeof (*dev),GFP_KERNEL ); -if (dev =NULL ) { +if (!dev) {usb_put_dev (usbdev);return -ENOMEM ; }
drivers/media/usb/tm6000/tm6000-dvb.c +3 -3
@@ -123,7 +123,7 @@ static int tm6000_start_stream(struct tm6000_core *dev) } dvb->bulk_urb =usb_alloc_urb (0 ,GFP_KERNEL ); -if (dvb->bulk_urb =NULL ) +if (!dvb->bulk_urb)return -ENOMEM ; pipe = usb_rcvbulkpipe(dev->udev, dev->bulk_in.endp->desc.bEndpointAddress
@@ -133,7 +133,7 @@ static int tm6000_start_stream(struct tm6000_core *dev) size = size *15 ;/* 512 x 8 or 12 or 15 */ 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);return -ENOMEM ; }
@@ -360,7 +360,7 @@ static void unregister_dvb(struct tm6000_core *dev) {struct tm6000_dvb *dvb = dev->dvb; -if (dvb->bulk_urb !=NULL ) { +if (dvb->bulk_urb) {struct urb *bulk_urb = dvb->bulk_urb;kfree (bulk_urb->transfer_buffer);
drivers/media/usb/tm6000/tm6000-input.c +1 -1
@@ -352,7 +352,7 @@ static int __tm6000_ir_int_start(struct rc_dev *rc)dprintk (1 ,"IR max size: %d\n" , size); 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);return err; }
drivers/media/usb/tm6000/tm6000-video.c +2 -2
@@ -470,7 +470,7 @@ static int tm6000_alloc_urb_buffers(struct tm6000_core *dev)int num_bufs =TM6000_NUM_URB_BUF ;int i; -if (dev->urb_buffer !=NULL ) +if (dev->urb_buffer)return 0 ; dev->urb_buffer =kmalloc (sizeof (void *)*num_bufs,GFP_KERNEL );
@@ -503,7 +503,7 @@ static int tm6000_free_urb_buffers(struct tm6000_core *dev) {int i; -if (dev->urb_buffer =NULL ) +if (!dev->urb_buffer)return 0 ;for (i =0 ; i <TM6000_NUM_URB_BUF ; i++) {
Signature · 1 line
2.14.1
PATCH 3/9 tm6000: Use common error handling code in tm6000_usb_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 14 Sep 2017 16:00:47 +0200
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
--- drivers/media/usb/tm6000/tm6000-cards.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/media/usb/tm6000/tm6000-cards.c +6 -5
@@ -1200,15 +1200,15 @@ static int tm6000_usb_probe(struct usb_interface *interface, nr =find_first_zero_bit (&tm6000_devused,TM6000_MAXBOARDS );if (nr >=TM6000_MAXBOARDS ) {printk (KERN_ERR "tm6000: Supports only %i tm60xx boards.\n" ,TM6000_MAXBOARDS ); -usb_put_dev (usbdev); -return -ENOMEM ; + rc = -ENOMEM ; + goto put_device; }/* Create and initialize dev struct */ dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev) { -usb_put_dev (usbdev); -return -ENOMEM ; + rc = -ENOMEM ; + goto put_device; }spin_lock_init (&dev->slock);mutex_init (&dev->usb_lock);
@@ -1331,9 +1331,10 @@ static int tm6000_usb_probe(struct usb_interface *interface,printk (KERN_ERR "tm6000: Error %d while registering\n" , rc);clear_bit (nr, &tm6000_devused); -usb_put_dev (usbdev);kfree (dev); +put_device: +usb_put_dev (usbdev);return rc; }
Signature · 1 line
2.14.1
PATCH 4/9 tm6000: One function call less in tm6000_usb_probe() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 14 Sep 2017 16:11:55 +0200
* 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.
--- drivers/media/usb/tm6000/tm6000-cards.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/media/usb/tm6000/tm6000-cards.c +7 -8
@@ -1184,7 +1184,7 @@ static int tm6000_usb_probe(struct usb_interface *interface, const struct usb_device_id *id) {struct usb_device *usbdev; -struct tm6000_core *dev =NULL ; +struct tm6000_core *dev;int i, rc =0 ;int nr =0 ;char *speed;
@@ -1194,7 +1194,7 @@ static int tm6000_usb_probe(struct usb_interface *interface,/* Selects the proper interface */ rc =usb_set_interface (usbdev,0 ,1 );if (rc <0 ) - goto err; + goto report_failure;/* Check to see next free device and mark as used */ nr =find_first_zero_bit (&tm6000_devused,TM6000_MAXBOARDS );
@@ -1312,8 +1312,7 @@ static int tm6000_usb_probe(struct usb_interface *interface,if (!dev->isoc_in.endp) {printk (KERN_ERR "tm6000: probing error: no IN ISOC endpoint!\n" ); rc = -ENODEV ; - - goto err; + goto free_device; }/* save our data pointer in this interface device */
@@ -1323,16 +1322,16 @@ static int tm6000_usb_probe(struct usb_interface *interface, rc =tm6000_init_dev (dev);if (rc <0 ) - goto err; + goto free_device;return 0 ; -err: +free_device: +kfree (dev); +report_failure:printk (KERN_ERR "tm6000: Error %d while registering\n" , rc);clear_bit (nr, &tm6000_devused); - -kfree (dev); put_device:usb_put_dev (usbdev);return rc;
Signature · 1 line
2.14.1
PATCH 5/9 tm6000: Delete an unnecessary variable initialisation in tm6000_usb_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 14 Sep 2017 16:13:56 +0200
The local variable "rc" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/media/usb/tm6000/tm6000-cards.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/tm6000/tm6000-cards.c +1 -1
@@ -1185,7 +1185,7 @@ static int tm6000_usb_probe(struct usb_interface *interface, {struct usb_device *usbdev;struct tm6000_core *dev; -int i, rc =0 ; +int i, rc;int nr =0 ;char *speed;
Signature · 1 line
2.14.1
PATCH 6/9 tm6000: Use common error handling code in tm6000_cards_setup()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 14 Sep 2017 16:26:42 +0200
Add a jump target so that a bit of exception handling can be better reused in this function.
This issue was detected by using the Coccinelle software.
--- drivers/media/usb/tm6000/tm6000-cards.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/media/usb/tm6000/tm6000-cards.c +3 -4
@@ -872,15 +872,14 @@ int tm6000_cards_setup(struct tm6000_core *dev)for (i =0 ; i <2 ; i++) { rc =tm6000_set_reg (dev,REQ_03_SET_GET_MCU_PIN , dev->gpio.tuner_reset,0x00 ); -if (rc <0 ) { -printk (KERN_ERR "Error %i doing tuner reset\n" , rc); -return rc; - } +if (rc <0 ) + goto report_failure;msleep (10 );/* Just to be conservative */ rc =tm6000_set_reg (dev,REQ_03_SET_GET_MCU_PIN , dev->gpio.tuner_reset,0x01 );if (rc <0 ) { +report_failure:printk (KERN_ERR "Error %i doing tuner reset\n" , rc);return rc; }
Signature · 1 line
2.14.1
PATCH 7/9 tm6000: Improve a size determination in dvb_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 15 Sep 2017 07:33:24 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
--- drivers/media/usb/tm6000/tm6000-dvb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/tm6000/tm6000-dvb.c +1 -1
@@ -398,7 +398,7 @@ static int dvb_init(struct tm6000_core *dev)return 0 ; } - dvb =kzalloc (sizeof (struct tm6000_dvb ),GFP_KERNEL ); + dvb =kzalloc (sizeof (*dvb),GFP_KERNEL );if (!dvb)return -ENOMEM ;
Signature · 1 line
2.14.1
PATCH 8/9 tm6000: Use common error handling code in tm6000_start_stream()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 15 Sep 2017 07:47:41 +0200
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
--- drivers/media/usb/tm6000/tm6000-dvb.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/media/usb/tm6000/tm6000-dvb.c +7 -4
@@ -134,8 +134,8 @@ static int tm6000_start_stream(struct tm6000_core *dev) dvb->bulk_urb->transfer_buffer =kzalloc (size,GFP_KERNEL );if (!dvb->bulk_urb->transfer_buffer) { -usb_free_urb (dvb->bulk_urb); -return -ENOMEM ; + ret = -ENOMEM ; + goto free_urb; } usb_fill_bulk_urb(dvb->bulk_urb, dev->udev, pipe,
@@ -160,11 +160,14 @@ static int tm6000_start_stream(struct tm6000_core *dev) ret);kfree (dvb->bulk_urb->transfer_buffer); -usb_free_urb (dvb->bulk_urb); -return ret; + goto free_urb; }return 0 ; + +free_urb: +usb_free_urb (dvb->bulk_urb); +return ret; }static void tm6000_stop_stream (struct tm6000_core *dev)
Signature · 1 line
2.14.1
PATCH 9/9 tm6000: Use common error handling code in tm6000_prepare_isoc()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 15 Sep 2017 08:02:33 +0200
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
--- drivers/media/usb/tm6000/tm6000-video.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/media/usb/tm6000/tm6000-video.c +7 -6
@@ -602,7 +602,5 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev) -if (!dev->isoc_ctl.transfer_buffer) { -kfree (dev->isoc_ctl.urb); -return -ENOMEM ; - } +if (!dev->isoc_ctl.transfer_buffer) + goto free_urb; dprintk(dev, V4L2_DEBUG_QUEUE, "Allocating %d x %d packets (%d bytes) of %d bytes each to handle %u size\n", max_packets, num_bufs, sb_size,
@@ -616,7 +614,6 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)tm6000_free_urb_buffers (dev); -kfree (dev->isoc_ctl.urb);kfree (dev->isoc_ctl.transfer_buffer); -return -ENOMEM ; + goto free_urb; }/* allocate urbs and transfer buffers */
@@ -646,6 +643,10 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev) }return 0 ; + +free_urb: +kfree (dev->isoc_ctl.urb); +return -ENOMEM ; }static int tm6000_start_thread (struct tm6000_core *dev)
Signature · 1 line
2.14.1