* [PATCH 0/6] [media] cx24116: Adjustments for two function implementations
@ 2017-08-30 7:18 ` SF Markus Elfring
0 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7:18 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 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(-)
--
2.14.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/6] [media] cx24116: Delete an error message for a failed memory allocation in cx24116_writeregN()
2017-08-30 7:18 ` SF Markus Elfring
@ 2017-08-30 7:19 ` SF Markus Elfring
-1 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7:19 UTC (permalink / raw)
To: linux-media, Mauro Carvalho Chehab, Max Kellermann; +Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index e105532bfba8..96af4ffba0f9 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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;
}
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 1/6] [media] cx24116: Delete an error message for a failed memory allocation in cx24116_write
@ 2017-08-30 7:19 ` SF Markus Elfring
0 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7:19 UTC (permalink / raw)
To: linux-media, Mauro Carvalho Chehab, Max Kellermann; +Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index e105532bfba8..96af4ffba0f9 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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;
}
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/6] [media] cx24116: Return directly after a failed kmalloc() in cx24116_writeregN()
2017-08-30 7:18 ` SF Markus Elfring
@ 2017-08-30 7:20 ` SF Markus Elfring
-1 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7: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 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index 96af4ffba0f9..69c156443b50 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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;
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/6] [media] cx24116: Return directly after a failed kmalloc() in cx24116_writeregN()
@ 2017-08-30 7:20 ` SF Markus Elfring
0 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7: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 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index 96af4ffba0f9..69c156443b50 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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;
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/6] [media] cx24116: Delete an unnecessary variable initialisation in cx24116_writeregN()
2017-08-30 7:18 ` SF Markus Elfring
@ 2017-08-30 7:21 ` SF Markus Elfring
-1 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7: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 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index 69c156443b50..54f09a5a5075 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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;
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/6] [media] cx24116: Delete an unnecessary variable initialisation in cx24116_writeregN()
@ 2017-08-30 7:21 ` SF Markus Elfring
0 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7: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 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index 69c156443b50..54f09a5a5075 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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;
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/6] [media] cx24116: Improve a size determination in cx24116_attach()
2017-08-30 7:18 ` SF Markus Elfring
@ 2017-08-30 7:22 ` SF Markus Elfring
-1 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7: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 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index 54f09a5a5075..74d610207bf2 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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;
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/6] [media] cx24116: Improve a size determination in cx24116_attach()
@ 2017-08-30 7:22 ` SF Markus Elfring
0 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7: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 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index 54f09a5a5075..74d610207bf2 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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;
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 5/6] [media] cx24116: Delete an unnecessary variable initialisation in cx24116_attach()
2017-08-30 7:18 ` SF Markus Elfring
@ 2017-08-30 7:23 ` SF Markus Elfring
-1 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7: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 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index 74d610207bf2..902a60d2e1b5 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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__);
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 5/6] [media] cx24116: Delete an unnecessary variable initialisation in cx24116_attach()
@ 2017-08-30 7:23 ` SF Markus Elfring
0 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7: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 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index 74d610207bf2..902a60d2e1b5 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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__);
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 6/6] [media] cx24116: Delete jump targets in cx24116_attach()
2017-08-30 7:18 ` SF Markus Elfring
@ 2017-08-30 7:24 ` SF Markus Elfring
-1 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7: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 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index 902a60d2e1b5..8fb3f095e21c 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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);
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 6/6] [media] cx24116: Delete jump targets in cx24116_attach()
@ 2017-08-30 7:24 ` SF Markus Elfring
0 siblings, 0 replies; 14+ messages in thread
From: SF Markus Elfring @ 2017-08-30 7: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 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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/media/dvb-frontends/cx24116.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index 902a60d2e1b5..8fb3f095e21c 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -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);
--
2.14.1
^ permalink raw reply related [flat|nested] 14+ messages in thread