Skip to contentSkip to conversation

ASoC: audio-graph-card: test memory allocation

PATCH In review Pierre-Louis Bossart 2 participants 6 messages Mar 9, 2019 – Mar 13, 2019

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

PATCH 1/2 ASoC: audio-graph-card: test memory allocation

devm_kcalloc() return value needs to be checked.

Fixes 1e4771a62fd7a ('ASoC: audio-graph-card: add link_info')
---
 sound/soc/generic/audio-graph-card.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/generic/audio-graph-card.c +1 -1
index bb12351330e8..ba65b48c10a7 100644
@@ -670,7 +670,7 @@ static int graph_probe(struct platform_device *pdev)
 	dai_link  = devm_kcalloc(dev, li.link, sizeof(*dai_link),  GFP_KERNEL);
 	dais      = devm_kcalloc(dev, li.dais, sizeof(*dais),      GFP_KERNEL);
 	cconf     = devm_kcalloc(dev, li.conf, sizeof(*cconf),     GFP_KERNEL);
-	if (!dai_props || !dai_link || !dais)
+	if (!dai_props || !dai_link || !dais || !cconf)
 		return -ENOMEM;
 
 	/*
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 ASoC: simple-card: test memory allocation

devm_kcalloc() return value needs to be tested

Fixes 17029e494edc6 ('ASoC: simple-card: add link_info')
---
 sound/soc/generic/simple-card.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/generic/simple-card.c +1 -1
index 08df261024cf..bed4fe5721a2 100644
@@ -715,7 +715,7 @@ static int simple_probe(struct platform_device *pdev)
 	dai_link  = devm_kcalloc(dev, li.link, sizeof(*dai_link),  GFP_KERNEL);
 	dais      = devm_kcalloc(dev, li.dais, sizeof(*dais),      GFP_KERNEL);
 	cconf     = devm_kcalloc(dev, li.conf, sizeof(*cconf),     GFP_KERNEL);
-	if (!dai_props || !dai_link || !dais)
+	if (!dai_props || !dai_link || !dais || !cconf)
 		return -ENOMEM;
 
 	/*
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 2/2] ASoC: simple-card: test memory allocation

Hi Pierre-Louis

Thank you for your patch.

Quoted 13 lines

devm_kcalloc() return value needs to be tested

Fixes 17029e494edc6 ('ASoC: simple-card: add link_info')
---
 sound/soc/generic/simple-card.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/generic/simple-card.c +0 -0
index 08df261024cf..bed4fe5721a2 100644

sound/soc/generic/simple-card.c static int simple_probe(struct platform_device *pdev) · line 719

Quoted 6 lines
sound/soc/generic/simple-card.c +1 -1
@@ -715,7 +715,7 @@ static int simple_probe(struct platform_device *pdev)
 	dai_link  = devm_kcalloc(dev, li.link, sizeof(*dai_link),  GFP_KERNEL);
 	dais      = devm_kcalloc(dev, li.dais, sizeof(*dais),      GFP_KERNEL);
 	cconf     = devm_kcalloc(dev, li.conf, sizeof(*cconf),     GFP_KERNEL);
-	if (!dai_props || !dai_link || !dais)
+	if (!dai_props || !dai_link || !dais || !cconf)
 		return -ENOMEM;

It isn't mentioned on code, but, "li.conf" will be 0 if it was not DPCM case. This means cconf NULL might be happen.

Best regards
---
Kuninori Morimoto

#3 lore raw

Re: [PATCH 2/2] ASoC: simple-card: test memory allocation

Quoted 13 lines · Kuninori Morimoto

Hi Pierre-Louis

Thank you for your patch.

Quoted 8 lines

devm_kcalloc() return value needs to be tested

Fixes 17029e494edc6 ('ASoC: simple-card: add link_info')
---
  sound/soc/generic/simple-card.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

sound/soc/generic/simple-card.c static int simple_probe(struct platform_device *pdev) · line 719

Quoted 11 lines
sound/soc/generic/simple-card.c +1 -1
index 08df261024cf..bed4fe5721a2 100644
@@ -715,7 +715,7 @@ static int simple_probe(struct platform_device *pdev)
  	dai_link  = devm_kcalloc(dev, li.link, sizeof(*dai_link),  GFP_KERNEL);
  	dais      = devm_kcalloc(dev, li.dais, sizeof(*dais),      GFP_KERNEL);
  	cconf     = devm_kcalloc(dev, li.conf, sizeof(*cconf),     GFP_KERNEL);
-	if (!dai_props || !dai_link || !dais)
+	if (!dai_props || !dai_link || !dais || !cconf)
  		return -ENOMEM;

It isn't mentioned on code, but, "li.conf" will be 0 if it was not DPCM case. This means cconf NULL might be happen.

Humm, then don't call devm_kcalloc with a zero argument...
And if you keep this code, if li.conf is not zero you still have a risk of memory allocation failure. the test should be

+ if (!dai_props || !dai_link || !dais || (!cconf && li.conf))

#4 lore raw

Re: [PATCH 2/2] ASoC: simple-card: test memory allocation

Hi Pierre

Quoted 20 lines
Quoted 6 lines
Quoted 6 lines
sound/soc/generic/simple-card.c +0 -0
index 08df261024cf..bed4fe5721a2 100644
@@ -715,7 +715,7 @@ static int simple_probe(struct platform_device *pdev)
  	dai_link  = devm_kcalloc(dev, li.link, sizeof(*dai_link),  GFP_KERNEL);
Quoted 8 lines

sound/soc/generic/simple-card.c static int simple_probe(struct platform_device *pdev) · line 719

Quoted 5 lines
sound/soc/generic/simple-card.c +1 -1
  	dais      = devm_kcalloc(dev, li.dais, sizeof(*dais),      GFP_KERNEL);
  	cconf     = devm_kcalloc(dev, li.conf, sizeof(*cconf),     GFP_KERNEL);
-	if (!dai_props || !dai_link || !dais)
+	if (!dai_props || !dai_link || !dais || !cconf)
  		return -ENOMEM;

It isn't mentioned on code, but, "li.conf" will be 0 if it was not DPCM case. This means cconf NULL might be happen.

Humm, then don't call devm_kcalloc with a zero argument... And if you keep this code, if li.conf is not zero you still have a risk of memory allocation failure. the test should be

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (!dai_props || !dai_link || !dais || (!cconf && li.conf))

Yes, indeed.
Thank you for your feedback

Actually, I have few cleanup patches for simple-card/audio-graph for v5.2, then, your patch and it will be conflict.
If you are OK, I can merge your patch on my patch-set with your Signed-off-by (or Reported-by).
Is OK for you ? I will post it when -rc1 was released from Linus.

Best regards
---
Kuninori Morimoto

#5 lore raw

Re: [PATCH 2/2] ASoC: simple-card: test memory allocation

Quoted 19 lines
Quoted 14 lines
Quoted 8 lines

sound/soc/generic/simple-card.c static int simple_probe(struct platform_device *pdev) · line 719

Quoted 5 lines
   	cconf     = devm_kcalloc(dev, li.conf, sizeof(*cconf),     GFP_KERNEL);
sound/soc/generic/simple-card.c +1 -1
-	if (!dai_props || !dai_link || !dais)
+	if (!dai_props || !dai_link || !dais || !cconf)
   		return -ENOMEM;

It isn't mentioned on code, but, "li.conf" will be 0 if it was not DPCM case. This means cconf NULL might be happen.

Humm, then don't call devm_kcalloc with a zero argument... And if you keep this code, if li.conf is not zero you still have a risk of memory allocation failure. the test should be

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (!dai_props || !dai_link || !dais || (!cconf && li.conf))

Yes, indeed.
Thank you for your feedback

Quoted 5 lines

Actually, I have few cleanup patches for simple-card/audio-graph for v5.2, then, your patch and it will be conflict.
If you are OK, I can merge your patch on my patch-set with your Signed-off-by (or Reported-by).
Is OK for you ? I will post it when -rc1 was released from Linus.

yes, that's fine. Thanks!