Cx231xx: Adjustments for several function implementations
Subsystems (2)
cover Cx231xx: Adjustments for several function implementations
From: Markus Elfring <[email protected]>
Date: Sun, 17 Sep 2017 21:30:12 +0200
Some update suggestions were taken into account
from static source code analysis.
Markus Elfring (8):
Delete eight error messages for a failed memory allocation Adjust 56 checks for null pointers
Improve six size determinations
Delete an unnecessary variable initialisation in dvb_init() Use common error handling code in dvb_init()
Use common error handling code in read_eeprom() Delete an unnecessary variable initialisation in read_eeprom() Use common error handling code in cx231xx_load_firmware()
drivers/media/usb/cx231xx/cx231xx-417.c | 65 +++++----- drivers/media/usb/cx231xx/cx231xx-audio.c | 2 +- drivers/media/usb/cx231xx/cx231xx-cards.c | 35 +++--- drivers/media/usb/cx231xx/cx231xx-core.c | 34 ++---- drivers/media/usb/cx231xx/cx231xx-dvb.c | 195 ++++++++++++------------------ drivers/media/usb/cx231xx/cx231xx-vbi.c | 17 +-- drivers/media/usb/cx231xx/cx231xx-video.c | 6 +- 7 files changed, 143 insertions(+), 211 deletions(-)
Signature · 1 line
2.14.1
PATCH 1/8 cx231xx: Delete eight error messages for a failed memory allocation
From: Markus Elfring <[email protected]>
Date: Sun, 17 Sep 2017 17:43:47 +0200
Omit extra messages for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
--- drivers/media/usb/cx231xx/cx231xx-core.c | 14 ++------------ drivers/media/usb/cx231xx/cx231xx-dvb.c | 7 ++----- drivers/media/usb/cx231xx/cx231xx-vbi.c | 11 +---------- 3 files changed, 5 insertions(+), 27 deletions(-)
drivers/media/usb/cx231xx/cx231xx-core.c +2 -12
@@ -1038,12 +1038,7 @@ int cx231xx_init_isoc(struct cx231xx *dev, int max_packets, -if (!dev->video_mode.isoc_ctl.urb) { -dev_err (dev->dev, -"cannot alloc memory for usb buffers\n" ); +if (!dev->video_mode.isoc_ctl.urb)return -ENOMEM ; - } dev->video_mode.isoc_ctl.transfer_buffer kzalloc(sizeof(void *) * num_bufs, GFP_KERNEL);if (!dev->video_mode.isoc_ctl.transfer_buffer) { -dev_err (dev->dev, -"cannot allocate memory for usbtransfer\n" );kfree (dev->video_mode.isoc_ctl.urb);
@@ -1173,12 +1168,7 @@ int cx231xx_init_bulk(struct cx231xx *dev, int max_packets, -if (!dev->video_mode.bulk_ctl.urb) { -dev_err (dev->dev, -"cannot alloc memory for usb buffers\n" ); +if (!dev->video_mode.bulk_ctl.urb)return -ENOMEM ; - } dev->video_mode.bulk_ctl.transfer_buffer kzalloc(sizeof(void *) * num_bufs, GFP_KERNEL);if (!dev->video_mode.bulk_ctl.transfer_buffer) { -dev_err (dev->dev, -"cannot allocate memory for usbtransfer\n" );kfree (dev->video_mode.bulk_ctl.urb);
drivers/media/usb/cx231xx/cx231xx-dvb.c +2 -5
@@ -618,9 +618,6 @@ static int dvb_init(struct cx231xx *dev) - -if (dvb =NULL ) { -dev_info (dev->dev, -"cx231xx_dvb: memory allocation failed\n" ); +if (!dvb)return -ENOMEM ; - } + dev->dvb = dvb; dev->cx231xx_set_analog_freq = cx231xx_set_analog_freq; dev->cx231xx_reset_analog_tuner = cx231xx_reset_analog_tuner;
drivers/media/usb/cx231xx/cx231xx-vbi.c +1 -10
@@ -420,12 +420,7 @@ int cx231xx_init_vbi_isoc(struct cx231xx *dev, int max_packets, -if (!dev->vbi_mode.bulk_ctl.urb) { -dev_err (dev->dev, -"cannot alloc memory for usb buffers\n" ); +if (!dev->vbi_mode.bulk_ctl.urb)return -ENOMEM ; - } dev->vbi_mode.bulk_ctl.transfer_buffer kzalloc(sizeof(void *) * num_bufs, GFP_KERNEL);if (!dev->vbi_mode.bulk_ctl.transfer_buffer) { -dev_err (dev->dev, -"cannot allocate memory for usbtransfer\n" );kfree (dev->vbi_mode.bulk_ctl.urb);
@@ -453,8 +448,4 @@ int cx231xx_init_vbi_isoc(struct cx231xx *dev, int max_packets,if (!dev->vbi_mode.bulk_ctl.transfer_buffer[i]) { -dev_err (dev->dev, -"unable to allocate %i bytes for transfer buffer %i%s\n" , - sb_size, i, -in_interrupt () ?" while in int" :"" );cx231xx_uninit_vbi_isoc (dev);return -ENOMEM ; }
Signature · 1 line
2.14.1
PATCH 2/8 cx231xx: Adjust 56 checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 17 Sep 2017 18:23:06 +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/cx231xx/cx231xx-417.c | 6 ++-- drivers/media/usb/cx231xx/cx231xx-audio.c | 2 +- drivers/media/usb/cx231xx/cx231xx-cards.c | 16 +++++----- drivers/media/usb/cx231xx/cx231xx-core.c | 20 ++++++------ drivers/media/usb/cx231xx/cx231xx-dvb.c | 51 ++++++++++++------------------- drivers/media/usb/cx231xx/cx231xx-vbi.c | 6 ++-- drivers/media/usb/cx231xx/cx231xx-video.c | 4 +-- 7 files changed, 45 insertions(+), 60 deletions(-)
drivers/media/usb/cx231xx/cx231xx-417.c +3 -3
@@ -954,13 +954,13 @@ static int cx231xx_load_firmware(struct cx231xx *dev) p_current_fw =vmalloc (1884180 *4 ); p_fw = p_current_fw; -if (p_current_fw =NULL ) { +if (!p_current_fw) {dprintk (2 ,"FAIL!!!\n" );return -ENOMEM ; } p_buffer =vmalloc (4096 ); -if (p_buffer =NULL ) { +if (!p_buffer) {dprintk (2 ,"FAIL!!!\n" );vfree (p_current_fw);return -ENOMEM ;
@@ -1711,7 +1711,7 @@ static int mpeg_open(struct file *file)/* allocate + initialize per filehandle data */ fh =kzalloc (sizeof (*fh),GFP_KERNEL ); - if (NULL = fh) { +if (!fh) {mutex_unlock (&dev->lock);return -ENOMEM ; }
drivers/media/usb/cx231xx/cx231xx-audio.c +1 -1
@@ -745,7 +745,7 @@ static int cx231xx_audio_init(struct cx231xx *dev)static int cx231xx_audio_fini (struct cx231xx *dev) { -if (dev =NULL ) +if (!dev)return 0 ;if (dev->has_alsa_audio !=1 ) {
drivers/media/usb/cx231xx/cx231xx-cards.c +8 -8
@@ -1156,7 +1156,7 @@ void cx231xx_card_setup(struct cx231xx *dev) dev->sd_cx25840 =v4l2_i2c_new_subdev (&dev->v4l2_dev,cx231xx_get_i2c_adap (dev,I2C_0 ),"cx25840" ,0x88 >>1 ,NULL ); -if (dev->sd_cx25840 =NULL ) +if (!dev->sd_cx25840)dev_err (dev->dev,"cx25840 subdev registration failure\n" );cx25840_call (dev, core, load_fw);
@@ -1171,7 +1171,7 @@ void cx231xx_card_setup(struct cx231xx *dev) tuner_i2c,"tuner" , dev->tuner_addr, NULL); -if (dev->sd_tuner =NULL ) +if (!dev->sd_tuner)dev_err (dev->dev,"tuner subdev registration failure\n" );else
@@ -1190,7 +1190,7 @@ void cx231xx_card_setup(struct cx231xx *dev) };struct eeprom *e =kzalloc (sizeof (*e),GFP_KERNEL ); -if (e =NULL ) { +if (!e) {dev_err (dev->dev,"failed to allocate memory to read eeprom\n" );break ;
@@ -1471,7 +1471,7 @@ static int cx231xx_init_v4l2(struct cx231xx *dev, dev->video_mode.num_alt); dev->video_mode.alt_max_pkt_size =devm_kmalloc_array (&udev->dev,32 , dev->video_mode.num_alt,GFP_KERNEL ); -if (dev->video_mode.alt_max_pkt_size =NULL ) +if (!dev->video_mode.alt_max_pkt_size)return -ENOMEM ;for (i =0 ; i < dev->video_mode.num_alt; i++) {
@@ -1512,7 +1512,7 @@ static int cx231xx_init_v4l2(struct cx231xx *dev,/* compute alternate max packet sizes for vbi */ dev->vbi_mode.alt_max_pkt_size =devm_kmalloc_array (&udev->dev,32 , dev->vbi_mode.num_alt,GFP_KERNEL ); -if (dev->vbi_mode.alt_max_pkt_size =NULL ) +if (!dev->vbi_mode.alt_max_pkt_size)return -ENOMEM ;for (i =0 ; i < dev->vbi_mode.num_alt; i++) {
@@ -1554,7 +1554,7 @@ static int cx231xx_init_v4l2(struct cx231xx *dev, dev->sliced_cc_mode.end_point_addr, dev->sliced_cc_mode.num_alt); dev->sliced_cc_mode.alt_max_pkt_size =devm_kmalloc_array (&udev->dev,32 , dev->sliced_cc_mode.num_alt,GFP_KERNEL ); -if (dev->sliced_cc_mode.alt_max_pkt_size =NULL ) +if (!dev->sliced_cc_mode.alt_max_pkt_size)return -ENOMEM ;for (i =0 ; i < dev->sliced_cc_mode.num_alt; i++) {
@@ -1618,7 +1618,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface,/* allocate memory for our device state and initialize it */ dev =devm_kzalloc (&udev->dev,sizeof (*dev),GFP_KERNEL ); -if (dev =NULL ) { +if (!dev) { retval = -ENOMEM ; goto err_if; }
@@ -1748,7 +1748,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface, dev->ts1_mode.num_alt); dev->ts1_mode.alt_max_pkt_size =devm_kmalloc_array (&udev->dev,32 , dev->ts1_mode.num_alt,GFP_KERNEL ); -if (dev->ts1_mode.alt_max_pkt_size =NULL ) { +if (!dev->ts1_mode.alt_max_pkt_size) { retval = -ENOMEM ; goto err_video_alt; }
drivers/media/usb/cx231xx/cx231xx-core.c +10 -10
@@ -69,9 +69,9 @@ static DEFINE_MUTEX(cx231xx_devlist_mutex);*/ void cx231xx_remove_from_devlist (struct cx231xx *dev) { -if (dev =NULL ) +if (!dev)return ; -if (dev->udev =NULL ) +if (!dev->udev)return ;if (atomic_read (&dev->devlist_count) >0 ) {
@@ -508,7 +508,7 @@ int cx231xx_set_video_alternate(struct cx231xx *dev)cx231xx_coredbg ("minimum isoc packet size: %u (alt=%d)\n" , min_pkt_size, dev->video_mode.alt); -if (dev->video_mode.alt_max_pkt_size !=NULL ) +if (dev->video_mode.alt_max_pkt_size) dev->video_mode.max_pkt_size dev->video_mode.alt_max_pkt_size[dev->video_mode.alt]; cx231xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n",
@@ -539,7 +539,7 @@ int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt) dev->current_pcb_config.hs_config_info[0 ].interface_info. ts1_index +1 ; dev->ts1_mode.alt = alt; -if (dev->ts1_mode.alt_max_pkt_size !=NULL ) +if (dev->ts1_mode.alt_max_pkt_size) max_pkt_size = dev->ts1_mode.max_pkt_size dev->ts1_mode.alt_max_pkt_size[dev->ts1_mode.alt];break ;
@@ -553,7 +553,7 @@ int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt) dev->current_pcb_config.hs_config_info[0 ].interface_info. audio_index +1 ; dev->adev.alt = alt; -if (dev->adev.alt_max_pkt_size !=NULL ) +if (dev->adev.alt_max_pkt_size) max_pkt_size = dev->adev.max_pkt_size dev->adev.alt_max_pkt_size[dev->adev.alt];break ;
@@ -562,7 +562,7 @@ int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt) dev->current_pcb_config.hs_config_info[0 ].interface_info. video_index +1 ; dev->video_mode.alt = alt; -if (dev->video_mode.alt_max_pkt_size !=NULL ) +if (dev->video_mode.alt_max_pkt_size) max_pkt_size = dev->video_mode.max_pkt_size dev->video_mode.alt_max_pkt_size[dev->video_mode. alt];
@@ -574,7 +574,7 @@ int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt) dev->current_pcb_config.hs_config_info[0 ].interface_info. vanc_index +1 ; dev->vbi_mode.alt = alt; -if (dev->vbi_mode.alt_max_pkt_size !=NULL ) +if (dev->vbi_mode.alt_max_pkt_size) max_pkt_size = dev->vbi_mode.max_pkt_size dev->vbi_mode.alt_max_pkt_size[dev->vbi_mode.alt];break ;
@@ -583,7 +583,7 @@ int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt) dev->current_pcb_config.hs_config_info[0 ].interface_info. hanc_index +1 ; dev->sliced_cc_mode.alt = alt; -if (dev->sliced_cc_mode.alt_max_pkt_size !=NULL ) +if (dev->sliced_cc_mode.alt_max_pkt_size) max_pkt_size = dev->sliced_cc_mode.max_pkt_size dev->sliced_cc_mode.alt_max_pkt_size[dev-> sliced_cc_mode.
@@ -768,7 +768,7 @@ int cx231xx_ep5_bulkout(struct cx231xx *dev, u8 *firmware, u16 size)u32 *buffer; buffer =kzalloc (4096 ,GFP_KERNEL ); -if (buffer =NULL ) +if (!buffer)return -ENOMEM ;memcpy (&buffer[0 ], firmware,4096 );
@@ -1009,7 +1009,7 @@ int cx231xx_init_isoc(struct cx231xx *dev, int max_packets,cx231xx_uninit_isoc (dev); dma_q->p_left_data =kzalloc (4096 ,GFP_KERNEL ); -if (dma_q->p_left_data =NULL ) +if (!dma_q->p_left_data)return -ENOMEM ; dev->video_mode.isoc_ctl.isoc_copy = isoc_copy;
drivers/media/usb/cx231xx/cx231xx-dvb.c +19 -32
157 lines not on this page · raw message
drivers/media/usb/cx231xx/cx231xx-vbi.c +2 -4
@@ -630,8 +630,7 @@ void cx231xx_reset_vbi_buffer(struct cx231xx *dev,struct cx231xx_buffer *buf; buf = dev->vbi_mode.bulk_ctl.buf; - -if (buf =NULL ) { +if (!buf) {/* first try to get the buffer */ get_next_vbi_buf (dma_q, &buf);
@@ -654,8 +653,7 @@ int cx231xx_do_vbi_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,int offset, lencopy; buf = dev->vbi_mode.bulk_ctl.buf; - -if (buf =NULL ) +if (!buf)return -EINVAL ; p_out_buffer =videobuf_to_vmalloc (&buf->vb);
drivers/media/usb/cx231xx/cx231xx-video.c +2 -2
@@ -634,7 +634,7 @@ void cx231xx_reset_video_buffer(struct cx231xx *dev,else buf = dev->video_mode.bulk_ctl.buf; -if (buf =NULL ) { +if (!buf) {/* first try to get the buffer */ get_next_buf (dma_q, &buf);
@@ -663,7 +663,7 @@ int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,else buf = dev->video_mode.bulk_ctl.buf; -if (buf =NULL ) +if (!buf)return -1 ; p_out_buffer =videobuf_to_vmalloc (&buf->vb);
Signature · 1 line
2.14.1
PATCH 3/8 cx231xx: Improve six size determinations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 17 Sep 2017 18:38:50 +0200
Replace the specification of data structures by variable references as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/media/usb/cx231xx/cx231xx-dvb.c | 10 +++++----- drivers/media/usb/cx231xx/cx231xx-video.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/media/usb/cx231xx/cx231xx-dvb.c +5 -5
@@ -611,5 +611,5 @@ static int dvb_init(struct cx231xx *dev)return 0 ; } - dvb =kzalloc (sizeof (struct cx231xx_dvb ),GFP_KERNEL ); + dvb =kzalloc (sizeof (*dvb),GFP_KERNEL );if (!dvb)
@@ -754,7 +754,7 @@ static int dvb_init(struct cx231xx *dev) si2165_pdata.chip_mode =SI2165_MODE_PLL_XTAL , si2165_pdata.ref_freq_Hz =16000000 , -memset (&info,0 ,sizeof (struct i2c_board_info )); +memset (&info,0 ,sizeof (info));strlcpy (info.type,"si2165" ,I2C_NAME_SIZE ); info.addr =0x64 ; info.platform_data = &si2165_pdata;
@@ -801,7 +801,7 @@ static int dvb_init(struct cx231xx *dev) si2165_pdata.chip_mode =SI2165_MODE_PLL_EXT , si2165_pdata.ref_freq_Hz =24000000 , -memset (&info,0 ,sizeof (struct i2c_board_info )); +memset (&info,0 ,sizeof (info));strlcpy (info.type,"si2165" ,I2C_NAME_SIZE ); info.addr =0x64 ; info.platform_data = &si2165_pdata;
@@ -822,7 +822,7 @@ static int dvb_init(struct cx231xx *dev) dvb->i2c_client_demod = client; -memset (&info,0 ,sizeof (struct i2c_board_info )); +memset (&info,0 ,sizeof (info)); dev->dvb->frontend->ops.i2c_gate_ctrl =NULL ;
@@ -869,7 +869,7 @@ static int dvb_init(struct cx231xx *dev)struct i2c_board_info info;struct si2157_config si2157_config; -memset (&info,0 ,sizeof (struct i2c_board_info )); +memset (&info,0 ,sizeof (info)); dev->dvb->frontend = dvb_attach(lgdt3306a_attach, &hauppauge_955q_lgdt3306a_config,
drivers/media/usb/cx231xx/cx231xx-video.c +1 -1
@@ -1771,5 +1771,5 @@ static int cx231xx_v4l2_open(struct file *filp) }#endif - fh =kzalloc (sizeof (struct cx231xx_fh ),GFP_KERNEL ); + fh =kzalloc (sizeof (*fh),GFP_KERNEL );if (!fh)
Signature · 1 line
2.14.1
PATCH 4/8 cx231xx: Delete an unnecessary variable initialisation in dvb_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 17 Sep 2017 18:53:16 +0200
The variable "result" will eventually be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/media/usb/cx231xx/cx231xx-dvb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/cx231xx/cx231xx-dvb.c +1 -1
@@ -601,6 +601,6 @@ static void unregister_dvb(struct cx231xx_dvb *dvb)static int dvb_init (struct cx231xx *dev) { -int result =0 ; +int result;struct cx231xx_dvb *dvb;struct i2c_adapter *tuner_i2c;
Signature · 1 line
2.14.1
PATCH 5/8 cx231xx: Use common error handling code in dvb_init()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 17 Sep 2017 20:10:34 +0200
Add jump targets so that a bit of exception handling can be better reused at the end of this function.
--- drivers/media/usb/cx231xx/cx231xx-dvb.c | 135 +++++++++++++------------------- 1 file changed, 53 insertions(+), 82 deletions(-)
drivers/media/usb/cx231xx/cx231xx-dvb.c +53 -82
@@ -635,19 +635,15 @@ static int dvb_init(struct cx231xx *dev)if (!dev->dvb->frontend) {dev_err (dev->dev,"Failed to attach s5h1432 front end\n" ); - result = -EINVAL ; - goto out_free; + goto e_inval; }/* define general-purpose callback pointer */ dvb->frontend->callback = cx231xx_tuner_callback;if (!dvb_attach (xc5000_attach, dev->dvb->frontend, - tuner_i2c, - &cnxt_rde250_tunerconfig)) { - result = -EINVAL ; - goto out_free; - } + tuner_i2c, &cnxt_rde250_tunerconfig)) + goto e_inval;break ;case CX231XX_BOARD_CNXT_SHELBY :
@@ -659,19 +655,16 @@ static int dvb_init(struct cx231xx *dev)if (!dev->dvb->frontend) {dev_err (dev->dev,"Failed to attach s5h1411 front end\n" ); - result = -EINVAL ; - goto out_free; + goto e_inval; }/* define general-purpose callback pointer */ dvb->frontend->callback = cx231xx_tuner_callback;if (!dvb_attach (xc5000_attach, dev->dvb->frontend, - tuner_i2c, - &cnxt_rdu250_tunerconfig)) { - result = -EINVAL ; - goto out_free; - } + tuner_i2c, &cnxt_rdu250_tunerconfig)) + goto e_inval; +break ;case CX231XX_BOARD_CNXT_RDE_253S :
@@ -681,19 +674,16 @@ static int dvb_init(struct cx231xx *dev)if (!dev->dvb->frontend) {dev_err (dev->dev,"Failed to attach s5h1432 front end\n" ); - result = -EINVAL ; - goto out_free; + goto e_inval; }/* define general-purpose callback pointer */ dvb->frontend->callback = cx231xx_tuner_callback;if (!dvb_attach (tda18271_attach, dev->dvb->frontend, -0x60 , tuner_i2c, - &cnxt_rde253s_tunerconfig)) { - result = -EINVAL ; - goto out_free; - } +0x60 , tuner_i2c, &cnxt_rde253s_tunerconfig)) + goto e_inval; +break ;case CX231XX_BOARD_CNXT_RDU_253S :case CX231XX_BOARD_KWORLD_UB445_USB_HYBRID :
@@ -704,19 +694,16 @@ static int dvb_init(struct cx231xx *dev)if (!dev->dvb->frontend) {dev_err (dev->dev,"Failed to attach s5h1411 front end\n" ); - result = -EINVAL ; - goto out_free; + goto e_inval; }/* define general-purpose callback pointer */ dvb->frontend->callback = cx231xx_tuner_callback;if (!dvb_attach (tda18271_attach, dev->dvb->frontend, -0x60 , tuner_i2c, - &cnxt_rde253s_tunerconfig)) { - result = -EINVAL ; - goto out_free; - } +0x60 , tuner_i2c, &cnxt_rde253s_tunerconfig)) + goto e_inval; +break ;case CX231XX_BOARD_HAUPPAUGE_EXETER :
@@ -730,8 +717,7 @@ static int dvb_init(struct cx231xx *dev)if (!dev->dvb->frontend) {dev_err (dev->dev,"Failed to attach LG3305 front end\n" ); - result = -EINVAL ; - goto out_free; + goto e_inval; }/* define general-purpose callback pointer */
@@ -763,14 +749,12 @@ static int dvb_init(struct cx231xx *dev)if (!client || !client->dev.driver || !dev->dvb->frontend) {dev_err (dev->dev,"Failed to attach SI2165 front end\n" ); - result = -EINVAL ; - goto out_free; + goto e_inval; }if (!try_module_get (client->dev.driver->owner)) {i2c_unregister_device (client); - result = -ENODEV ; - goto out_free; + goto e_nodev; } dvb->i2c_client_demod = client;
@@ -810,14 +794,12 @@ static int dvb_init(struct cx231xx *dev)if (!client || !client->dev.driver || !dev->dvb->frontend) {dev_err (dev->dev,"Failed to attach SI2165 front end\n" ); - result = -EINVAL ; - goto out_free; + goto e_inval; }if (!try_module_get (client->dev.driver->owner)) {i2c_unregister_device (client); - result = -ENODEV ; - goto out_free; + goto e_nodev; } dvb->i2c_client_demod = client;
@@ -845,17 +827,12 @@ static int dvb_init(struct cx231xx *dev) client =i2c_new_device ( tuner_i2c, &info); -if (!client || !client->dev.driver) { -dvb_frontend_detach (dev->dvb->frontend); - result = -ENODEV ; - goto out_free; - } +if (!client || !client->dev.driver) + goto detach_frontend;if (!try_module_get (client->dev.driver->owner)) {i2c_unregister_device (client); -dvb_frontend_detach (dev->dvb->frontend); - result = -ENODEV ; - goto out_free; + goto detach_frontend; } dev->cx231xx_reset_analog_tuner =NULL ;
@@ -878,8 +855,7 @@ static int dvb_init(struct cx231xx *dev)if (!dev->dvb->frontend) {dev_err (dev->dev,"Failed to attach LGDT3306A frontend.\n" ); - result = -EINVAL ; - goto out_free; + goto e_inval; } dev->dvb->frontend->ops.i2c_gate_ctrl =NULL ;
@@ -903,17 +879,12 @@ static int dvb_init(struct cx231xx *dev) client =i2c_new_device ( tuner_i2c, &info); -if (!client || !client->dev.driver) { -dvb_frontend_detach (dev->dvb->frontend); - result = -ENODEV ; - goto out_free; - } +if (!client || !client->dev.driver) + goto detach_frontend;if (!try_module_get (client->dev.driver->owner)) {i2c_unregister_device (client); -dvb_frontend_detach (dev->dvb->frontend); - result = -ENODEV ; - goto out_free; + goto detach_frontend; } dev->cx231xx_reset_analog_tuner =NULL ;
@@ -934,8 +905,7 @@ static int dvb_init(struct cx231xx *dev)if (!dev->dvb->frontend) {dev_err (dev->dev,"Failed to attach mb86a20s demod\n" ); - result = -EINVAL ; - goto out_free; + goto e_inval; }/* define general-purpose callback pointer */
@@ -966,15 +936,12 @@ static int dvb_init(struct cx231xx *dev)request_module (info.type); client =i2c_new_device (demod_i2c, &info); -if (!client || !client->dev.driver) { - result = -ENODEV ; - goto out_free; - } +if (!client || !client->dev.driver) + goto e_nodev;if (!try_module_get (client->dev.driver->owner)) {i2c_unregister_device (client); - result = -ENODEV ; - goto out_free; + goto e_nodev; } dvb->i2c_client_demod = client;
@@ -994,19 +961,12 @@ static int dvb_init(struct cx231xx *dev)request_module (info.type); client =i2c_new_device (tuner_i2c, &info); -if (!client || !client->dev.driver) { -module_put (dvb->i2c_client_demod->dev.driver->owner); -i2c_unregister_device (dvb->i2c_client_demod); - result = -ENODEV ; - goto out_free; - } +if (!client || !client->dev.driver) + goto put_module;if (!try_module_get (client->dev.driver->owner)) {i2c_unregister_device (client); -module_put (dvb->i2c_client_demod->dev.driver->owner); -i2c_unregister_device (dvb->i2c_client_demod); - result = -ENODEV ; - goto out_free; + goto put_module; } dev->cx231xx_reset_analog_tuner =NULL ;
@@ -1030,15 +990,12 @@ static int dvb_init(struct cx231xx *dev)request_module (info.type); client =i2c_new_device (demod_i2c, &info); -if (!client || !client->dev.driver) { - result = -ENODEV ; - goto out_free; - } +if (!client || !client->dev.driver) + goto e_nodev;if (!try_module_get (client->dev.driver->owner)) {i2c_unregister_device (client); - result = -ENODEV ; - goto out_free; + goto e_nodev; } dvb->i2c_client_demod = client;
@@ -1061,8 +1018,7 @@ static int dvb_init(struct cx231xx *dev)if (!dvb->frontend) {dev_err (dev->dev,"%s/2: frontend initialization failed\n" , dev->name); - result = -EINVAL ; - goto out_free; + goto e_inval; }/* register everything */
@@ -1079,6 +1035,21 @@ static int dvb_init(struct cx231xx *dev)mutex_unlock (&dev->lock);return result; +put_module: +module_put (dvb->i2c_client_demod->dev.driver->owner); +i2c_unregister_device (dvb->i2c_client_demod); + goto e_nodev; + +detach_frontend: +dvb_frontend_detach (dev->dvb->frontend); + +e_nodev: + result = -ENODEV ; + goto out_free; + +e_inval: + result = -EINVAL ; + out_free:kfree (dvb); dev->dvb =NULL ;
Signature · 1 line
2.14.1
PATCH 6/8 cx231xx: Use common error handling code in read_eeprom()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 17 Sep 2017 20:22:15 +0200
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
This issue was detected by using the Coccinelle software.
--- drivers/media/usb/cx231xx/cx231xx-cards.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/media/usb/cx231xx/cx231xx-cards.c +9 -8
@@ -1117,20 +1117,17 @@ static int read_eeprom(struct cx231xx *dev, struct i2c_client *client,/* start reading at offset 0 */ ret =i2c_transfer (client->adapter, &msg_write,1 ); -if (ret <0 ) { -dev_err (dev->dev,"Can't read eeprom\n" ); -return ret; - } +if (ret <0 ) + goto report_failure;while (len_todo >0 ) { msg_read.len = (len_todo >64 ) ?64 : len_todo; msg_read.buf = eedata_cur; ret =i2c_transfer (client->adapter, &msg_read,1 ); -if (ret <0 ) { -dev_err (dev->dev,"Can't read eeprom\n" ); -return ret; - } +if (ret <0 ) + goto report_failure; + eedata_cur += msg_read.len; len_todo -= msg_read.len; }
@@ -1140,6 +1137,10 @@ static int read_eeprom(struct cx231xx *dev, struct i2c_client *client, i, 16, &eedata[i]);return 0 ; + +report_failure: +dev_err (dev->dev,"Can't read eeprom\n" ); +return ret; }void cx231xx_card_setup (struct cx231xx *dev)
Signature · 1 line
2.14.1
PATCH 7/8 cx231xx: Delete an unnecessary variable initialisation in read_eeprom()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 17 Sep 2017 20:28:00 +0200
The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.
--- drivers/media/usb/cx231xx/cx231xx-cards.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/cx231xx/cx231xx-cards.c +1 -1
@@ -1106,6 +1106,6 @@ static void cx231xx_config_tuner(struct cx231xx *dev)static int read_eeprom (struct cx231xx *dev,struct i2c_client *client,u8 *eedata,int len) { -int ret =0 ; +int ret;u8 start_offset =0 ;int len_todo = len;
Signature · 1 line
2.14.1
PATCH 8/8 cx231xx: Use common error handling code in cx231xx_load_firmware()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Sun, 17 Sep 2017 21:07:39 +0200
Add jump targets so that a bit of exception handling can be better reused at the end of this function.
--- drivers/media/usb/cx231xx/cx231xx-417.c | 61 ++++++++++++++++----------------- 1 file changed, 29 insertions(+), 32 deletions(-)
drivers/media/usb/cx231xx/cx231xx-417.c +29 -32
@@ -954,16 +954,13 @@ static int cx231xx_load_firmware(struct cx231xx *dev) p_current_fw =vmalloc (1884180 *4 ); p_fw = p_current_fw; -if (!p_current_fw) { -dprintk (2 ,"FAIL!!!\n" ); -return -ENOMEM ; - } +if (!p_current_fw) + goto e_nomem; p_buffer =vmalloc (4096 );if (!p_buffer) { -dprintk (2 ,"FAIL!!!\n" );vfree (p_current_fw); -return -ENOMEM ; + goto e_nomem; }dprintk (2 ,"%s()\n" , __func__);
@@ -986,9 +983,7 @@ static int cx231xx_load_firmware(struct cx231xx *dev)if (retval !=0 ) {dev_err (dev->dev,"%s: Error with mc417_register_write\n" , __func__); -vfree (p_current_fw); -vfree (p_buffer); -return retval; + goto free_fw; } retval = request_firmware(&firmware, CX231xx_FIRM_IMAGE_NAME,
@@ -1000,28 +995,20 @@ static int cx231xx_load_firmware(struct cx231xx *dev) CX231xx_FIRM_IMAGE_NAME);dev_err (dev->dev,"Please fix your hotplug setup, the board will not work without firmware loaded!\n" ); -vfree (p_current_fw); -vfree (p_buffer); -return retval; + goto free_fw; }if (firmware->size != CX231xx_FIRM_IMAGE_SIZE) {dev_err (dev->dev,"ERROR: Firmware size mismatch (have %zd, expected %d)\n" , firmware->size, CX231xx_FIRM_IMAGE_SIZE); -release_firmware (firmware); -vfree (p_current_fw); -vfree (p_buffer); -return -EINVAL ; + goto e_inval; }if (0 !=memcmp (firmware->data, magic,8 )) {dev_err (dev->dev,"ERROR: Firmware magic mismatch, wrong file?\n" ); -release_firmware (firmware); -vfree (p_current_fw); -vfree (p_buffer); -return -EINVAL ; + goto e_inval; }initGPIO (dev);
@@ -1065,26 +1052,36 @@ static int cx231xx_load_firmware(struct cx231xx *dev) retval |=mc417_register_write (dev,IVTV_REG_HW_BLOCKS ,IVTV_CMD_HW_BLOCKS_RST ); -if (retval <0 ) { -dev_err (dev->dev, -"%s: Error with mc417_register_write\n" , - __func__); -return retval; - } +if (retval <0 ) + goto report_write_failure; +/* F/W power up disturbs the GPIOs, restore state */ retval |=mc417_register_write (dev,0x9020 , gpio_output); retval |=mc417_register_write (dev,0x900C , value); retval |=mc417_register_read (dev,IVTV_REG_VPU , &value); retval |=mc417_register_write (dev,IVTV_REG_VPU , value &0xFFFFFFE8 ); +if (retval <0 ) + goto report_write_failure; -if (retval <0 ) { -dev_err (dev->dev, -"%s: Error with mc417_register_write\n" , - __func__); -return retval; - }return 0 ; + +e_nomem: +dprintk (2 ,"FAIL!!!\n" ); +return -ENOMEM ; + +e_inval: + retval = -EINVAL ; +release_firmware (firmware); + +free_fw: +vfree (p_current_fw); +vfree (p_buffer); +return retval; + +report_write_failure: +dev_err (dev->dev,"%s: Error with mc417_register_write\n" , __func__); +return retval; }static void cx231xx_417_check_encoder (struct cx231xx *dev)
Signature · 1 line
2.14.1