linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] [media] xc2028: Adjustments for two function implementations
@ 2017-09-09 20:30 SF Markus Elfring
  2017-09-09 20:31 ` [PATCH 1/3] [media] xc2028: Delete two error messages for a failed memory allocation in load_all_firmwares() SF Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-09-09 20:30 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Sep 2017 22:18:22 +0200

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
  Delete two error messages for a failed memory allocation
  Adjust two null pointer checks
  Use common error handling code in load_firmware()

 drivers/media/tuners/tuner-xc2028.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

-- 
2.14.1

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

* [PATCH 1/3] [media] xc2028: Delete two error messages for a failed memory allocation in load_all_firmwares()
  2017-09-09 20:30 [PATCH 0/3] [media] xc2028: Adjustments for two function implementations SF Markus Elfring
@ 2017-09-09 20:31 ` SF Markus Elfring
  2017-09-09 20:32 ` [PATCH 2/3] [media] xc2028: Adjust two null pointer checks " SF Markus Elfring
  2017-09-09 20:33 ` [PATCH 3/3] [media] xc2028: Use common error handling code in load_firmware() SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-09-09 20:31 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Sep 2017 21:30:11 +0200

Omit extra messages for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/tuners/tuner-xc2028.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/tuners/tuner-xc2028.c b/drivers/media/tuners/tuner-xc2028.c
index b5b62b08159e..7353f25f9e7d 100644
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -339,4 +339,3 @@ static int load_all_firmwares(struct dvb_frontend *fe,
-		tuner_err("Not enough memory to load firmware file.\n");
 		rc = -ENOMEM;
 		goto err;
 	}
@@ -389,4 +388,3 @@ static int load_all_firmwares(struct dvb_frontend *fe,
-			tuner_err("Not enough memory to load firmware file.\n");
 			rc = -ENOMEM;
 			goto err;
 		}
-- 
2.14.1

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

* [PATCH 2/3] [media] xc2028: Adjust two null pointer checks in load_all_firmwares()
  2017-09-09 20:30 [PATCH 0/3] [media] xc2028: Adjustments for two function implementations SF Markus Elfring
  2017-09-09 20:31 ` [PATCH 1/3] [media] xc2028: Delete two error messages for a failed memory allocation in load_all_firmwares() SF Markus Elfring
@ 2017-09-09 20:32 ` SF Markus Elfring
  2017-09-09 20:33 ` [PATCH 3/3] [media] xc2028: Use common error handling code in load_firmware() SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-09-09 20:32 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Sep 2017 21:48:58 +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/tuners/tuner-xc2028.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/tuners/tuner-xc2028.c b/drivers/media/tuners/tuner-xc2028.c
index 7353f25f9e7d..90efe11aa0a8 100644
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -335,5 +335,5 @@ static int load_all_firmwares(struct dvb_frontend *fe,
 		   priv->firm_version >> 8, priv->firm_version & 0xff);
 
 	priv->firm = kcalloc(n_array, sizeof(*priv->firm), GFP_KERNEL);
-	if (priv->firm == NULL) {
+	if (!priv->firm) {
 		rc = -ENOMEM;
@@ -384,5 +384,5 @@ static int load_all_firmwares(struct dvb_frontend *fe,
 		}
 
 		priv->firm[n].ptr = kzalloc(size, GFP_KERNEL);
-		if (priv->firm[n].ptr == NULL) {
+		if (!priv->firm[n].ptr) {
 			rc = -ENOMEM;
-- 
2.14.1

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

* [PATCH 3/3] [media] xc2028: Use common error handling code in load_firmware()
  2017-09-09 20:30 [PATCH 0/3] [media] xc2028: Adjustments for two function implementations SF Markus Elfring
  2017-09-09 20:31 ` [PATCH 1/3] [media] xc2028: Delete two error messages for a failed memory allocation in load_all_firmwares() SF Markus Elfring
  2017-09-09 20:32 ` [PATCH 2/3] [media] xc2028: Adjust two null pointer checks " SF Markus Elfring
@ 2017-09-09 20:33 ` SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-09-09 20:33 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 9 Sep 2017 22:07:04 +0200

Add jump targets 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/tuners/tuner-xc2028.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/media/tuners/tuner-xc2028.c b/drivers/media/tuners/tuner-xc2028.c
index 90efe11aa0a8..4b617e09b81f 100644
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -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,
-- 
2.14.1

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-09 20:30 [PATCH 0/3] [media] xc2028: Adjustments for two function implementations SF Markus Elfring
2017-09-09 20:31 ` [PATCH 1/3] [media] xc2028: Delete two error messages for a failed memory allocation in load_all_firmwares() SF Markus Elfring
2017-09-09 20:32 ` [PATCH 2/3] [media] xc2028: Adjust two null pointer checks " SF Markus Elfring
2017-09-09 20:33 ` [PATCH 3/3] [media] xc2028: Use common error handling code in 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;
as well as URLs for NNTP newsgroup(s).