Skip to contentSkip to conversation

cx24116: Adjustments for two function implementations

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

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

cover cx24116: Adjustments for two function implementations

From: Markus Elfring <[email protected]>
Date: Wed, 30 Aug 2017 09:05:04 +0200

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

Markus Elfring (6):
Delete an error message for a failed memory allocation in cx24116_writeregN() Return directly after a failed kmalloc() in cx24116_writeregN() Delete an unnecessary variable initialisation in cx24116_writeregN() Improve a size determination in cx24116_attach()
Delete an unnecessary variable initialisation in cx24116_attach() Delete jump targets in cx24116_attach()

 drivers/media/dvb-frontends/cx24116.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/6 cx24116: Delete an error message for a failed memory allocation in cx24116_writeregN()

From: Markus Elfring <[email protected]>
Date: Tue, 29 Aug 2017 22:56:29 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

---
 drivers/media/dvb-frontends/cx24116.c | 1 -
 1 file changed, 1 deletion(-)
drivers/media/dvb-frontends/cx24116.c +0 -1
index e105532bfba8..96af4ffba0f9 100644
@@ -227,7 +227,6 @@ static int cx24116_writeregN(struct cx24116_state *state, int reg,
 
 	buf = kmalloc(len + 1, GFP_KERNEL);
 	if (buf = NULL) {
-		printk("Unable to kmalloc\n");
 		ret = -ENOMEM;
 		goto error;
 	}
Signature · 1 line
2.14.1
#2 lore raw

PATCH 2/6 cx24116: Return directly after a failed kmalloc() in cx24116_writeregN()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 30 Aug 2017 07:55:49 +0200

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

* Delete the jump target "error" which became unnecessary with this refactoring.

---
 drivers/media/dvb-frontends/cx24116.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/media/dvb-frontends/cx24116.c +2 -5
index 96af4ffba0f9..69c156443b50 100644
@@ -226,10 +226,8 @@ static int cx24116_writeregN(struct cx24116_state *state, int reg,
 	u8 *buf;
 
 	buf = kmalloc(len + 1, GFP_KERNEL);
-	if (buf = NULL) {
-		ret = -ENOMEM;
-		goto error;
-	}
+	if (!buf)
+		return -ENOMEM;
 
 	*(buf) = reg;
 	memcpy(buf + 1, data, len);
@@ -250,7 +248,6 @@ static int cx24116_writeregN(struct cx24116_state *state, int reg,
 		ret = -EREMOTEIO;
 	}
 
-error:
 	kfree(buf);
 
 	return ret;
Signature · 1 line
2.14.1
#3 lore raw

PATCH 3/6 cx24116: Delete an unnecessary variable initialisation in cx24116_writeregN()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 30 Aug 2017 08:10:38 +0200

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

---
 drivers/media/dvb-frontends/cx24116.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb-frontends/cx24116.c +1 -1
index 69c156443b50..54f09a5a5075 100644
@@ -221,7 +221,7 @@ static int cx24116_writereg(struct cx24116_state *state, int reg, int data)
 static int cx24116_writeregN(struct cx24116_state *state, int reg,
 			     const u8 *data, u16 len)
 {
-	int ret = -EREMOTEIO;
+	int ret;
 	struct i2c_msg msg;
 	u8 *buf;
 
Signature · 1 line
2.14.1
#4 lore raw

PATCH 4/6 cx24116: Improve a size determination in cx24116_attach()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 30 Aug 2017 08:15:33 +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/cx24116.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb-frontends/cx24116.c +1 -1
index 54f09a5a5075..74d610207bf2 100644
@@ -1123,7 +1123,7 @@ struct dvb_frontend *cx24116_attach(const struct cx24116_config *config,
 	dprintk("%s\n", __func__);
 
 	/* allocate memory for the internal state */
-	state = kzalloc(sizeof(struct cx24116_state), GFP_KERNEL);
+	state = kzalloc(sizeof(*state), GFP_KERNEL);
 	if (state = NULL)
 		goto error1;
 
Signature · 1 line
2.14.1
#5 lore raw

PATCH 5/6 cx24116: Delete an unnecessary variable initialisation in cx24116_attach()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 30 Aug 2017 08:30:12 +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/cx24116.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb-frontends/cx24116.c +1 -1
index 74d610207bf2..902a60d2e1b5 100644
@@ -1117,7 +1117,7 @@ static const struct dvb_frontend_ops cx24116_ops;
 struct dvb_frontend *cx24116_attach(const struct cx24116_config *config,
 	struct i2c_adapter *i2c)
 {
-	struct cx24116_state *state = NULL;
+	struct cx24116_state *state;
 	int ret;
 
 	dprintk("%s\n", __func__);
Signature · 1 line
2.14.1
#6 lore raw

PATCH 6/6 cx24116: Delete jump targets in cx24116_attach()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 30 Aug 2017 08:44:29 +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/cx24116.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/dvb-frontends/cx24116.c +3 -5
index 902a60d2e1b5..8fb3f095e21c 100644
@@ -1125,7 +1125,7 @@ struct dvb_frontend *cx24116_attach(const struct cx24116_config *config,
 	/* allocate memory for the internal state */
 	state = kzalloc(sizeof(*state), GFP_KERNEL);
 	if (state = NULL)
-		goto error1;
+		return NULL;
 
 	state->config = config;
 	state->i2c = i2c;
@@ -1134,8 +1134,9 @@ struct dvb_frontend *cx24116_attach(const struct cx24116_config *config,
 	ret = (cx24116_readreg(state, 0xFF) << 8) |
 		cx24116_readreg(state, 0xFE);
 	if (ret != 0x0501) {
+		kfree(state);
 		printk(KERN_INFO "Invalid probe, probably not a CX24116 device\n");
-		goto error2;
+		return NULL;
 	}
 
 	/* create dvb_frontend */
@@ -1143,9 +1144,6 @@ struct dvb_frontend *cx24116_attach(const struct cx24116_config *config,
 		sizeof(struct dvb_frontend_ops));
 	state->frontend.demodulator_priv = state;
 	return &state->frontend;
-
-error2: kfree(state);
-error1: return NULL;
 }
 EXPORT_SYMBOL(cx24116_attach);
 
Signature · 1 line
2.14.1