linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] ASoC: simple-card: Fine-tuning for three function implementations
@ 2017-04-26 13:02 SF Markus Elfring
  2017-04-26 13:04 ` [PATCH 1/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_parse_aux_devs() SF Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-04-26 13:02 UTC (permalink / raw)
  To: alsa-devel, Jaroslav Kysela, Kuninori Morimoto, Liam Girdwood,
	Mark Brown, Nikita Yushchenko, Takashi Iwai
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 26 Apr 2017 14:54:32 +0200

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

Markus Elfring (3):
  Use devm_kcalloc() in asoc_simple_card_parse_aux_devs()
  Use devm_kcalloc() in asoc_simple_card_probe()
  SCU: Use devm_kcalloc() in asoc_simple_card_probe()

 sound/soc/generic/simple-card.c     | 8 ++++----
 sound/soc/generic/simple-scu-card.c | 5 ++---
 2 files changed, 6 insertions(+), 7 deletions(-)

-- 
2.12.2

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

* [PATCH 1/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_parse_aux_devs()
  2017-04-26 13:02 [PATCH 0/3] ASoC: simple-card: Fine-tuning for three function implementations SF Markus Elfring
@ 2017-04-26 13:04 ` SF Markus Elfring
  2017-04-28  8:57   ` [alsa-devel] " Alexandre Belloni
  2017-04-26 13:05 ` [PATCH 2/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_probe() SF Markus Elfring
  2017-04-26 13:06 ` [PATCH 3/3] ASoC: simple-scu-card: " SF Markus Elfring
  2 siblings, 1 reply; 6+ messages in thread
From: SF Markus Elfring @ 2017-04-26 13:04 UTC (permalink / raw)
  To: alsa-devel, Jaroslav Kysela, Kuninori Morimoto, Liam Girdwood,
	Mark Brown, Nikita Yushchenko, Takashi Iwai
  Cc: LKML, kernel-janitors

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

A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "devm_kcalloc".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 sound/soc/generic/simple-card.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 2c9dedab5184..b59d51374b89 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -334,8 +334,8 @@ static int asoc_simple_card_parse_aux_devs(struct device_node *node,
 	if (n <= 0)
 		return -EINVAL;
 
-	card->aux_dev = devm_kzalloc(dev,
-			n * sizeof(*card->aux_dev), GFP_KERNEL);
+	card->aux_dev = devm_kcalloc(dev, n, sizeof(*card->aux_dev),
+				     GFP_KERNEL);
 	if (!card->aux_dev)
 		return -ENOMEM;
 
-- 
2.12.2

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

* [PATCH 2/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_probe()
  2017-04-26 13:02 [PATCH 0/3] ASoC: simple-card: Fine-tuning for three function implementations SF Markus Elfring
  2017-04-26 13:04 ` [PATCH 1/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_parse_aux_devs() SF Markus Elfring
@ 2017-04-26 13:05 ` SF Markus Elfring
  2017-04-26 13:06 ` [PATCH 3/3] ASoC: simple-scu-card: " SF Markus Elfring
  2 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-04-26 13:05 UTC (permalink / raw)
  To: alsa-devel, Jaroslav Kysela, Kuninori Morimoto, Liam Girdwood,
	Mark Brown, Nikita Yushchenko, Takashi Iwai
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 26 Apr 2017 14:32:12 +0200

Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "devm_kcalloc".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 sound/soc/generic/simple-card.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index b59d51374b89..55586326fde8 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -437,8 +437,8 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
-	dai_props = devm_kzalloc(dev, sizeof(*dai_props) * num, GFP_KERNEL);
-	dai_link  = devm_kzalloc(dev, sizeof(*dai_link)  * num, GFP_KERNEL);
+	dai_props = devm_kcalloc(dev, num, sizeof(*dai_props), GFP_KERNEL);
+	dai_link  = devm_kcalloc(dev, num, sizeof(*dai_link), GFP_KERNEL);
 	if (!dai_props || !dai_link)
 		return -ENOMEM;
 
-- 
2.12.2

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

* [PATCH 3/3] ASoC: simple-scu-card: Use devm_kcalloc() in asoc_simple_card_probe()
  2017-04-26 13:02 [PATCH 0/3] ASoC: simple-card: Fine-tuning for three function implementations SF Markus Elfring
  2017-04-26 13:04 ` [PATCH 1/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_parse_aux_devs() SF Markus Elfring
  2017-04-26 13:05 ` [PATCH 2/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_probe() SF Markus Elfring
@ 2017-04-26 13:06 ` SF Markus Elfring
  2 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-04-26 13:06 UTC (permalink / raw)
  To: alsa-devel, Jaroslav Kysela, Kuninori Morimoto, Liam Girdwood,
	Mark Brown, Nikita Yushchenko, Takashi Iwai
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 26 Apr 2017 14:40:40 +0200

Multiplications for the size determination of memory allocations
indicated that array data structures should be processed.
Thus use the corresponding function "devm_kcalloc".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 sound/soc/generic/simple-scu-card.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/sound/soc/generic/simple-scu-card.c b/sound/soc/generic/simple-scu-card.c
index dcbcab230d1b..530a7aa387c5 100644
--- a/sound/soc/generic/simple-scu-card.c
+++ b/sound/soc/generic/simple-scu-card.c
@@ -270,9 +270,8 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	num = of_get_child_count(np);
-
-	dai_props = devm_kzalloc(dev, sizeof(*dai_props) * num, GFP_KERNEL);
-	dai_link  = devm_kzalloc(dev, sizeof(*dai_link)  * num, GFP_KERNEL);
+	dai_props = devm_kcalloc(dev, num, sizeof(*dai_props), GFP_KERNEL);
+	dai_link  = devm_kcalloc(dev, num, sizeof(*dai_link), GFP_KERNEL);
 	if (!dai_props || !dai_link)
 		return -ENOMEM;
 
-- 
2.12.2

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

* Re: [alsa-devel] [PATCH 1/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_parse_aux_devs()
  2017-04-26 13:04 ` [PATCH 1/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_parse_aux_devs() SF Markus Elfring
@ 2017-04-28  8:57   ` Alexandre Belloni
  2017-04-28 10:48     ` SF Markus Elfring
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2017-04-28  8:57 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: alsa-devel, Jaroslav Kysela, Kuninori Morimoto, Liam Girdwood,
	Mark Brown, Nikita Yushchenko, Takashi Iwai, kernel-janitors,
	LKML

Hi,

On 26/04/2017 at 15:04:11 +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 26 Apr 2017 14:21:51 +0200
> 
> A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus use the corresponding function "devm_kcalloc".
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  sound/soc/generic/simple-card.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
> index 2c9dedab5184..b59d51374b89 100644
> --- a/sound/soc/generic/simple-card.c
> +++ b/sound/soc/generic/simple-card.c
> @@ -334,8 +334,8 @@ static int asoc_simple_card_parse_aux_devs(struct device_node *node,
>  	if (n <= 0)
>  		return -EINVAL;
>  
> -	card->aux_dev = devm_kzalloc(dev,
> -			n * sizeof(*card->aux_dev), GFP_KERNEL);
> +	card->aux_dev = devm_kcalloc(dev, n, sizeof(*card->aux_dev),
> +				     GFP_KERNEL);

Do you realize that this change has absolutely no value and just makes
the code slower (one more test in the allocation path)?

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* Re: [alsa-devel] [PATCH 1/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_parse_aux_devs()
  2017-04-28  8:57   ` [alsa-devel] " Alexandre Belloni
@ 2017-04-28 10:48     ` SF Markus Elfring
  0 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-04-28 10:48 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: alsa-devel, Jaroslav Kysela, Kuninori Morimoto, Liam Girdwood,
	Mark Brown, Nikita Yushchenko, Takashi Iwai, kernel-janitors,
	LKML

>> @@ -334,8 +334,8 @@ static int asoc_simple_card_parse_aux_devs(struct device_node *node,
>>  	if (n <= 0)
>>  		return -EINVAL;
>>  
>> -	card->aux_dev = devm_kzalloc(dev,
>> -			n * sizeof(*card->aux_dev), GFP_KERNEL);
>> +	card->aux_dev = devm_kcalloc(dev, n, sizeof(*card->aux_dev),
>> +				     GFP_KERNEL);
> 
> Do you realize that this change has absolutely no value

We can have different software development opinions about such a source code adjustment.
Does it improve the indentation for the parameters which are passed to this function call?


> and just makes the code slower (one more test in the allocation path)?

Do we stumble on a target conflict for the shown implementation detail?

Does the previous size calculation contain the general possibility for
an integer overflow?
https://cwe.mitre.org/data/definitions/190.html

The value for the variable “len” (and also “n”) might be small enough so that
the computed value will usually not exceed the data type limit in this use case.

Regards,
Markus

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

end of thread, other threads:[~2017-04-28 10:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-26 13:02 [PATCH 0/3] ASoC: simple-card: Fine-tuning for three function implementations SF Markus Elfring
2017-04-26 13:04 ` [PATCH 1/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_parse_aux_devs() SF Markus Elfring
2017-04-28  8:57   ` [alsa-devel] " Alexandre Belloni
2017-04-28 10:48     ` SF Markus Elfring
2017-04-26 13:05 ` [PATCH 2/3] ASoC: simple-card: Use devm_kcalloc() in asoc_simple_card_probe() SF Markus Elfring
2017-04-26 13:06 ` [PATCH 3/3] ASoC: simple-scu-card: " 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;
as well as URLs for NNTP newsgroup(s).