mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] [media] SP2: Adjustments for two function implementations
@ 2017-09-01 19:41 SF Markus Elfring
  2017-09-01 19:42 ` [PATCH 1/4] [media] sp2: Delete an error message for a failed memory allocation in sp2_probe() SF Markus Elfring
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-09-01 19:41 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab, Olli Salonen; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 1 Sep 2017 21:31:23 +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
  Improve a size determination
  Adjust a jump target
  Adjust three null pointer checks

 drivers/media/dvb-frontends/sp2.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

-- 
2.14.1

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

* [PATCH 1/4] [media] sp2: Delete an error message for a failed memory allocation in sp2_probe()
  2017-09-01 19:41 [PATCH 0/4] [media] SP2: Adjustments for two function implementations SF Markus Elfring
@ 2017-09-01 19:42 ` SF Markus Elfring
  2017-09-01 19:43 ` [PATCH 2/4] [media] sp2: Improve a size determination " SF Markus Elfring
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-09-01 19:42 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab, Olli Salonen; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 1 Sep 2017 20:44:05 +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/sp2.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/sp2.c b/drivers/media/dvb-frontends/sp2.c
index 43d47dfcc7b8..d3b4f8822096 100644
--- a/drivers/media/dvb-frontends/sp2.c
+++ b/drivers/media/dvb-frontends/sp2.c
@@ -385,6 +385,5 @@ static int sp2_probe(struct i2c_client *client,
 	if (!s) {
 		ret = -ENOMEM;
-		dev_err(&client->dev, "kzalloc() failed\n");
 		goto err;
 	}
 
-- 
2.14.1

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

* [PATCH 2/4] [media] sp2: Improve a size determination in sp2_probe()
  2017-09-01 19:41 [PATCH 0/4] [media] SP2: Adjustments for two function implementations SF Markus Elfring
  2017-09-01 19:42 ` [PATCH 1/4] [media] sp2: Delete an error message for a failed memory allocation in sp2_probe() SF Markus Elfring
@ 2017-09-01 19:43 ` SF Markus Elfring
  2017-09-01 19:44 ` [PATCH 3/4] [media] sp2: Adjust a jump target " SF Markus Elfring
  2017-09-01 19:45 ` [PATCH 4/4] [media] sp2: Adjust three null pointer checks in sp2_exit() SF Markus Elfring
  3 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-09-01 19:43 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab, Olli Salonen; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 1 Sep 2017 20:46:18 +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/sp2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/sp2.c b/drivers/media/dvb-frontends/sp2.c
index d3b4f8822096..dd556012ceb6 100644
--- a/drivers/media/dvb-frontends/sp2.c
+++ b/drivers/media/dvb-frontends/sp2.c
@@ -381,6 +381,6 @@ static int sp2_probe(struct i2c_client *client,
 
 	dev_dbg(&client->dev, "\n");
 
-	s = kzalloc(sizeof(struct sp2), GFP_KERNEL);
+	s = kzalloc(sizeof(*s), GFP_KERNEL);
 	if (!s) {
 		ret = -ENOMEM;
-- 
2.14.1

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

* [PATCH 3/4] [media] sp2: Adjust a jump target in sp2_probe()
  2017-09-01 19:41 [PATCH 0/4] [media] SP2: Adjustments for two function implementations SF Markus Elfring
  2017-09-01 19:42 ` [PATCH 1/4] [media] sp2: Delete an error message for a failed memory allocation in sp2_probe() SF Markus Elfring
  2017-09-01 19:43 ` [PATCH 2/4] [media] sp2: Improve a size determination " SF Markus Elfring
@ 2017-09-01 19:44 ` SF Markus Elfring
  2017-09-08 13:42   ` Hans Verkuil
  2017-09-01 19:45 ` [PATCH 4/4] [media] sp2: Adjust three null pointer checks in sp2_exit() SF Markus Elfring
  3 siblings, 1 reply; 6+ messages in thread
From: SF Markus Elfring @ 2017-09-01 19:44 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab, Olli Salonen; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 1 Sep 2017 21:08:38 +0200

* Adjust a jump target so that a null pointer will not be passed to a call
  of the function "kfree".

* Move this function call into an if branch.

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

diff --git a/drivers/media/dvb-frontends/sp2.c b/drivers/media/dvb-frontends/sp2.c
index dd556012ceb6..b2a7a54174ae 100644
--- a/drivers/media/dvb-frontends/sp2.c
+++ b/drivers/media/dvb-frontends/sp2.c
@@ -384,7 +384,7 @@ static int sp2_probe(struct i2c_client *client,
 	s = kzalloc(sizeof(*s), GFP_KERNEL);
 	if (!s) {
 		ret = -ENOMEM;
-		goto err;
+		goto report_failure;
 	}
 
 	s->client = client;
@@ -395,15 +395,16 @@ static int sp2_probe(struct i2c_client *client,
 	i2c_set_clientdata(client, s);
 
 	ret = sp2_init(s);
-	if (ret)
-		goto err;
+	if (ret) {
+		kfree(s);
+		goto report_failure;
+	}
 
 	dev_info(&s->client->dev, "CIMaX SP2 successfully attached\n");
 	return 0;
-err:
-	dev_dbg(&client->dev, "init failed=%d\n", ret);
-	kfree(s);
 
+report_failure:
+	dev_dbg(&client->dev, "init failed=%d\n", ret);
 	return ret;
 }
 
-- 
2.14.1

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

* [PATCH 4/4] [media] sp2: Adjust three null pointer checks in sp2_exit()
  2017-09-01 19:41 [PATCH 0/4] [media] SP2: Adjustments for two function implementations SF Markus Elfring
                   ` (2 preceding siblings ...)
  2017-09-01 19:44 ` [PATCH 3/4] [media] sp2: Adjust a jump target " SF Markus Elfring
@ 2017-09-01 19:45 ` SF Markus Elfring
  3 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-09-01 19:45 UTC (permalink / raw)
  To: linux-media, Mauro Carvalho Chehab, Olli Salonen; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 1 Sep 2017 21:16:06 +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/dvb-frontends/sp2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/sp2.c b/drivers/media/dvb-frontends/sp2.c
index b2a7a54174ae..9bd71ba36d86 100644
--- a/drivers/media/dvb-frontends/sp2.c
+++ b/drivers/media/dvb-frontends/sp2.c
@@ -357,14 +357,14 @@ static int sp2_exit(struct i2c_client *client)
 
 	dev_dbg(&client->dev, "\n");
 
-	if (client == NULL)
+	if (!client)
 		return 0;
 
 	s = i2c_get_clientdata(client);
-	if (s == NULL)
+	if (!s)
 		return 0;
 
-	if (s->ca.data == NULL)
+	if (!s->ca.data)
 		return 0;
 
 	dvb_ca_en50221_release(&s->ca);
-- 
2.14.1

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

* Re: [PATCH 3/4] [media] sp2: Adjust a jump target in sp2_probe()
  2017-09-01 19:44 ` [PATCH 3/4] [media] sp2: Adjust a jump target " SF Markus Elfring
@ 2017-09-08 13:42   ` Hans Verkuil
  0 siblings, 0 replies; 6+ messages in thread
From: Hans Verkuil @ 2017-09-08 13:42 UTC (permalink / raw)
  To: SF Markus Elfring, linux-media, Mauro Carvalho Chehab, Olli Salonen
  Cc: LKML, kernel-janitors

Hi Markus,

On 09/01/17 21:44, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 1 Sep 2017 21:08:38 +0200
> 
> * Adjust a jump target so that a null pointer will not be passed to a call
>   of the function "kfree".
> 
> * Move this function call into an if branch.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/media/dvb-frontends/sp2.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/dvb-frontends/sp2.c b/drivers/media/dvb-frontends/sp2.c
> index dd556012ceb6..b2a7a54174ae 100644
> --- a/drivers/media/dvb-frontends/sp2.c
> +++ b/drivers/media/dvb-frontends/sp2.c
> @@ -384,7 +384,7 @@ static int sp2_probe(struct i2c_client *client,
>  	s = kzalloc(sizeof(*s), GFP_KERNEL);
>  	if (!s) {
>  		ret = -ENOMEM;
> -		goto err;
> +		goto report_failure;
>  	}
>  
>  	s->client = client;
> @@ -395,15 +395,16 @@ static int sp2_probe(struct i2c_client *client,
>  	i2c_set_clientdata(client, s);
>  
>  	ret = sp2_init(s);
> -	if (ret)
> -		goto err;
> +	if (ret) {
> +		kfree(s);
> +		goto report_failure;
> +	}
>  
>  	dev_info(&s->client->dev, "CIMaX SP2 successfully attached\n");
>  	return 0;
> -err:
> -	dev_dbg(&client->dev, "init failed=%d\n", ret);
> -	kfree(s);
>  
> +report_failure:
> +	dev_dbg(&client->dev, "init failed=%d\n", ret);
>  	return ret;
>  }
>  
> 

It's perfectly fine to call kfree() with a NULL pointer, and I don't think
that this patch makes the code more readable, so I'm dropping this patch.

Regards,

	Hans

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

end of thread, other threads:[~2017-09-08 13:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-01 19:41 [PATCH 0/4] [media] SP2: Adjustments for two function implementations SF Markus Elfring
2017-09-01 19:42 ` [PATCH 1/4] [media] sp2: Delete an error message for a failed memory allocation in sp2_probe() SF Markus Elfring
2017-09-01 19:43 ` [PATCH 2/4] [media] sp2: Improve a size determination " SF Markus Elfring
2017-09-01 19:44 ` [PATCH 3/4] [media] sp2: Adjust a jump target " SF Markus Elfring
2017-09-08 13:42   ` Hans Verkuil
2017-09-01 19:45 ` [PATCH 4/4] [media] sp2: Adjust three null pointer checks in sp2_exit() 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