mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] [media] ds3000: Adjustments for two function implementations
@ 2017-08-30 20:20 SF Markus Elfring
  2017-08-30 20:21 ` [PATCH 1/4] [media] ds3000: Delete an error message for a failed memory allocation in two functions SF Markus Elfring
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-08-30 20:20 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab, Max Kellermann; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 30 Aug 2017 22:11:33 +0200

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

Markus Elfring (4):
  Delete an error message for a failed memory allocation in two functions
  Improve a size determination in ds3000_attach()
  Delete an unnecessary variable initialisation in ds3000_attach()
  Delete jump targets in ds3000_attach()

 drivers/media/dvb-frontends/ds3000.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

-- 
2.14.1

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

* [PATCH 1/4] [media] ds3000: Delete an error message for a failed memory allocation in two functions
  2017-08-30 20:20 [PATCH 0/4] [media] ds3000: Adjustments for two function implementations SF Markus Elfring
@ 2017-08-30 20:21 ` SF Markus Elfring
  2017-08-30 20:22 ` [PATCH 2/4] [media] ds3000: Improve a size determination in ds3000_attach() SF Markus Elfring
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-08-30 20:21 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab, Max Kellermann; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 30 Aug 2017 21:41:28 +0200

Omit an extra message 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/dvb-frontends/ds3000.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb-frontends/ds3000.c b/drivers/media/dvb-frontends/ds3000.c
index 0b17a45c5640..c2959a9695a7 100644
--- a/drivers/media/dvb-frontends/ds3000.c
+++ b/drivers/media/dvb-frontends/ds3000.c
@@ -280,7 +280,5 @@ static int ds3000_writeFW(struct ds3000_state *state, int reg,
-	if (buf == NULL) {
-		printk(KERN_ERR "Unable to kmalloc\n");
+	if (!buf)
 		return -ENOMEM;
-	}
 
 	*(buf) = reg;
 
@@ -845,7 +843,5 @@ struct dvb_frontend *ds3000_attach(const struct ds3000_config *config,
-	if (state == NULL) {
-		printk(KERN_ERR "Unable to kmalloc\n");
+	if (!state)
 		goto error2;
-	}
 
 	state->config = config;
 	state->i2c = i2c;
-- 
2.14.1

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

* [PATCH 2/4] [media] ds3000: Improve a size determination in ds3000_attach()
  2017-08-30 20:20 [PATCH 0/4] [media] ds3000: Adjustments for two function implementations SF Markus Elfring
  2017-08-30 20:21 ` [PATCH 1/4] [media] ds3000: Delete an error message for a failed memory allocation in two functions SF Markus Elfring
@ 2017-08-30 20:22 ` SF Markus Elfring
  2017-08-30 20:23 ` [PATCH 3/4] [media] ds3000: Delete an unnecessary variable initialisation " SF Markus Elfring
  2017-08-30 20:24 ` [PATCH 4/4] [media] ds3000: Delete jump targets " SF Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-08-30 20:22 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab, Max Kellermann; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 30 Aug 2017 21:49:22 +0200

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

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

diff --git a/drivers/media/dvb-frontends/ds3000.c b/drivers/media/dvb-frontends/ds3000.c
index c2959a9695a7..988a464de3e9 100644
--- a/drivers/media/dvb-frontends/ds3000.c
+++ b/drivers/media/dvb-frontends/ds3000.c
@@ -839,7 +839,7 @@ struct dvb_frontend *ds3000_attach(const struct ds3000_config *config,
 	dprintk("%s\n", __func__);
 
 	/* allocate memory for the internal state */
-	state = kzalloc(sizeof(struct ds3000_state), GFP_KERNEL);
+	state = kzalloc(sizeof(*state), GFP_KERNEL);
 	if (!state)
 		goto error2;
 
-- 
2.14.1

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

* [PATCH 3/4] [media] ds3000: Delete an unnecessary variable initialisation in ds3000_attach()
  2017-08-30 20:20 [PATCH 0/4] [media] ds3000: Adjustments for two function implementations SF Markus Elfring
  2017-08-30 20:21 ` [PATCH 1/4] [media] ds3000: Delete an error message for a failed memory allocation in two functions SF Markus Elfring
  2017-08-30 20:22 ` [PATCH 2/4] [media] ds3000: Improve a size determination in ds3000_attach() SF Markus Elfring
@ 2017-08-30 20:23 ` SF Markus Elfring
  2017-08-30 20:24 ` [PATCH 4/4] [media] ds3000: Delete jump targets " SF Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-08-30 20:23 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab, Max Kellermann; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 30 Aug 2017 21:51:26 +0200

The variable "state" will be set to an appropriate pointer a bit later.
Thus omit the explicit initialisation at the beginning.

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

diff --git a/drivers/media/dvb-frontends/ds3000.c b/drivers/media/dvb-frontends/ds3000.c
index 988a464de3e9..3e347d03acb3 100644
--- a/drivers/media/dvb-frontends/ds3000.c
+++ b/drivers/media/dvb-frontends/ds3000.c
@@ -833,7 +833,7 @@ static const struct dvb_frontend_ops ds3000_ops;
 struct dvb_frontend *ds3000_attach(const struct ds3000_config *config,
 				    struct i2c_adapter *i2c)
 {
-	struct ds3000_state *state = NULL;
+	struct ds3000_state *state;
 	int ret;
 
 	dprintk("%s\n", __func__);
-- 
2.14.1

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

* [PATCH 4/4] [media] ds3000: Delete jump targets in ds3000_attach()
  2017-08-30 20:20 [PATCH 0/4] [media] ds3000: Adjustments for two function implementations SF Markus Elfring
                   ` (2 preceding siblings ...)
  2017-08-30 20:23 ` [PATCH 3/4] [media] ds3000: Delete an unnecessary variable initialisation " SF Markus Elfring
@ 2017-08-30 20:24 ` SF Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-08-30 20:24 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab, Max Kellermann; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 30 Aug 2017 22:02:54 +0200

* Return directly after a call of the function "kzalloc" failed
  at the beginning.

* Move a bit of exception handling code into an if branch.

* Delete two jump targets which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/dvb-frontends/ds3000.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/media/dvb-frontends/ds3000.c b/drivers/media/dvb-frontends/ds3000.c
index 3e347d03acb3..bd4f8278c906 100644
--- a/drivers/media/dvb-frontends/ds3000.c
+++ b/drivers/media/dvb-frontends/ds3000.c
@@ -841,7 +841,7 @@ struct dvb_frontend *ds3000_attach(const struct ds3000_config *config,
 	/* allocate memory for the internal state */
 	state = kzalloc(sizeof(*state), GFP_KERNEL);
 	if (!state)
-		goto error2;
+		return NULL;
 
 	state->config = config;
 	state->i2c = i2c;
@@ -850,8 +850,9 @@ struct dvb_frontend *ds3000_attach(const struct ds3000_config *config,
 	/* check if the demod is present */
 	ret = ds3000_readreg(state, 0x00) & 0xfe;
 	if (ret != 0xe0) {
+		kfree(state);
 		printk(KERN_ERR "Invalid probe, probably not a DS3000\n");
-		goto error3;
+		return NULL;
 	}
 
 	printk(KERN_INFO "DS3000 chip version: %d.%d attached.\n",
@@ -869,11 +870,6 @@ struct dvb_frontend *ds3000_attach(const struct ds3000_config *config,
 	 */
 	ds3000_set_voltage(&state->frontend, SEC_VOLTAGE_OFF);
 	return &state->frontend;
-
-error3:
-	kfree(state);
-error2:
-	return NULL;
 }
 EXPORT_SYMBOL(ds3000_attach);
 
-- 
2.14.1

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-30 20:20 [PATCH 0/4] [media] ds3000: Adjustments for two function implementations SF Markus Elfring
2017-08-30 20:21 ` [PATCH 1/4] [media] ds3000: Delete an error message for a failed memory allocation in two functions SF Markus Elfring
2017-08-30 20:22 ` [PATCH 2/4] [media] ds3000: Improve a size determination in ds3000_attach() SF Markus Elfring
2017-08-30 20:23 ` [PATCH 3/4] [media] ds3000: Delete an unnecessary variable initialisation " SF Markus Elfring
2017-08-30 20:24 ` [PATCH 4/4] [media] ds3000: Delete jump targets " 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