mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/8] [media] Cx231xx: Adjustments for several function implementations
@ 2017-09-17 20:15 SF Markus Elfring
  2017-09-17 20:16 ` [PATCH 1/8] [media] cx231xx: Delete eight error messages for a failed memory allocation SF Markus Elfring
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: SF Markus Elfring @ 2017-09-17 20:15 UTC (permalink / raw)
  To: linux-media, Bhumika Goyal, Hans Verkuil, Johan Hovold,
	Julia Lawall, Matthias Schwarzott, Mauro Carvalho Chehab,
	Oleh Kravchenko, Peter Rosin, Sakari Ailus
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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(-)

-- 
2.14.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/8] [media] cx231xx: Delete eight error messages for a failed memory allocation
  2017-09-17 20:15 [PATCH 0/8] [media] Cx231xx: Adjustments for several function implementations SF Markus Elfring
@ 2017-09-17 20:16 ` SF Markus Elfring
  2017-09-17 20:17 ` [PATCH 2/8] [media] cx231xx: Adjust 56 checks for null pointers SF Markus Elfring
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: SF Markus Elfring @ 2017-09-17 20:16 UTC (permalink / raw)
  To: linux-media, Bhumika Goyal, Hans Verkuil, Johan Hovold,
	Julia Lawall, Matthias Schwarzott, Mauro Carvalho Chehab,
	Oleh Kravchenko, Peter Rosin, Sakari Ailus
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 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(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c b/drivers/media/usb/cx231xx/cx231xx-core.c
index f372ad3917a8..d9f4ae50e869 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -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);
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index c18bb33e060e..248b62e2099c 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -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;
diff --git a/drivers/media/usb/cx231xx/cx231xx-vbi.c b/drivers/media/usb/cx231xx/cx231xx-vbi.c
index 76e901920f6f..9c27db16db2a 100644
--- a/drivers/media/usb/cx231xx/cx231xx-vbi.c
+++ b/drivers/media/usb/cx231xx/cx231xx-vbi.c
@@ -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;
 		}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/8] [media] cx231xx: Adjust 56 checks for null pointers
  2017-09-17 20:15 [PATCH 0/8] [media] Cx231xx: Adjustments for several function implementations SF Markus Elfring
  2017-09-17 20:16 ` [PATCH 1/8] [media] cx231xx: Delete eight error messages for a failed memory allocation SF Markus Elfring
@ 2017-09-17 20:17 ` SF Markus Elfring
  2017-09-17 20:18 ` [PATCH 3/8] [media] cx231xx: Improve six size determinations SF Markus Elfring
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: SF Markus Elfring @ 2017-09-17 20:17 UTC (permalink / raw)
  To: linux-media, Bhumika Goyal, Hans Verkuil, Johan Hovold,
	Julia Lawall, Matthias Schwarzott, Mauro Carvalho Chehab,
	Oleh Kravchenko, Peter Rosin, Sakari Ailus
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 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(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-417.c b/drivers/media/usb/cx231xx/cx231xx-417.c
index d538fa407742..d43345593172 100644
--- a/drivers/media/usb/cx231xx/cx231xx-417.c
+++ b/drivers/media/usb/cx231xx/cx231xx-417.c
@@ -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;
 	}
diff --git a/drivers/media/usb/cx231xx/cx231xx-audio.c b/drivers/media/usb/cx231xx/cx231xx-audio.c
index 06f10d7fc4b0..f98ba0c66f8f 100644
--- a/drivers/media/usb/cx231xx/cx231xx-audio.c
+++ b/drivers/media/usb/cx231xx/cx231xx-audio.c
@@ -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) {
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index e0daa9b6c2a0..d204f220dfe5 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -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;
 		}
diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c b/drivers/media/usb/cx231xx/cx231xx-core.c
index d9f4ae50e869..76ce18cf2383 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -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;
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 248b62e2099c..0813f368fb3c 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -408,11 +408,10 @@ static int attach_xc5000(u8 addr, struct cx231xx *dev)
 
 int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq)
 {
-	if ((dev->dvb != NULL) && (dev->dvb->frontend != NULL)) {
-
+	if (dev->dvb && dev->dvb->frontend) {
 		struct dvb_tuner_ops *dops = &dev->dvb->frontend->ops.tuner_ops;
 
-		if (dops->set_analog_params != NULL) {
+		if (dops->set_analog_params) {
 			struct analog_parameters params;
 
 			params.frequency = freq;
@@ -433,12 +432,10 @@ int cx231xx_reset_analog_tuner(struct cx231xx *dev)
 {
 	int status = 0;
 
-	if ((dev->dvb != NULL) && (dev->dvb->frontend != NULL)) {
-
+	if (dev->dvb && dev->dvb->frontend) {
 		struct dvb_tuner_ops *dops = &dev->dvb->frontend->ops.tuner_ops;
 
-		if (dops->init != NULL && !dev->xc_fw_load_done) {
-
+		if (dops->init && !dev->xc_fw_load_done) {
 			dev_dbg(dev->dev,
 				"Reloading firmware for XC5000\n");
 			status = dops->init(dev->dvb->frontend);
@@ -635,8 +632,7 @@ static int dvb_init(struct cx231xx *dev)
 		dev->dvb->frontend = dvb_attach(s5h1432_attach,
 					&dvico_s5h1432_config,
 					demod_i2c);
-
-		if (dev->dvb->frontend == NULL) {
+		if (!dev->dvb->frontend) {
 			dev_err(dev->dev,
 				"Failed to attach s5h1432 front end\n");
 			result = -EINVAL;
@@ -660,8 +656,7 @@ static int dvb_init(struct cx231xx *dev)
 		dev->dvb->frontend = dvb_attach(s5h1411_attach,
 					       &xc5000_s5h1411_config,
 					       demod_i2c);
-
-		if (dev->dvb->frontend == NULL) {
+		if (!dev->dvb->frontend) {
 			dev_err(dev->dev,
 				"Failed to attach s5h1411 front end\n");
 			result = -EINVAL;
@@ -683,8 +678,7 @@ static int dvb_init(struct cx231xx *dev)
 		dev->dvb->frontend = dvb_attach(s5h1432_attach,
 					&dvico_s5h1432_config,
 					demod_i2c);
-
-		if (dev->dvb->frontend == NULL) {
+		if (!dev->dvb->frontend) {
 			dev_err(dev->dev,
 				"Failed to attach s5h1432 front end\n");
 			result = -EINVAL;
@@ -707,8 +701,7 @@ static int dvb_init(struct cx231xx *dev)
 		dev->dvb->frontend = dvb_attach(s5h1411_attach,
 					       &tda18271_s5h1411_config,
 					       demod_i2c);
-
-		if (dev->dvb->frontend == NULL) {
+		if (!dev->dvb->frontend) {
 			dev_err(dev->dev,
 				"Failed to attach s5h1411 front end\n");
 			result = -EINVAL;
@@ -734,8 +727,7 @@ static int dvb_init(struct cx231xx *dev)
 		dev->dvb->frontend = dvb_attach(lgdt3305_attach,
 						&hcw_lgdt3305_config,
 						demod_i2c);
-
-		if (dev->dvb->frontend == NULL) {
+		if (!dev->dvb->frontend) {
 			dev_err(dev->dev,
 				"Failed to attach LG3305 front end\n");
 			result = -EINVAL;
@@ -768,7 +760,7 @@ static int dvb_init(struct cx231xx *dev)
 		info.platform_data = &si2165_pdata;
 		request_module(info.type);
 		client = i2c_new_device(demod_i2c, &info);
-		if (client == NULL || client->dev.driver == NULL || dev->dvb->frontend == NULL) {
+		if (!client || !client->dev.driver || !dev->dvb->frontend) {
 			dev_err(dev->dev,
 				"Failed to attach SI2165 front end\n");
 			result = -EINVAL;
@@ -815,7 +807,7 @@ static int dvb_init(struct cx231xx *dev)
 		info.platform_data = &si2165_pdata;
 		request_module(info.type);
 		client = i2c_new_device(demod_i2c, &info);
-		if (client == NULL || client->dev.driver == NULL || dev->dvb->frontend == NULL) {
+		if (!client || !client->dev.driver || !dev->dvb->frontend) {
 			dev_err(dev->dev,
 				"Failed to attach SI2165 front end\n");
 			result = -EINVAL;
@@ -853,7 +845,7 @@ static int dvb_init(struct cx231xx *dev)
 		client = i2c_new_device(
 			tuner_i2c,
 			&info);
-		if (client == NULL || client->dev.driver == NULL) {
+		if (!client || !client->dev.driver) {
 			dvb_frontend_detach(dev->dvb->frontend);
 			result = -ENODEV;
 			goto out_free;
@@ -883,8 +875,7 @@ static int dvb_init(struct cx231xx *dev)
 			&hauppauge_955q_lgdt3306a_config,
 			demod_i2c
 			);
-
-		if (dev->dvb->frontend == NULL) {
+		if (!dev->dvb->frontend) {
 			dev_err(dev->dev,
 				"Failed to attach LGDT3306A frontend.\n");
 			result = -EINVAL;
@@ -912,7 +903,7 @@ static int dvb_init(struct cx231xx *dev)
 		client = i2c_new_device(
 			tuner_i2c,
 			&info);
-		if (client == NULL || client->dev.driver == NULL) {
+		if (!client || !client->dev.driver) {
 			dvb_frontend_detach(dev->dvb->frontend);
 			result = -ENODEV;
 			goto out_free;
@@ -940,8 +931,7 @@ static int dvb_init(struct cx231xx *dev)
 		dev->dvb->frontend = dvb_attach(mb86a20s_attach,
 						&pv_mb86a20s_config,
 						demod_i2c);
-
-		if (dev->dvb->frontend == NULL) {
+		if (!dev->dvb->frontend) {
 			dev_err(dev->dev,
 				"Failed to attach mb86a20s demod\n");
 			result = -EINVAL;
@@ -976,8 +966,7 @@ static int dvb_init(struct cx231xx *dev)
 
 		request_module(info.type);
 		client = i2c_new_device(demod_i2c, &info);
-
-		if (client == NULL || client->dev.driver == NULL) {
+		if (!client || !client->dev.driver) {
 			result = -ENODEV;
 			goto out_free;
 		}
@@ -1005,8 +994,7 @@ static int dvb_init(struct cx231xx *dev)
 
 		request_module(info.type);
 		client = i2c_new_device(tuner_i2c, &info);
-
-		if (client == NULL || client->dev.driver == NULL) {
+		if (!client || !client->dev.driver) {
 			module_put(dvb->i2c_client_demod->dev.driver->owner);
 			i2c_unregister_device(dvb->i2c_client_demod);
 			result = -ENODEV;
@@ -1042,8 +1030,7 @@ static int dvb_init(struct cx231xx *dev)
 
 		request_module(info.type);
 		client = i2c_new_device(demod_i2c, &info);
-
-		if (client == NULL || client->dev.driver == NULL) {
+		if (!client || !client->dev.driver) {
 			result = -ENODEV;
 			goto out_free;
 		}
@@ -1071,7 +1058,7 @@ static int dvb_init(struct cx231xx *dev)
 			dev->name);
 		break;
 	}
-	if (NULL == dvb->frontend) {
+	if (!dvb->frontend) {
 		dev_err(dev->dev,
 		       "%s/2: frontend initialization failed\n", dev->name);
 		result = -EINVAL;
diff --git a/drivers/media/usb/cx231xx/cx231xx-vbi.c b/drivers/media/usb/cx231xx/cx231xx-vbi.c
index 9c27db16db2a..8ec53017da2b 100644
--- a/drivers/media/usb/cx231xx/cx231xx-vbi.c
+++ b/drivers/media/usb/cx231xx/cx231xx-vbi.c
@@ -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);
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index 179b8481a870..956f8cbcb454 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -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);
-- 
2.14.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/8] [media] cx231xx: Improve six size determinations
  2017-09-17 20:15 [PATCH 0/8] [media] Cx231xx: Adjustments for several function implementations SF Markus Elfring
  2017-09-17 20:16 ` [PATCH 1/8] [media] cx231xx: Delete eight error messages for a failed memory allocation SF Markus Elfring
  2017-09-17 20:17 ` [PATCH 2/8] [media] cx231xx: Adjust 56 checks for null pointers SF Markus Elfring
@ 2017-09-17 20:18 ` SF Markus Elfring
  2017-09-17 20:19 ` [PATCH 4/8] [media] cx231xx: Delete an unnecessary variable initialisation in dvb_init() SF Markus Elfring
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: SF Markus Elfring @ 2017-09-17 20:18 UTC (permalink / raw)
  To: linux-media, Bhumika Goyal, Hans Verkuil, Johan Hovold,
	Julia Lawall, Matthias Schwarzott, Mauro Carvalho Chehab,
	Oleh Kravchenko, Peter Rosin, Sakari Ailus
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/usb/cx231xx/cx231xx-dvb.c   | 10 +++++-----
 drivers/media/usb/cx231xx/cx231xx-video.c |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 0813f368fb3c..35d98ec948b2 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -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,
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index 956f8cbcb454..a12ec3567684 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -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)
-- 
2.14.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/8] [media] cx231xx: Delete an unnecessary variable initialisation in dvb_init()
  2017-09-17 20:15 [PATCH 0/8] [media] Cx231xx: Adjustments for several function implementations SF Markus Elfring
                   ` (2 preceding siblings ...)
  2017-09-17 20:18 ` [PATCH 3/8] [media] cx231xx: Improve six size determinations SF Markus Elfring
@ 2017-09-17 20:19 ` SF Markus Elfring
  2017-09-17 20:21 ` [PATCH 5/8] [media] cx231xx: Use common error handling code " SF Markus Elfring
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: SF Markus Elfring @ 2017-09-17 20:19 UTC (permalink / raw)
  To: linux-media, Bhumika Goyal, Hans Verkuil, Johan Hovold,
	Julia Lawall, Matthias Schwarzott, Mauro Carvalho Chehab,
	Oleh Kravchenko, Peter Rosin, Sakari Ailus
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/usb/cx231xx/cx231xx-dvb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 35d98ec948b2..091ec0cf56a6 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -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;
-- 
2.14.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/8] [media] cx231xx: Use common error handling code in dvb_init()
  2017-09-17 20:15 [PATCH 0/8] [media] Cx231xx: Adjustments for several function implementations SF Markus Elfring
                   ` (3 preceding siblings ...)
  2017-09-17 20:19 ` [PATCH 4/8] [media] cx231xx: Delete an unnecessary variable initialisation in dvb_init() SF Markus Elfring
@ 2017-09-17 20:21 ` SF Markus Elfring
  2017-09-17 20:22 ` [PATCH 6/8] [media] cx231xx: Use common error handling code in read_eeprom() SF Markus Elfring
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: SF Markus Elfring @ 2017-09-17 20:21 UTC (permalink / raw)
  To: linux-media, Bhumika Goyal, Hans Verkuil, Johan Hovold,
	Julia Lawall, Matthias Schwarzott, Mauro Carvalho Chehab,
	Oleh Kravchenko, Peter Rosin, Sakari Ailus
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/usb/cx231xx/cx231xx-dvb.c | 135 +++++++++++++-------------------
 1 file changed, 53 insertions(+), 82 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 091ec0cf56a6..af51113b4a55 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -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;
-- 
2.14.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/8] [media] cx231xx: Use common error handling code in read_eeprom()
  2017-09-17 20:15 [PATCH 0/8] [media] Cx231xx: Adjustments for several function implementations SF Markus Elfring
                   ` (4 preceding siblings ...)
  2017-09-17 20:21 ` [PATCH 5/8] [media] cx231xx: Use common error handling code " SF Markus Elfring
@ 2017-09-17 20:22 ` SF Markus Elfring
  2017-09-17 20:23 ` [PATCH 7/8] [media] cx231xx: Delete an unnecessary variable initialisation " SF Markus Elfring
  2017-09-17 20:24 ` [PATCH 8/8] [media] cx231xx: Use common error handling code in cx231xx_load_firmware() SF Markus Elfring
  7 siblings, 0 replies; 9+ messages in thread
From: SF Markus Elfring @ 2017-09-17 20:22 UTC (permalink / raw)
  To: linux-media, Bhumika Goyal, Hans Verkuil, Johan Hovold,
	Julia Lawall, Matthias Schwarzott, Mauro Carvalho Chehab,
	Oleh Kravchenko, Peter Rosin, Sakari Ailus
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/usb/cx231xx/cx231xx-cards.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index d204f220dfe5..04c0734aee79 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -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)
-- 
2.14.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 7/8] [media] cx231xx: Delete an unnecessary variable initialisation in read_eeprom()
  2017-09-17 20:15 [PATCH 0/8] [media] Cx231xx: Adjustments for several function implementations SF Markus Elfring
                   ` (5 preceding siblings ...)
  2017-09-17 20:22 ` [PATCH 6/8] [media] cx231xx: Use common error handling code in read_eeprom() SF Markus Elfring
@ 2017-09-17 20:23 ` SF Markus Elfring
  2017-09-17 20:24 ` [PATCH 8/8] [media] cx231xx: Use common error handling code in cx231xx_load_firmware() SF Markus Elfring
  7 siblings, 0 replies; 9+ messages in thread
From: SF Markus Elfring @ 2017-09-17 20:23 UTC (permalink / raw)
  To: linux-media, Bhumika Goyal, Hans Verkuil, Johan Hovold,
	Julia Lawall, Matthias Schwarzott, Mauro Carvalho Chehab,
	Oleh Kravchenko, Peter Rosin, Sakari Ailus
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/usb/cx231xx/cx231xx-cards.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 04c0734aee79..69fdd507fa92 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -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;
-- 
2.14.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 8/8] [media] cx231xx: Use common error handling code in cx231xx_load_firmware()
  2017-09-17 20:15 [PATCH 0/8] [media] Cx231xx: Adjustments for several function implementations SF Markus Elfring
                   ` (6 preceding siblings ...)
  2017-09-17 20:23 ` [PATCH 7/8] [media] cx231xx: Delete an unnecessary variable initialisation " SF Markus Elfring
@ 2017-09-17 20:24 ` SF Markus Elfring
  7 siblings, 0 replies; 9+ messages in thread
From: SF Markus Elfring @ 2017-09-17 20:24 UTC (permalink / raw)
  To: linux-media, Bhumika Goyal, Hans Verkuil, Johan Hovold,
	Julia Lawall, Matthias Schwarzott, Mauro Carvalho Chehab,
	Oleh Kravchenko, Peter Rosin, Sakari Ailus
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/usb/cx231xx/cx231xx-417.c | 61 ++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 32 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-417.c b/drivers/media/usb/cx231xx/cx231xx-417.c
index d43345593172..88aac129b678 100644
--- a/drivers/media/usb/cx231xx/cx231xx-417.c
+++ b/drivers/media/usb/cx231xx/cx231xx-417.c
@@ -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)
-- 
2.14.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-09-17 20:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-17 20:15 [PATCH 0/8] [media] Cx231xx: Adjustments for several function implementations SF Markus Elfring
2017-09-17 20:16 ` [PATCH 1/8] [media] cx231xx: Delete eight error messages for a failed memory allocation SF Markus Elfring
2017-09-17 20:17 ` [PATCH 2/8] [media] cx231xx: Adjust 56 checks for null pointers SF Markus Elfring
2017-09-17 20:18 ` [PATCH 3/8] [media] cx231xx: Improve six size determinations SF Markus Elfring
2017-09-17 20:19 ` [PATCH 4/8] [media] cx231xx: Delete an unnecessary variable initialisation in dvb_init() SF Markus Elfring
2017-09-17 20:21 ` [PATCH 5/8] [media] cx231xx: Use common error handling code " SF Markus Elfring
2017-09-17 20:22 ` [PATCH 6/8] [media] cx231xx: Use common error handling code in read_eeprom() SF Markus Elfring
2017-09-17 20:23 ` [PATCH 7/8] [media] cx231xx: Delete an unnecessary variable initialisation " SF Markus Elfring
2017-09-17 20:24 ` [PATCH 8/8] [media] cx231xx: Use common error handling code in cx231xx_load_firmware() SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome