Skip to contentSkip to conversation

ds3000: Adjustments for two function implementations

PATCH New SF Markus Elfring 1 participant 5 messages Aug 30, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ds3000: Adjustments for two function implementations

From: Markus Elfring <[email protected]>
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(-)
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/4 ds3000: Delete an error message for a failed memory allocation in two functions

From: Markus Elfring <[email protected]>
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.

---
 drivers/media/dvb-frontends/ds3000.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/media/dvb-frontends/ds3000.c +2 -6
index 0b17a45c5640..c2959a9695a7 100644
@@ -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;
Signature · 1 line
2.14.1
#2 lore raw

PATCH 2/4 ds3000: Improve a size determination in ds3000_attach()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 drivers/media/dvb-frontends/ds3000.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb-frontends/ds3000.c +1 -1
index c2959a9695a7..988a464de3e9 100644
@@ -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;
 
Signature · 1 line
2.14.1
#3 lore raw

PATCH 3/4 ds3000: Delete an unnecessary variable initialisation in ds3000_attach()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 drivers/media/dvb-frontends/ds3000.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb-frontends/ds3000.c +1 -1
index 988a464de3e9..3e347d03acb3 100644
@@ -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__);
Signature · 1 line
2.14.1
#4 lore raw

PATCH 4/4 ds3000: Delete jump targets in ds3000_attach()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 drivers/media/dvb-frontends/ds3000.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/media/dvb-frontends/ds3000.c +3 -7
index 3e347d03acb3..bd4f8278c906 100644
@@ -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);
 
Signature · 1 line
2.14.1