Use common error handling code in 20 functions
Subsystems (9)
PATCH v2 1/1 Use common error handling code in 20 functions
From: Markus Elfring <[email protected]>
Date: Mon, 19 Feb 2018 18:50:40 +0100
Adjust jump targets so that a bit of exception handling can be better reused at the end of these functions.
This issue was partly detected by using the Coccinelle software.
---
v2:
Hans Verkuil insisted on patch squashing. Thus several changes were recombined based on source files from Linux next-20180216.
The implementation of the function "tda8261_set_params" was improved after a notification by Christoph Böhmwalder on 2017-09-26.
drivers/media/dvb-core/dmxdev.c | 16 ++++---- drivers/media/dvb-frontends/tda1004x.c | 20 ++++++---- drivers/media/dvb-frontends/tda8261.c | 19 ++++++---- drivers/media/pci/bt8xx/dst.c | 19 ++++++---- drivers/media/pci/bt8xx/dst_ca.c | 30 +++++++-------- drivers/media/pci/cx88/cx88-input.c | 17 +++++---- drivers/media/platform/omap3isp/ispvideo.c | 29 +++++++-------- .../media/platform/qcom/camss-8x16/camss-csid.c | 20 +++++----- drivers/media/tuners/tuner-xc2028.c | 30 +++++++-------- drivers/media/usb/cpia2/cpia2_usb.c | 13 ++++--- drivers/media/usb/gspca/gspca.c | 17 +++++---- drivers/media/usb/gspca/sn9c20x.c | 17 +++++---- drivers/media/usb/pvrusb2/pvrusb2-ioread.c | 10 +++-- drivers/media/usb/tm6000/tm6000-cards.c | 7 ++-- drivers/media/usb/tm6000/tm6000-dvb.c | 11 ++++-- drivers/media/usb/tm6000/tm6000-video.c | 13 ++++--- drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c | 13 +++---- drivers/media/usb/ttusb-dec/ttusb_dec.c | 43 ++++++++-------------- drivers/media/usb/uvc/uvc_v4l2.c | 13 ++++--- 19 files changed, 180 insertions(+), 177 deletions(-)
drivers/media/dvb-core/dmxdev.c +8 -8
@@ -645,18 +645,18 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev, tsfeed->priv = filter; ret = tsfeed->set (tsfeed, feed->pid, ts_type, ts_pes, timeout); -if (ret <0 ) { - dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); -return ret; - } +if (ret <0 ) + goto release_feed; ret = tsfeed->start_filtering (tsfeed); -if (ret <0 ) { - dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); -return ret; - } +if (ret <0 ) + goto release_feed;return 0 ; + +release_feed: + dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); +return ret; }static int dvb_dmxdev_filter_start (struct dmxdev_filter *filter)
drivers/media/dvb-frontends/tda1004x.c +12 -8
@@ -1299,20 +1299,22 @@ struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config, id =tda1004x_read_byte (state,TDA1004X_CHIPID );if (id <0 ) {printk (KERN_ERR "tda10045: chip is not answering. Giving up.\n" ); -kfree (state); -return NULL ; + goto free_state; }if (id !=0x25 ) {printk (KERN_ERR "Invalid tda1004x ID = 0x%02x. Can't proceed\n" , id); -kfree (state); -return NULL ; + goto free_state; }/* create dvb_frontend */ memcpy (&state->frontend.ops, &tda10045_ops,sizeof (struct dvb_frontend_ops )); state->frontend.demodulator_priv = state;return &state->frontend; + +free_state: +kfree (state); +return NULL ; }static const struct dvb_frontend_ops tda10046_ops = {
@@ -1369,19 +1371,21 @@ struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config, id =tda1004x_read_byte (state,TDA1004X_CHIPID );if (id <0 ) {printk (KERN_ERR "tda10046: chip is not answering. Giving up.\n" ); -kfree (state); -return NULL ; + goto free_state; }if (id !=0x46 ) {printk (KERN_ERR "Invalid tda1004x ID = 0x%02x. Can't proceed\n" , id); -kfree (state); -return NULL ; + goto free_state; }/* create dvb_frontend */ memcpy (&state->frontend.ops, &tda10046_ops,sizeof (struct dvb_frontend_ops )); state->frontend.demodulator_priv = state;return &state->frontend; + +free_state: +kfree (state); +return NULL ; }module_param (debug, int,0644 );
drivers/media/dvb-frontends/tda8261.c +11 -8
@@ -129,18 +129,17 @@ static int tda8261_set_params(struct dvb_frontend *fe)/* Set params */ err =tda8261_write (state, buf); -if (err <0 ) { -pr_err ("%s: I/O Error\n" , __func__); -return err; - } +if (err <0 ) + goto report_failure; +/* sleep for some time */ pr_debug ("%s: Waiting to Phase LOCK\n" , __func__);msleep (20 );/* check status */ -if ((err =tda8261_get_status (fe, &status)) <0 ) { -pr_err ("%s: I/O Error\n" , __func__); -return err; - } + err =tda8261_get_status (fe, &status); +if (err <0 ) + goto report_failure; +if (status =1 ) {pr_debug ("%s: Tuner Phase locked: status=%d\n" , __func__, status);
@@ -150,6 +149,10 @@ static int tda8261_set_params(struct dvb_frontend *fe) }return 0 ; + +report_failure: +pr_err ("%s: I/O Error\n" , __func__); +return err; }static void tda8261_release (struct dvb_frontend *fe)
drivers/media/pci/bt8xx/dst.c +11 -8
@@ -134,17 +134,20 @@ EXPORT_SYMBOL(rdc_reset_state);static int rdc_8820_reset (struct dst_state *state) {dprintk (3 ,"Resetting DST\n" ); -if (dst_gpio_outb (state,RDC_8820_RESET ,RDC_8820_RESET ,0 ,NO_DELAY ) <0 ) { -pr_err ("dst_gpio_outb ERROR !\n" ); -return -1 ; - } +if (dst_gpio_outb (state,RDC_8820_RESET ,RDC_8820_RESET ,0 ,NO_DELAY ) + <0 ) + goto report_failure; +udelay (1000 ); -if (dst_gpio_outb (state,RDC_8820_RESET ,RDC_8820_RESET ,RDC_8820_RESET ,DELAY ) <0 ) { -pr_err ("dst_gpio_outb ERROR !\n" ); -return -1 ; - } +if (dst_gpio_outb (state,RDC_8820_RESET ,RDC_8820_RESET , +RDC_8820_RESET ,DELAY ) <0 ) + goto report_failure;return 0 ; + +report_failure: +pr_err ("dst_gpio_outb ERROR !\n" ); +return -1 ; }static int dst_pio_enable (struct dst_state *state)
drivers/media/pci/bt8xx/dst_ca.c +15 -15
@@ -83,33 +83,33 @@ static int dst_ci_command(struct dst_state* state, u8 * data, u8 *ca_string, u8if (write_dst (state, data, len)) {dprintk (verbose,DST_CA_INFO ,1 ," Write not successful, trying to recover" ); -dst_error_recovery (state); - goto error; + goto error_recovery; }if ((dst_pio_disable (state)) <0 ) {dprintk (verbose,DST_CA_ERROR ,1 ," DST PIO disable failed." ); - goto error; - } -if (read_dst (state, &reply,GET_ACK ) <0 ) { -dprintk (verbose,DST_CA_INFO ,1 ," Read not successful, trying to recover" ); -dst_error_recovery (state); - goto error; + goto unlock; } +if (read_dst (state, &reply,GET_ACK ) <0 ) + goto report_read_failure; +if (read) {if (!dst_wait_dst_ready (state,LONG_DELAY )) {dprintk (verbose,DST_CA_NOTICE ,1 ," 8820 not ready" ); - goto error; - } -if (read_dst (state, ca_string,128 ) <0 ) {/* Try to make this dynamic */ -dprintk (verbose,DST_CA_INFO ,1 ," Read not successful, trying to recover" ); -dst_error_recovery (state); - goto error; + goto unlock; } +/* Try to make this dynamic */ +if (read_dst (state, ca_string,128 ) <0 ) + goto report_read_failure; }mutex_unlock (&state->dst_mutex);return 0 ; -error: +report_read_failure: +dprintk (verbose,DST_CA_INFO ,1 , +" Read not successful, trying to recover" ); +error_recovery: +dst_error_recovery (state); +unlock:mutex_unlock (&state->dst_mutex);return -EIO ; }
drivers/media/pci/cx88/cx88-input.c +9 -8
@@ -566,20 +566,17 @@ static int get_key_pvr2000(struct IR_i2c *ir, enum rc_proto *protocol,/* poll IR chip */ flags =i2c_smbus_read_byte_data (ir->c,0x10 ); -if (flags <0 ) { -dprintk ("read error\n" ); -return 0 ; - } +if (flags <0 ) + goto report_read_failure; +/* key pressed ? */ if (0 = (flags & 0x80))return 0 ;/* read actual key code */ code =i2c_smbus_read_byte_data (ir->c,0x00 ); -if (code <0 ) { -dprintk ("read error\n" ); -return 0 ; - } +if (code <0 ) + goto report_read_failure;dprintk ("IR Key/Flags: (0x%02x/0x%02x)\n" , code &0xff , flags &0xff );
@@ -588,6 +585,10 @@ static int get_key_pvr2000(struct IR_i2c *ir, enum rc_proto *protocol, *scancode = code &0xff ; *toggle =0 ;return 1 ; + +report_read_failure: +dprintk ("read error\n" ); +return 0 ; }void cx88_i2c_init_ir (struct cx88_core *core)
drivers/media/platform/omap3isp/ispvideo.c +13 -16
@@ -1315,14 +1315,12 @@ static int isp_video_open(struct file *file)/* If this is the first user, initialise the pipeline. */ if (omap3isp_get (video->isp) =NULL ) { ret = -EBUSY ; - goto done; + goto delete_fh; } ret =v4l2_pipeline_pm_use (&video->video.entity,1 ); -if (ret <0 ) { -omap3isp_put (video->isp); - goto done; - } +if (ret <0 ) + goto put_isp; queue = &handle->queue; queue->type = video->type;
@@ -1335,10 +1333,8 @@ static int isp_video_open(struct file *file) queue->dev = video->isp->dev; ret =vb2_queue_init (&handle->queue); -if (ret <0 ) { -omap3isp_put (video->isp); - goto done; - } +if (ret <0 ) + goto put_isp;memset (&handle->format,0 ,sizeof (handle->format)); handle->format.type = video->type;
@@ -1346,14 +1342,15 @@ static int isp_video_open(struct file *file) handle->video = video; file->private_data = &handle->vfh; + goto exit; -done: -if (ret <0 ) { -v4l2_fh_del (&handle->vfh); -v4l2_fh_exit (&handle->vfh); -kfree (handle); - } - +put_isp: +omap3isp_put (video->isp); +delete_fh: +v4l2_fh_del (&handle->vfh); +v4l2_fh_exit (&handle->vfh); +kfree (handle); +exit:return ret; }
drivers/media/platform/qcom/camss-8x16/camss-csid.c +10 -10
@@ -328,16 +328,12 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)return ret; ret =csid_set_clock_rates (csid); -if (ret <0 ) { -regulator_disable (csid->vdda); -return ret; - } +if (ret <0 ) + goto disable_regulator; ret =camss_enable_clocks (csid->nclocks, csid->clock, dev); -if (ret <0 ) { -regulator_disable (csid->vdda); -return ret; - } +if (ret <0 ) + goto disable_regulator;enable_irq (csid->irq);
@@ -345,8 +341,7 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)if (ret <0 ) {disable_irq (csid->irq);camss_disable_clocks (csid->nclocks, csid->clock); -regulator_disable (csid->vdda); -return ret; + goto disable_regulator; } hw_version =readl_relaxed (csid->base +CAMSS_CSID_HW_VERSION );
@@ -357,6 +352,11 @@ static int csid_set_power(struct v4l2_subdev *sd, int on) ret =regulator_disable (csid->vdda); } + goto exit; + +disable_regulator: +regulator_disable (csid->vdda); +exit:return ret; }
drivers/media/tuners/tuner-xc2028.c +15 -15
@@ -571,7 +571,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,/* Checks if there's enough bytes to read */ if (p +sizeof (size) > endp) {tuner_err ("Firmware chunk size is wrong\n" ); -return -EINVAL ; + goto e_inval; } size =le16_to_cpu (*(__le16 *) p);
@@ -583,28 +583,23 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,if (!size) {/* Special callback command received */ rc =do_tuner_callback (fe,XC2028_TUNER_RESET ,0 ); -if (rc <0 ) { -tuner_err ("Error at RESET code %d\n" , - (*p) &0x7f ); -return -EINVAL ; - } +if (rc <0 ) + goto report_failure; +continue ; }if (size >=0xff00 ) {switch (size) {case 0xff00 : rc =do_tuner_callback (fe,XC2028_RESET_CLK ,0 ); -if (rc <0 ) { -tuner_err ("Error at RESET code %d\n" , - (*p) &0x7f ); -return -EINVAL ; - } +if (rc <0 ) + goto report_failure; +break ;default :tuner_info ("Invalid RESET code %d\n" , size &0x7f ); -return -EINVAL ; - + goto e_inval; }continue ; }
@@ -618,7 +613,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,if ((size + p > endp)) {tuner_err ("missing bytes: need %d, have %d\n" , size, (int )(endp - p)); -return -EINVAL ; + goto e_inval; } buf[0 ] = *p;
@@ -635,7 +630,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, rc =i2c_send (priv, buf, len +1 );if (rc <0 ) {tuner_err ("%d returned from send\n" , rc); -return -EINVAL ; + goto e_inval; } p += len;
@@ -650,6 +645,11 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, } }return 0 ; + +report_failure: +tuner_err ("Error at RESET code %d\n" , (*p) &0x7f ); +e_inval: +return -EINVAL ; } static int load_scode(struct dvb_frontend *fe, unsigned int type,
drivers/media/usb/cpia2/cpia2_usb.c +7 -6
@@ -848,15 +848,13 @@ static int cpia2_usb_probe(struct usb_interface *intf, ret =set_alternate (cam,USBIF_CMDONLY );if (ret <0 ) {ERR ("%s: usb_set_interface error (ret = %d)\n" , __func__, ret); -kfree (cam); -return ret; + goto free_data; }if ((ret =cpia2_init_camera (cam)) <0 ) {ERR ("%s: failed to initialize cpia2 camera (ret = %d)\n" , __func__, ret); -kfree (cam); -return ret; + goto free_data; } LOG(" CPiA Version: %d.%02d (%d.%d)\n", cam->params.version.firmware_revision_hi,
@@ -876,11 +874,14 @@ static int cpia2_usb_probe(struct usb_interface *intf, ret =cpia2_register_camera (cam);if (ret <0 ) {ERR ("%s: Failed to register cpia2 camera (ret = %d)\n" , __func__, ret); -kfree (cam); -return ret; + goto free_data; }return 0 ; + +free_data: +kfree (cam); +return ret; }/******************************************************************************
drivers/media/usb/gspca/gspca.c +9 -8
@@ -907,10 +907,8 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) ret =create_urbs (gspca_dev,alt_xfer (&intf->altsetting[alt], xfer, gspca_dev->xfer_ep)); -if (ret <0 ) { -destroy_urbs (gspca_dev); - goto out; - } +if (ret <0 ) + goto destroy_urbs; }/* clear the bulk endpoint */
@@ -920,10 +918,9 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)/* start the cam */ ret = gspca_dev->sd_desc->start (gspca_dev); -if (ret <0 ) { -destroy_urbs (gspca_dev); - goto out; - } +if (ret <0 ) + goto destroy_urbs; + gspca_dev->streaming =1 ;v4l2_ctrl_handler_setup (gspca_dev->vdev.ctrl_handler);
@@ -974,6 +971,10 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) out:gspca_input_create_urb (gspca_dev);return ret; + +destroy_urbs: +destroy_urbs (gspca_dev); + goto out; }static void gspca_set_default_mode (struct gspca_dev *gspca_dev)
drivers/media/usb/gspca/sn9c20x.c +9 -8
@@ -1788,10 +1788,8 @@ static int sd_init(struct gspca_dev *gspca_dev)for (i =0 ; i <ARRAY_SIZE (bridge_init); i++) { value = bridge_init[i][1 ];reg_w (gspca_dev, bridge_init[i][0 ], &value,1 ); -if (gspca_dev->usb_err <0 ) { -pr_err ("Device initialization failed\n" ); -return gspca_dev->usb_err; - } +if (gspca_dev->usb_err <0 ) + goto report_failure; }if (sd->flags &LED_REVERSE )
@@ -1800,10 +1798,8 @@ static int sd_init(struct gspca_dev *gspca_dev)reg_w1 (gspca_dev,0x1006 ,0x20 );reg_w (gspca_dev,0x10c0 , i2c_init,9 ); -if (gspca_dev->usb_err <0 ) { -pr_err ("Device initialization failed\n" ); -return gspca_dev->usb_err; - } +if (gspca_dev->usb_err <0 ) + goto report_failure;switch (sd->sensor) {case SENSOR_OV9650 :
@@ -1869,6 +1865,11 @@ static int sd_init(struct gspca_dev *gspca_dev)pr_err ("Unsupported sensor\n" ); gspca_dev->usb_err = -ENODEV ; } + goto exit; + +report_failure: +pr_err ("Device initialization failed\n" ); +exit:return gspca_dev->usb_err; }
drivers/media/usb/pvrusb2/pvrusb2-ioread.c +6 -4
@@ -266,8 +266,7 @@ static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp)pvr2_trace (PVR2_TRACE_DATA_FLOW ,"/*---TRACE_READ---*/ pvr2_ioread_read id=%p queue_error=%d" , cp,stat); -pvr2_ioread_stop (cp); -return 0 ; + goto stop_read; } cp->c_buf =NULL ; cp->c_data_ptr =NULL ;
@@ -286,9 +285,8 @@ static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp)pvr2_trace (PVR2_TRACE_DATA_FLOW ,"/*---TRACE_READ---*/ pvr2_ioread_read id=%p buffer_error=%d" , cp,stat); -pvr2_ioread_stop (cp);// Give up. -return 0 ; + goto stop_read; }// Start over... continue ;
@@ -298,6 +296,10 @@ static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp) pvr2_buffer_get_id(cp->c_buf)]; }return !0 ; + +stop_read: +pvr2_ioread_stop (cp); +return 0 ; }static void pvr2_ioread_filter (struct pvr2_ioread *cp)
drivers/media/usb/tm6000/tm6000-cards.c +3 -4
@@ -861,15 +861,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; }
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)
drivers/media/usb/tm6000/tm6000-video.c +7 -6
@@ -589,10 +589,8 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev) dev->isoc_ctl.transfer_buffer =kmalloc (sizeof (void *)*num_bufs,GFP_KERNEL ); -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,
@@ -604,9 +602,8 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)/* call free, as some buffers might have been allocated */ 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 */
@@ -636,6 +633,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)
drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c +6 -7
@@ -1665,8 +1665,7 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *iif (result <0 ) {dprintk ("%s: ttusb_alloc_iso_urbs - failed\n" , __func__);mutex_unlock (&ttusb->semi2c); -kfree (ttusb); -return result; + goto err_free_usb; }if (ttusb_init_controller (ttusb))
@@ -1677,11 +1676,9 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i result =dvb_register_adapter (&ttusb->adapter,"Technotrend/Hauppauge Nova-USB" ,THIS_MODULE , &udev->dev, adapter_nr); -if (result <0 ) { -ttusb_free_iso_urbs (ttusb); -kfree (ttusb); -return result; - } +if (result <0 ) + goto err_free_iso_urbs; + ttusb->adapter.priv = ttusb;/* i2c */
@@ -1752,7 +1749,9 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *ii2c_del_adapter (&ttusb->i2c_adap); err_unregister_adapter:dvb_unregister_adapter (&ttusb->adapter); +err_free_iso_urbs:ttusb_free_iso_urbs (ttusb); +err_free_usb:kfree (ttusb);return result; }
drivers/media/usb/ttusb-dec/ttusb_dec.c +15 -28
68 lines not on this page · raw message
drivers/media/usb/uvc/uvc_v4l2.c +7 -6
@@ -994,10 +994,8 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh,struct v4l2_queryctrl qc = { .id = ctrl->id }; ret =uvc_query_v4l2_ctrl (chain, &qc); -if (ret <0 ) { - ctrls->error_idx = i; -return ret; - } +if (ret <0 ) + goto set_index; ctrl->value = qc.default_value; }
@@ -1013,14 +1011,17 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, ret =uvc_ctrl_get (chain, ctrl);if (ret <0 ) {uvc_ctrl_rollback (handle); - ctrls->error_idx = i; -return ret; + goto set_index; } } ctrls->error_idx =0 ;return uvc_ctrl_rollback (handle); + +set_index: + ctrls->error_idx = i; +return ret; } static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle,
Signature · 6 lines
2.16.1 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Laurent Pinchart
maintainerHello Markus,
Quoted 38 lines · On Monday, 19 February 2018 20:11:56 EET SF Markus Elfring wrote:
From: Markus Elfring <[email protected]>
Date: Mon, 19 Feb 2018 18:50:40 +0100Adjust jump targets so that a bit of exception handling can be better reused at the end of these functions.
This issue was partly detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>---
v2:
Hans Verkuil insisted on patch squashing. Thus several changes were recombined based on source files from Linux next-20180216.The implementation of the function "
tda8261_set_params" was improved after a notification by Christoph Böhmwalder on 2017-09-26.drivers/media/dvb-core/dmxdev.c | 16 ++++---- drivers/media/dvb-frontends/tda1004x.c | 20 ++++++---- drivers/media/dvb-frontends/tda8261.c | 19 ++++++---- drivers/media/pci/bt8xx/dst.c | 19 ++++++---- drivers/media/pci/bt8xx/dst_ca.c | 30 +++++++-------- drivers/media/pci/cx88/cx88-input.c | 17 +++++---- drivers/media/platform/omap3isp/ispvideo.c | 29 +++++++-------- .../media/platform/qcom/camss-8x16/camss-csid.c | 20 +++++----- drivers/media/tuners/tuner-xc2028.c | 30 +++++++-------- drivers/media/usb/cpia2/cpia2_usb.c | 13 ++++--- drivers/media/usb/gspca/gspca.c | 17 +++++---- drivers/media/usb/gspca/sn9c20x.c | 17 +++++---- drivers/media/usb/pvrusb2/pvrusb2-ioread.c | 10 +++-- drivers/media/usb/tm6000/tm6000-cards.c | 7 ++-- drivers/media/usb/tm6000/tm6000-dvb.c | 11 ++++-- drivers/media/usb/tm6000/tm6000-video.c | 13 ++++--- drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c | 13 +++---- drivers/media/usb/ttusb-dec/ttusb_dec.c | 43 +++++++------------ drivers/media/usb/uvc/uvc_v4l2.c | 13 ++++--- 19 files changed, 180 insertions(+), 177 deletions(-)
[snip]
Quoted 37 lines
(quoted diff) +0
-0
b/drivers/media/platform/omap3isp/ispvideo.cindexa751c89a3ea8..2ddcac736402100644drivers/media/platform/omap3isp/ispvideo.c +5
-9@@ -1315,14 +1315,12 @@ static int isp_video_open(struct file *file)/* If this is the first user, initialise the pipeline. */ if (omap3isp_get (video->isp) ==NULL ) { ret = -EBUSY ; - goto done; + goto delete_fh; } ret =v4l2_pipeline_pm_use (&video->video.entity,1 ); -if (ret <0 ) { -omap3isp_put (video->isp); - goto done; - } +if (ret <0 ) + goto put_isp; queue = &handle->queue; queue->type = video->type;@@ -1335,10 +1333,8 @@ static int isp_video_open(struct file *file) queue->dev = video->isp->dev; ret =vb2_queue_init (&handle->queue); -if (ret <0 ) { -omap3isp_put (video->isp); - goto done; - } +if (ret <0 ) + goto put_isp;memset (&handle->format,0 ,sizeof (handle->format)); handle->format.type = video->type;
drivers/media/platform/omap3isp/ispvideo.c static int isp_video_open(struct file *file) · line 1345
Quoted 4 lines
drivers/media/platform/omap3isp/ispvideo.c +1
-0@@ -1346,14 +1342,15 @@ static int isp_video_open(struct file *file) handle->video = video; file->private_data = &handle->vfh; + goto exit;
No need for a goto here, you can just return 0.
Quoted 4 lines
drivers/media/platform/omap3isp/ispvideo.c +0
-3-done: -if (ret <0 ) { -v4l2_fh_del (&handle->vfh);
drivers/media/platform/omap3isp/ispvideo.c static int isp_video_open(struct file *file) · line 1352
Quoted 10 lines
drivers/media/platform/omap3isp/ispvideo.c +6
-4-v4l2_fh_exit (&handle->vfh); -kfree (handle); - } - +put_isp: +omap3isp_put (video->isp); +delete_fh: +v4l2_fh_del (&handle->vfh); +v4l2_fh_exit (&handle->vfh); +kfree (handle);
Please prefix the error labels with error_.
drivers/media/platform/omap3isp/ispvideo.c static int isp_video_open(struct file *file) · line 1356
Quoted 4 lines
drivers/media/platform/omap3isp/ispvideo.c +1
-0+exit:return ret; }
Otherwise the changes to omap3isp look OK to me.
[snip]
Quoted 25 lines
(quoted diff) +0
-0
b/drivers/media/usb/uvc/uvc_v4l2.cindexa13ad4e178be..f64c851adea2100644drivers/media/usb/uvc/uvc_v4l2.c +3
-6@@ -994,10 +994,8 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, struct v4l2_queryctrl qc = { .id = ctrl->id }; ret =uvc_query_v4l2_ctrl (chain, &qc); -if (ret <0 ) { - ctrls->error_idx = i; -return ret; - } +if (ret <0 ) + goto set_index; ctrl->value = qc.default_value; }@@ -1013,14 +1011,17 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file,void *fh, ret =uvc_ctrl_get (chain, ctrl);if (ret <0 ) {uvc_ctrl_rollback (handle); - ctrls->error_idx = i; -return ret; + goto set_index; }
drivers/media/usb/uvc/uvc_v4l2.c static int uvc_ioctl_g_ext_ctrls(struct file *file, · line 1025
Quoted 10 lines
drivers/media/usb/uvc/uvc_v4l2.c +4
-0} ctrls->error_idx =0 ;return uvc_ctrl_rollback (handle); + +set_index: + ctrls->error_idx = i; +return ret; }
For uvcvideo I find this to hinder readability without adding much added value. Please drop the uvcvideo change from this patch.
Quoted 2 lines
drivers/media/usb/uvc/uvc_v4l2.c +0
-0static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle,
Signature · 3 lines
Regards, Laurent Pinchart
Hi Markus,
Thank you for the patch.
Quoted 41 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 19 Feb 2018 18:50:40 +0100Adjust jump targets so that a bit of exception handling can be better reused at the end of these functions.
This issue was partly detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>---
v2:
Hans Verkuil insisted on patch squashing. Thus several changes were recombined based on source files from Linux next-20180216.The implementation of the function "
tda8261_set_params" was improved after a notification by Christoph Böhmwalder on 2017-09-26.drivers/media/dvb-core/dmxdev.c | 16 ++++---- drivers/media/dvb-frontends/tda1004x.c | 20 ++++++---- drivers/media/dvb-frontends/tda8261.c | 19 ++++++---- drivers/media/pci/bt8xx/dst.c | 19 ++++++---- drivers/media/pci/bt8xx/dst_ca.c | 30 +++++++-------- drivers/media/pci/cx88/cx88-input.c | 17 +++++---- drivers/media/platform/omap3isp/ispvideo.c | 29 +++++++-------- .../media/platform/qcom/camss-8x16/camss-csid.c | 20 +++++----- drivers/media/tuners/tuner-xc2028.c | 30 +++++++-------- drivers/media/usb/cpia2/cpia2_usb.c | 13 ++++--- drivers/media/usb/gspca/gspca.c | 17 +++++---- drivers/media/usb/gspca/sn9c20x.c | 17 +++++---- drivers/media/usb/pvrusb2/pvrusb2-ioread.c | 10 +++-- drivers/media/usb/tm6000/tm6000-cards.c | 7 ++-- drivers/media/usb/tm6000/tm6000-dvb.c | 11 ++++-- drivers/media/usb/tm6000/tm6000-video.c | 13 ++++--- drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c | 13 +++---- drivers/media/usb/ttusb-dec/ttusb_dec.c | 43 ++++++++-------------- drivers/media/usb/uvc/uvc_v4l2.c | 13 ++++--- 19 files changed, 180 insertions(+), 177 deletions(-)drivers/media/dvb-core/dmxdev.c +0
-0
<snip>
Quoted 36 lines
drivers/media/platform/qcom/camss-8x16/camss-csid.c +5
-10@@ -328,16 +328,12 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)return ret; ret =csid_set_clock_rates (csid); -if (ret <0 ) { -regulator_disable (csid->vdda); -return ret; - } +if (ret <0 ) + goto disable_regulator; ret =camss_enable_clocks (csid->nclocks, csid->clock, dev); -if (ret <0 ) { -regulator_disable (csid->vdda); -return ret; - } +if (ret <0 ) + goto disable_regulator;enable_irq (csid->irq);@@ -345,8 +341,7 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)if (ret <0 ) {disable_irq (csid->irq);camss_disable_clocks (csid->nclocks, csid->clock); -regulator_disable (csid->vdda); -return ret; + goto disable_regulator; } hw_version =readl_relaxed (csid->base +CAMSS_CSID_HW_VERSION );
drivers/media/platform/qcom/camss-8x16/camss-csid.c static int csid_set_power(struct v4l2_subdev *sd, int on) · line 355
Quoted 4 lines
drivers/media/platform/qcom/camss-8x16/camss-csid.c +1
-0@@ -357,6 +352,11 @@ static int csid_set_power(struct v4l2_subdev *sd, int on) ret =regulator_disable (csid->vdda); } + goto exit;
I think it will be cleaner if you remove the exit label and return here instead.
Quoted 6 lines
drivers/media/platform/qcom/camss-8x16/camss-csid.c +4
-0+ +disable_regulator: +regulator_disable (csid->vdda); +exit:return ret; }
Signature · 6 lines
Best regards, Todor Tomov -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines
drivers/media/platform/omap3isp/ispvideo.c static int isp_video_open(struct file *file) · line 1352
Quoted 6 lines
drivers/media/platform/omap3isp/ispvideo.c +6
-0+put_isp: +omap3isp_put (video->isp); +delete_fh: +v4l2_fh_del (&handle->vfh); +v4l2_fh_exit (&handle->vfh); +kfree (handle);Please prefix the error labels with
error_.
How often do you really need such an extra prefix?
Quoted 26 lines
Quoted 26 lines
+++
b/drivers/media/usb/uvc/uvc_v4l2.cdrivers/media/usb/uvc/uvc_v4l2.c +3
-6@@ -994,10 +994,8 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, struct v4l2_queryctrl qc = { .id = ctrl->id }; ret =uvc_query_v4l2_ctrl (chain, &qc); -if (ret <0 ) { - ctrls->error_idx = i; -return ret; - } +if (ret <0 ) + goto set_index; ctrl->value = qc.default_value; }@@ -1013,14 +1011,17 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file,void *fh, ret =uvc_ctrl_get (chain, ctrl);if (ret <0 ) {uvc_ctrl_rollback (handle); - ctrls->error_idx = i; -return ret; + goto set_index; } } ctrls->error_idx =0 ;
Quoted 8 lines
drivers/media/usb/uvc/uvc_v4l2.c static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, · line 1025
Quoted 6 lines
drivers/media/usb/uvc/uvc_v4l2.c +4
-0return uvc_ctrl_rollback (handle); + +set_index: + ctrls->error_idx = i; +return ret; }For uvcvideo I find this to hinder readability
I got an other development view.
Quoted 1 line
without adding much added value.
There can be a small effect for such a function implementation.
Quoted 1 line
Please drop the uvcvideo change from this patch.
Would it be nice if this source code adjustment could be integrated also?
Regards,
Markus
Hello,
Quoted 59 lines · On Wednesday, 28 February 2018 10:45:21 EET SF Markus Elfring wrote:
Quoted 8 lines
drivers/media/platform/omap3isp/ispvideo.c static int isp_video_open(struct file *file) · line 1352
Quoted 6 lines
drivers/media/platform/omap3isp/ispvideo.c +6
-0+put_isp: +omap3isp_put (video->isp); +delete_fh: +v4l2_fh_del (&handle->vfh); +v4l2_fh_exit (&handle->vfh); +kfree (handle);Please prefix the error labels with
error_.How often do you really need such an extra prefix?
Quoted 37 lines
Quoted 37 lines
+++
b/drivers/media/usb/uvc/uvc_v4l2.cdrivers/media/usb/uvc/uvc_v4l2.c +2
-4@@ -994,10 +994,8 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, struct v4l2_queryctrl qc = { .id = ctrl->id }; ret =uvc_query_v4l2_ctrl (chain, &qc); -if (ret <0 ) { - ctrls->error_idx = i; -return ret; - } +if (ret <0 ) + goto set_index; ctrl->value = qc.default_value;drivers/media/usb/uvc/uvc_v4l2.c +1
-2}@@ -1013,14 +1011,17 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, ret =uvc_ctrl_get (chain, ctrl);if (ret <0 ) {uvc_ctrl_rollback (handle); - ctrls->error_idx = i; -return ret; + goto set_index; } } ctrls->error_idx =0 ;return uvc_ctrl_rollback (handle);Quoted 8 lines
drivers/media/usb/uvc/uvc_v4l2.c static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh,
Quoted 6 lines
drivers/media/usb/uvc/uvc_v4l2.c +4
-0+ +set_index: + ctrls->error_idx = i; +return ret; }For uvcvideo I find this to hinder readability
I got an other development view.
Quoted 7 lines
Quoted 1 line
without adding much added value.
There can be a small effect for such a function implementation.
Quoted 1 line
Please drop the uvcvideo change from this patch.
Would it be nice if this source code adjustment could be integrated also?
Just for the record, and to avoid merging this patch by mistake,
at least until the requested changes are implemented.
Signature · 3 lines
Regards, Laurent Pinchart
I got the following notification.
- http://patchwork.linuxtv.org/patch/47270/
- for: Linux Media kernel patches
was: New
now: Rejected
Would you like to clarify still any other variant for this change proposal?
Regards,
Markus
PATCH v3 1/1 Use common error handling code in 19 functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Fri, 9 Mar 2018 21:00:12 +0100
Adjust jump targets so that a bit of exception handling can be better reused at the end of these functions.
This issue was partly detected by using the Coccinelle software.
---
v3:
Laurent Pinchart and Todor Tomov requested a few adjustments. Updates were rebased on source files from Linux next-20180308.
v2:
Hans Verkuil insisted on patch squashing. Thus several changes were recombined based on source files from Linux next-20180216.
The implementation of the function "tda8261_set_params" was improved after a notification by Christoph Böhmwalder on 2017-09-26.
drivers/media/dvb-core/dmxdev.c | 16 ++++---- drivers/media/dvb-frontends/tda1004x.c | 20 ++++++---- drivers/media/dvb-frontends/tda8261.c | 19 ++++++---- drivers/media/pci/bt8xx/dst.c | 19 ++++++---- drivers/media/pci/bt8xx/dst_ca.c | 30 +++++++-------- drivers/media/pci/cx88/cx88-input.c | 17 +++++---- drivers/media/platform/omap3isp/ispvideo.c | 28 ++++++-------- .../media/platform/qcom/camss-8x16/camss-csid.c | 19 +++++----- drivers/media/tuners/tuner-xc2028.c | 30 +++++++-------- drivers/media/usb/cpia2/cpia2_usb.c | 13 ++++--- drivers/media/usb/gspca/gspca.c | 17 +++++---- drivers/media/usb/gspca/sn9c20x.c | 17 +++++---- drivers/media/usb/pvrusb2/pvrusb2-ioread.c | 10 +++-- drivers/media/usb/tm6000/tm6000-cards.c | 7 ++-- drivers/media/usb/tm6000/tm6000-dvb.c | 11 ++++-- drivers/media/usb/tm6000/tm6000-video.c | 13 ++++--- drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c | 13 +++---- drivers/media/usb/ttusb-dec/ttusb_dec.c | 43 ++++++++-------------- 18 files changed, 171 insertions(+), 171 deletions(-)
drivers/media/dvb-core/dmxdev.c +8 -8
@@ -656,18 +656,18 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev, tsfeed->priv = filter; ret = tsfeed->set (tsfeed, feed->pid, ts_type, ts_pes, timeout); -if (ret <0 ) { - dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); -return ret; - } +if (ret <0 ) + goto release_feed; ret = tsfeed->start_filtering (tsfeed); -if (ret <0 ) { - dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); -return ret; - } +if (ret <0 ) + goto release_feed;return 0 ; + +release_feed: + dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); +return ret; }static int dvb_dmxdev_filter_start (struct dmxdev_filter *filter)
drivers/media/dvb-frontends/tda1004x.c +12 -8
@@ -1299,20 +1299,22 @@ struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config, id =tda1004x_read_byte (state,TDA1004X_CHIPID );if (id <0 ) {printk (KERN_ERR "tda10045: chip is not answering. Giving up.\n" ); -kfree (state); -return NULL ; + goto free_state; }if (id !=0x25 ) {printk (KERN_ERR "Invalid tda1004x ID = 0x%02x. Can't proceed\n" , id); -kfree (state); -return NULL ; + goto free_state; }/* create dvb_frontend */ memcpy (&state->frontend.ops, &tda10045_ops,sizeof (struct dvb_frontend_ops )); state->frontend.demodulator_priv = state;return &state->frontend; + +free_state: +kfree (state); +return NULL ; }static const struct dvb_frontend_ops tda10046_ops = {
@@ -1369,19 +1371,21 @@ struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config, id =tda1004x_read_byte (state,TDA1004X_CHIPID );if (id <0 ) {printk (KERN_ERR "tda10046: chip is not answering. Giving up.\n" ); -kfree (state); -return NULL ; + goto free_state; }if (id !=0x46 ) {printk (KERN_ERR "Invalid tda1004x ID = 0x%02x. Can't proceed\n" , id); -kfree (state); -return NULL ; + goto free_state; }/* create dvb_frontend */ memcpy (&state->frontend.ops, &tda10046_ops,sizeof (struct dvb_frontend_ops )); state->frontend.demodulator_priv = state;return &state->frontend; + +free_state: +kfree (state); +return NULL ; }module_param (debug, int,0644 );
drivers/media/dvb-frontends/tda8261.c +11 -8
@@ -129,18 +129,17 @@ static int tda8261_set_params(struct dvb_frontend *fe)/* Set params */ err =tda8261_write (state, buf); -if (err <0 ) { -pr_err ("%s: I/O Error\n" , __func__); -return err; - } +if (err <0 ) + goto report_failure; +/* sleep for some time */ pr_debug ("%s: Waiting to Phase LOCK\n" , __func__);msleep (20 );/* check status */ -if ((err =tda8261_get_status (fe, &status)) <0 ) { -pr_err ("%s: I/O Error\n" , __func__); -return err; - } + err =tda8261_get_status (fe, &status); +if (err <0 ) + goto report_failure; +if (status =1 ) {pr_debug ("%s: Tuner Phase locked: status=%d\n" , __func__, status);
@@ -150,6 +149,10 @@ static int tda8261_set_params(struct dvb_frontend *fe) }return 0 ; + +report_failure: +pr_err ("%s: I/O Error\n" , __func__); +return err; }static void tda8261_release (struct dvb_frontend *fe)
drivers/media/pci/bt8xx/dst.c +11 -8
@@ -134,17 +134,20 @@ EXPORT_SYMBOL(rdc_reset_state);static int rdc_8820_reset (struct dst_state *state) {dprintk (3 ,"Resetting DST\n" ); -if (dst_gpio_outb (state,RDC_8820_RESET ,RDC_8820_RESET ,0 ,NO_DELAY ) <0 ) { -pr_err ("dst_gpio_outb ERROR !\n" ); -return -1 ; - } +if (dst_gpio_outb (state,RDC_8820_RESET ,RDC_8820_RESET ,0 ,NO_DELAY ) + <0 ) + goto report_failure; +udelay (1000 ); -if (dst_gpio_outb (state,RDC_8820_RESET ,RDC_8820_RESET ,RDC_8820_RESET ,DELAY ) <0 ) { -pr_err ("dst_gpio_outb ERROR !\n" ); -return -1 ; - } +if (dst_gpio_outb (state,RDC_8820_RESET ,RDC_8820_RESET , +RDC_8820_RESET ,DELAY ) <0 ) + goto report_failure;return 0 ; + +report_failure: +pr_err ("dst_gpio_outb ERROR !\n" ); +return -1 ; }static int dst_pio_enable (struct dst_state *state)
drivers/media/pci/bt8xx/dst_ca.c +15 -15
@@ -83,33 +83,33 @@ static int dst_ci_command(struct dst_state* state, u8 * data, u8 *ca_string, u8if (write_dst (state, data, len)) {dprintk (verbose,DST_CA_INFO ,1 ," Write not successful, trying to recover" ); -dst_error_recovery (state); - goto error; + goto error_recovery; }if ((dst_pio_disable (state)) <0 ) {dprintk (verbose,DST_CA_ERROR ,1 ," DST PIO disable failed." ); - goto error; - } -if (read_dst (state, &reply,GET_ACK ) <0 ) { -dprintk (verbose,DST_CA_INFO ,1 ," Read not successful, trying to recover" ); -dst_error_recovery (state); - goto error; + goto unlock; } +if (read_dst (state, &reply,GET_ACK ) <0 ) + goto report_read_failure; +if (read) {if (!dst_wait_dst_ready (state,LONG_DELAY )) {dprintk (verbose,DST_CA_NOTICE ,1 ," 8820 not ready" ); - goto error; - } -if (read_dst (state, ca_string,128 ) <0 ) {/* Try to make this dynamic */ -dprintk (verbose,DST_CA_INFO ,1 ," Read not successful, trying to recover" ); -dst_error_recovery (state); - goto error; + goto unlock; } +/* Try to make this dynamic */ +if (read_dst (state, ca_string,128 ) <0 ) + goto report_read_failure; }mutex_unlock (&state->dst_mutex);return 0 ; -error: +report_read_failure: +dprintk (verbose,DST_CA_INFO ,1 , +" Read not successful, trying to recover" ); +error_recovery: +dst_error_recovery (state); +unlock:mutex_unlock (&state->dst_mutex);return -EIO ; }
drivers/media/pci/cx88/cx88-input.c +9 -8
@@ -566,20 +566,17 @@ static int get_key_pvr2000(struct IR_i2c *ir, enum rc_proto *protocol,/* poll IR chip */ flags =i2c_smbus_read_byte_data (ir->c,0x10 ); -if (flags <0 ) { -dprintk ("read error\n" ); -return 0 ; - } +if (flags <0 ) + goto report_read_failure; +/* key pressed ? */ if (0 = (flags & 0x80))return 0 ;/* read actual key code */ code =i2c_smbus_read_byte_data (ir->c,0x00 ); -if (code <0 ) { -dprintk ("read error\n" ); -return 0 ; - } +if (code <0 ) + goto report_read_failure;dprintk ("IR Key/Flags: (0x%02x/0x%02x)\n" , code &0xff , flags &0xff );
@@ -588,6 +585,10 @@ static int get_key_pvr2000(struct IR_i2c *ir, enum rc_proto *protocol, *scancode = code &0xff ; *toggle =0 ;return 1 ; + +report_read_failure: +dprintk ("read error\n" ); +return 0 ; }void cx88_i2c_init_ir (struct cx88_core *core)
drivers/media/platform/omap3isp/ispvideo.c +12 -16
@@ -1315,14 +1315,12 @@ static int isp_video_open(struct file *file)/* If this is the first user, initialise the pipeline. */ if (omap3isp_get (video->isp) =NULL ) { ret = -EBUSY ; - goto done; + goto error_delete_fh; } ret =v4l2_pipeline_pm_use (&video->video.entity,1 ); -if (ret <0 ) { -omap3isp_put (video->isp); - goto done; - } +if (ret <0 ) + goto error_put_isp; queue = &handle->queue; queue->type = video->type;
@@ -1335,10 +1333,8 @@ static int isp_video_open(struct file *file) queue->dev = video->isp->dev; ret =vb2_queue_init (&handle->queue); -if (ret <0 ) { -omap3isp_put (video->isp); - goto done; - } +if (ret <0 ) + goto error_put_isp;memset (&handle->format,0 ,sizeof (handle->format)); handle->format.type = video->type;
@@ -1346,14 +1342,14 @@ static int isp_video_open(struct file *file) handle->video = video; file->private_data = &handle->vfh; +return 0 ; -done: -if (ret <0 ) { -v4l2_fh_del (&handle->vfh); -v4l2_fh_exit (&handle->vfh); -kfree (handle); - } - +error_put_isp: +omap3isp_put (video->isp); +error_delete_fh: +v4l2_fh_del (&handle->vfh); +v4l2_fh_exit (&handle->vfh); +kfree (handle);return ret; }
drivers/media/platform/qcom/camss-8x16/camss-csid.c +9 -10
@@ -328,16 +328,12 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)return ret; ret =csid_set_clock_rates (csid); -if (ret <0 ) { -regulator_disable (csid->vdda); -return ret; - } +if (ret <0 ) + goto disable_regulator; ret =camss_enable_clocks (csid->nclocks, csid->clock, dev); -if (ret <0 ) { -regulator_disable (csid->vdda); -return ret; - } +if (ret <0 ) + goto disable_regulator;enable_irq (csid->irq);
@@ -345,8 +341,7 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)if (ret <0 ) {disable_irq (csid->irq);camss_disable_clocks (csid->nclocks, csid->clock); -regulator_disable (csid->vdda); -return ret; + goto disable_regulator; } hw_version =readl_relaxed (csid->base +CAMSS_CSID_HW_VERSION );
@@ -358,6 +353,10 @@ static int csid_set_power(struct v4l2_subdev *sd, int on) }return ret; + +disable_regulator: +regulator_disable (csid->vdda); +return ret; }/*
drivers/media/tuners/tuner-xc2028.c +15 -15
@@ -571,7 +571,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,/* Checks if there's enough bytes to read */ if (p +sizeof (size) > endp) {tuner_err ("Firmware chunk size is wrong\n" ); -return -EINVAL ; + goto e_inval; } size =le16_to_cpu (*(__le16 *) p);
@@ -583,28 +583,23 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,if (!size) {/* Special callback command received */ rc =do_tuner_callback (fe,XC2028_TUNER_RESET ,0 ); -if (rc <0 ) { -tuner_err ("Error at RESET code %d\n" , - (*p) &0x7f ); -return -EINVAL ; - } +if (rc <0 ) + goto report_failure; +continue ; }if (size >=0xff00 ) {switch (size) {case 0xff00 : rc =do_tuner_callback (fe,XC2028_RESET_CLK ,0 ); -if (rc <0 ) { -tuner_err ("Error at RESET code %d\n" , - (*p) &0x7f ); -return -EINVAL ; - } +if (rc <0 ) + goto report_failure; +break ;default :tuner_info ("Invalid RESET code %d\n" , size &0x7f ); -return -EINVAL ; - + goto e_inval; }continue ; }
@@ -618,7 +613,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,if ((size + p > endp)) {tuner_err ("missing bytes: need %d, have %d\n" , size, (int )(endp - p)); -return -EINVAL ; + goto e_inval; } buf[0 ] = *p;
@@ -635,7 +630,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, rc =i2c_send (priv, buf, len +1 );if (rc <0 ) {tuner_err ("%d returned from send\n" , rc); -return -EINVAL ; + goto e_inval; } p += len;
@@ -650,6 +645,11 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type, } }return 0 ; + +report_failure: +tuner_err ("Error at RESET code %d\n" , (*p) &0x7f ); +e_inval: +return -EINVAL ; } static int load_scode(struct dvb_frontend *fe, unsigned int type,
drivers/media/usb/cpia2/cpia2_usb.c +7 -6
@@ -848,15 +848,13 @@ static int cpia2_usb_probe(struct usb_interface *intf, ret =set_alternate (cam,USBIF_CMDONLY );if (ret <0 ) {ERR ("%s: usb_set_interface error (ret = %d)\n" , __func__, ret); -kfree (cam); -return ret; + goto free_data; }if ((ret =cpia2_init_camera (cam)) <0 ) {ERR ("%s: failed to initialize cpia2 camera (ret = %d)\n" , __func__, ret); -kfree (cam); -return ret; + goto free_data; } LOG(" CPiA Version: %d.%02d (%d.%d)\n", cam->params.version.firmware_revision_hi,
@@ -876,11 +874,14 @@ static int cpia2_usb_probe(struct usb_interface *intf, ret =cpia2_register_camera (cam);if (ret <0 ) {ERR ("%s: Failed to register cpia2 camera (ret = %d)\n" , __func__, ret); -kfree (cam); -return ret; + goto free_data; }return 0 ; + +free_data: +kfree (cam); +return ret; }/******************************************************************************
drivers/media/usb/gspca/gspca.c +9 -8
@@ -907,10 +907,8 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) ret =create_urbs (gspca_dev,alt_xfer (&intf->altsetting[alt], xfer, gspca_dev->xfer_ep)); -if (ret <0 ) { -destroy_urbs (gspca_dev); - goto out; - } +if (ret <0 ) + goto destroy_urbs; }/* clear the bulk endpoint */
@@ -920,10 +918,9 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)/* start the cam */ ret = gspca_dev->sd_desc->start (gspca_dev); -if (ret <0 ) { -destroy_urbs (gspca_dev); - goto out; - } +if (ret <0 ) + goto destroy_urbs; + gspca_dev->streaming =1 ;v4l2_ctrl_handler_setup (gspca_dev->vdev.ctrl_handler);
@@ -974,6 +971,10 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) out:gspca_input_create_urb (gspca_dev);return ret; + +destroy_urbs: +destroy_urbs (gspca_dev); + goto out; }static void gspca_set_default_mode (struct gspca_dev *gspca_dev)
drivers/media/usb/gspca/sn9c20x.c +9 -8
@@ -1788,10 +1788,8 @@ static int sd_init(struct gspca_dev *gspca_dev)for (i =0 ; i <ARRAY_SIZE (bridge_init); i++) { value = bridge_init[i][1 ];reg_w (gspca_dev, bridge_init[i][0 ], &value,1 ); -if (gspca_dev->usb_err <0 ) { -pr_err ("Device initialization failed\n" ); -return gspca_dev->usb_err; - } +if (gspca_dev->usb_err <0 ) + goto report_failure; }if (sd->flags &LED_REVERSE )
@@ -1800,10 +1798,8 @@ static int sd_init(struct gspca_dev *gspca_dev)reg_w1 (gspca_dev,0x1006 ,0x20 );reg_w (gspca_dev,0x10c0 , i2c_init,9 ); -if (gspca_dev->usb_err <0 ) { -pr_err ("Device initialization failed\n" ); -return gspca_dev->usb_err; - } +if (gspca_dev->usb_err <0 ) + goto report_failure;switch (sd->sensor) {case SENSOR_OV9650 :
@@ -1869,6 +1865,11 @@ static int sd_init(struct gspca_dev *gspca_dev)pr_err ("Unsupported sensor\n" ); gspca_dev->usb_err = -ENODEV ; } + goto exit; + +report_failure: +pr_err ("Device initialization failed\n" ); +exit:return gspca_dev->usb_err; }
drivers/media/usb/pvrusb2/pvrusb2-ioread.c +6 -4
@@ -266,8 +266,7 @@ static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp)pvr2_trace (PVR2_TRACE_DATA_FLOW ,"/*---TRACE_READ---*/ pvr2_ioread_read id=%p queue_error=%d" , cp,stat); -pvr2_ioread_stop (cp); -return 0 ; + goto stop_read; } cp->c_buf =NULL ; cp->c_data_ptr =NULL ;
@@ -286,9 +285,8 @@ static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp)pvr2_trace (PVR2_TRACE_DATA_FLOW ,"/*---TRACE_READ---*/ pvr2_ioread_read id=%p buffer_error=%d" , cp,stat); -pvr2_ioread_stop (cp);// Give up. -return 0 ; + goto stop_read; }// Start over... continue ;
@@ -298,6 +296,10 @@ static int pvr2_ioread_get_buffer(struct pvr2_ioread *cp) pvr2_buffer_get_id(cp->c_buf)]; }return !0 ; + +stop_read: +pvr2_ioread_stop (cp); +return 0 ; }static void pvr2_ioread_filter (struct pvr2_ioread *cp)
drivers/media/usb/tm6000/tm6000-cards.c +3 -4
@@ -861,15 +861,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; }
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)
drivers/media/usb/tm6000/tm6000-video.c +7 -6
@@ -589,10 +589,8 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev) dev->isoc_ctl.transfer_buffer =kmalloc (sizeof (void *)*num_bufs,GFP_KERNEL ); -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,
@@ -604,9 +602,8 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)/* call free, as some buffers might have been allocated */ 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 */
@@ -636,6 +633,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)
drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c +6 -7
@@ -1665,8 +1665,7 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *iif (result <0 ) {dprintk ("%s: ttusb_alloc_iso_urbs - failed\n" , __func__);mutex_unlock (&ttusb->semi2c); -kfree (ttusb); -return result; + goto err_free_usb; }if (ttusb_init_controller (ttusb))
@@ -1677,11 +1676,9 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i result =dvb_register_adapter (&ttusb->adapter,"Technotrend/Hauppauge Nova-USB" ,THIS_MODULE , &udev->dev, adapter_nr); -if (result <0 ) { -ttusb_free_iso_urbs (ttusb); -kfree (ttusb); -return result; - } +if (result <0 ) + goto err_free_iso_urbs; + ttusb->adapter.priv = ttusb;/* i2c */
@@ -1752,7 +1749,9 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *ii2c_del_adapter (&ttusb->i2c_adap); err_unregister_adapter:dvb_unregister_adapter (&ttusb->adapter); +err_free_iso_urbs:ttusb_free_iso_urbs (ttusb); +err_free_usb:kfree (ttusb);return result; }
drivers/media/usb/ttusb-dec/ttusb_dec.c +15 -28
68 lines not on this page · raw message
Signature · 6 lines
2.16.2 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3] [media] Use common error handling code in 19 functions
Hi Markus,
Thank you for the patch.
Quoted 42 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 9 Mar 2018 21:00:12 +0100Adjust jump targets so that a bit of exception handling can be better reused at the end of these functions.
This issue was partly detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>---
v3:
Laurent Pinchart and Todor Tomov requested a few adjustments. Updates were rebased on source files from Linux next-20180308.v2:
Hans Verkuil insisted on patch squashing. Thus several changes were recombined based on source files from Linux next-20180216.The implementation of the function "
tda8261_set_params" was improved after a notification by Christoph Böhmwalder on 2017-09-26.drivers/media/dvb-core/dmxdev.c | 16 ++++---- drivers/media/dvb-frontends/tda1004x.c | 20 ++++++---- drivers/media/dvb-frontends/tda8261.c | 19 ++++++---- drivers/media/pci/bt8xx/dst.c | 19 ++++++---- drivers/media/pci/bt8xx/dst_ca.c | 30 +++++++-------- drivers/media/pci/cx88/cx88-input.c | 17 +++++---- drivers/media/platform/omap3isp/ispvideo.c | 28 ++++++-------- .../media/platform/qcom/camss-8x16/camss-csid.c | 19 +++++----- drivers/media/tuners/tuner-xc2028.c | 30 +++++++-------- drivers/media/usb/cpia2/cpia2_usb.c | 13 ++++--- drivers/media/usb/gspca/gspca.c | 17 +++++---- drivers/media/usb/gspca/sn9c20x.c | 17 +++++---- drivers/media/usb/pvrusb2/pvrusb2-ioread.c | 10 +++-- drivers/media/usb/tm6000/tm6000-cards.c | 7 ++-- drivers/media/usb/tm6000/tm6000-dvb.c | 11 ++++-- drivers/media/usb/tm6000/tm6000-video.c | 13 ++++--- drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c | 13 +++---- drivers/media/usb/ttusb-dec/ttusb_dec.c | 43 ++++++++-------------- 18 files changed, 171 insertions(+), 171 deletions(-)
<snip>
Quoted 36 lines
drivers/media/platform/qcom/camss-8x16/camss-csid.c +5
-10@@ -328,16 +328,12 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)return ret; ret =csid_set_clock_rates (csid); -if (ret <0 ) { -regulator_disable (csid->vdda); -return ret; - } +if (ret <0 ) + goto disable_regulator; ret =camss_enable_clocks (csid->nclocks, csid->clock, dev); -if (ret <0 ) { -regulator_disable (csid->vdda); -return ret; - } +if (ret <0 ) + goto disable_regulator;enable_irq (csid->irq);@@ -345,8 +341,7 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)if (ret <0 ) {disable_irq (csid->irq);camss_disable_clocks (csid->nclocks, csid->clock); -regulator_disable (csid->vdda); -return ret; + goto disable_regulator; } hw_version =readl_relaxed (csid->base +CAMSS_CSID_HW_VERSION );
drivers/media/platform/qcom/camss-8x16/camss-csid.c static int csid_set_power(struct v4l2_subdev *sd, int on) · line 361
Quoted 9 lines
drivers/media/platform/qcom/camss-8x16/camss-csid.c +4
-0@@ -358,6 +353,10 @@ static int csid_set_power(struct v4l2_subdev *sd, int on) }return ret; + +disable_regulator: +regulator_disable (csid->vdda); +return ret; }
For the QComm CAMSS part of the patch:
Signature · 6 lines
Best regards, Todor Tomov -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [v3] [media] Use common error handling code in 19 functions
In reply to SF Markus ElfringQuoted 2 lines
Adjust jump targets so that a bit of exception handling can be better reused at the end of these functions.
Why was this update suggestion rejected once more a moment ago?
https://patchwork.linuxtv.org/patch/47827/
lkml.kernel.org/r/<[email protected]>
https://lkml.org/lkml/2018/3/9/823
Would you like to integrate such a source code transformation after any further adjustments?
Regards,
Markus
Re: [v3] [media] Use common error handling code in 19 functions
Em Fri, 4 May 2018 18:08:59 +0200
SF Markus Elfring <[email protected]> escreveu:
Quoted 8 lines
Quoted 2 lines
Adjust jump targets so that a bit of exception handling can be better reused at the end of these functions.
Why was this update suggestion rejected once more a moment ago?
https://patchwork.linuxtv.org/patch/47827/
lkml.kernel.org/r/<[email protected]>
https://lkml.org/lkml/2018/3/9/823
Taking just the first diff there as an example:
drivers/media/dvb-core/dmxdev.c +8 -8
@@ -656,18 +656,18 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev, tsfeed->priv = filter; ret = tsfeed->set (tsfeed, feed->pid, ts_type, ts_pes, timeout); -if (ret <0 ) { - dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); -return ret; - } +if (ret <0 ) + goto release_feed; ret = tsfeed->start_filtering (tsfeed); -if (ret <0 ) { - dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); -return ret; - } +if (ret <0 ) + goto release_feed;return 0 ; + +release_feed: + dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); +return ret; }
There's *nothing* wrong with the above. It works fine, avoids goto and probably even produce the same code, as gcc will likely optimize it. It is also easier to review, as the error handling is closer to the code. On the other hand, there's nothing wrong on taking the approach you're proposing.
In the end, using goto or not on error handling like the above is a matter of personal taste - and taste changes with time and with developer. I really don't have time to keep reviewing patches that are just churning the code just due to someone's personal taste.
I'm pretty sure if I start accepting things like that, someone else would be on some future doing patches just reverting it, and I would be likely having to apply them too.
So, except if the patch is really fixing something - e.g. a broken error handling code, I'll just ignore such patches and mark as rejected without further notice/comments from now on.
Thanks,
Mauro
Re: [v3] [media] Use common error handling code in 19 functions
Quoted 17 lines
drivers/media/dvb-core/dmxdev.c +3
-8@@ -656,18 +656,18 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev, tsfeed->priv = filter; ret = tsfeed->set (tsfeed, feed->pid, ts_type, ts_pes, timeout); -if (ret <0 ) { - dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); -return ret; - } +if (ret <0 ) + goto release_feed; ret = tsfeed->start_filtering (tsfeed); -if (ret <0 ) { - dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); -return ret; - } +if (ret <0 )
drivers/media/dvb-core/dmxdev.c static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev, · line 673
Quoted 10 lines
drivers/media/dvb-core/dmxdev.c +5
-0+ goto release_feed;return 0 ; + +release_feed: + dmxdev->demux->release_ts_feed (dmxdev->demux, tsfeed); +return ret; } There's *nothing* wrong with the above. It works fine,
I can agree to this view in principle according to the required control flow.
Quoted 1 line
avoids goto
How does this wording fit to information from the section
“7) Centralized exiting of functions” in the document “coding-style.rst”?
Quoted 1 line
and probably even produce the same code, as gcc will likely optimize it.
Would you like to clarify the current situation around supported software optimisations any more?
Quoted 2 lines
It is also easier to review, as the error handling is closer to the code.
Do we stumble on different coding style preferences once more?
Quoted 2 lines
On the other hand, there's nothing wrong on taking the approach you're proposing.
Thanks for another bit of positive feedback.
Quoted 2 lines
In the end, using goto or not on error handling like the above is a matter of personal taste - and taste changes with time
Do Linux guidelines need any adjustments?
Quoted 2 lines
and with developer. I really don't have time to keep reviewing patches that are just churning the code just due to someone's personal taste.
I tried to apply another general source code transformation pattern.
Quoted 3 lines
I'm pretty sure if I start accepting things like that, someone else would be on some future doing patches just reverting it, and I would be likely having to apply them too.
Why?
I hope also that the source code can be kept consistent to some degree.
Quoted 3 lines
So, except if the patch is really fixing something - e.g. a broken error handling code, I'll just ignore such patches and mark as rejected without further notice/comments from now on.
I would find such a communication style questionable. Do you distinguish between bug fixes and possible corrections for other error categories (or software weaknesses)?
Regards,
Markus