Skip to contentSkip to conversation

ASoC: soc-core: add snd_soc_rtdcom_xxx()

bug report Superseded Dan Carpenter 3 participants 6 messages Sep 11, 2017 – Sep 14, 2017

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

Hello Kuninori Morimoto,

This is a semi-automatic email about new static checker warnings.

The patch a0ac44115223: "ASoC: soc-core: add snd_soc_rtdcom_xxx()" from Aug 8, 2017, leads to the following Smatch complaint:

sound/soc/soc-core.c:644 soc_free_pcm_runtime()
error: we previously assumed 'rtd' could be null (see line 642)

sound/soc/soc-core.c
641 {
642 if (rtd && rtd->codec_dais)

                    ^^^

Check for NULL.

643 kfree(rtd->codec_dais);

   644		snd_soc_rtdcom_del_all(rtd);
                                       ^^^

The check adds a new unchecked dereference inside the function. It's weird that we call INIT_LIST_HEAD(&rtd->component_list), btw. Don't we need to free the elements in the list?

   645		kfree(rtd);
   646	}

regards,
dan carpenter

#1 lore raw

Hi Dan

Quoted 7 lines

sound/soc/soc-core.c:644 soc_free_pcm_runtime()
error: we previously assumed 'rtd' could be null (see line 642)

sound/soc/soc-core.c

   641	{
   642		if (rtd && rtd->codec_dais)
                    ^^^
Quoted 8 lines

Check for NULL.

   643			kfree(rtd->codec_dais);
   644		snd_soc_rtdcom_del_all(rtd);
                                       ^^^

The check adds a new unchecked dereference inside the function. It's weird that we call INIT_LIST_HEAD(&rtd->component_list), btw. Don't we need to free the elements in the list?

Yes, indeed.
Thank you for your report.
I will fix it soon

Best regards
---
Kuninori Morimoto

#2 lore raw

PATCH 1/1 ASoC: soc-core: remove rtd NULL check from soc_free_pcm_runtime()

In reply to Dan Carpenter

From: Kuninori Morimoto <[email protected]>

static soc_free_pcm_runtime() is never called with rtd==NULL. This patch removes unnecessary rtd == NULL check from soc_free_pcm_runtime().
Otherwise it logically inconsistent.

---
 sound/soc/soc-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/soc-core.c +1 -1
index 19f6d07..ee29d7c 100644
@@ -407,7 +407,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 
 static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 {
-	if (rtd && rtd->codec_dais)
+	if (rtd->codec_dais)
 		kfree(rtd->codec_dais);
 	snd_soc_rtdcom_del_all(rtd);
 	kfree(rtd);
Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH] ASoC: soc-core: remove rtd NULL check from soc_free_pcm_runtime()

coccinelle warnings: (new ones prefixed by >>)

Hi Kuninori,

[auto build test WARNING on asoc/for-next]
[also build test WARNING on v4.13 next-20170913]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Kuninori-Morimoto/ASoC-soc-core-remove-rtd-NULL-check-from-soc_free_pcm_runtime/20170914-072344
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

coccinelle warnings: (new ones prefixed by >>)

>> sound/soc/soc-core.c:643:2-7: WARNING: NULL check before freeing functions like kfree, debugfs_remove, debugfs_remove_recursive or usb_free_urb is not needed. Maybe consider reorganizing relevant code to avoid passing NULL values.

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#4 lore raw

[PATCH] ASoC: soc-core: fix ifnullfree.cocci warnings

In reply to Kuninori Morimoto
sound/soc/soc-core.c:643:2-7: WARNING: NULL check before freeing functions like kfree, debugfs_remove, debugfs_remove_recursive or usb_free_urb is not needed. Maybe consider reorganizing relevant…

sound/soc/soc-core.c:643:2-7: WARNING: NULL check before freeing functions like kfree, debugfs_remove, debugfs_remove_recursive or usb_free_urb is not needed. Maybe consider reorganizing relevant code to avoid passing NULL values.

NULL check before some freeing functions is not needed.

Based on checkpatch warning
"kfree(NULL) is safe this check is probably not required" and kfreeaddr.cocci by Julia Lawall.

Generated by: scripts/coccinelle/free/ifnullfree.cocci

Fixes 7e74acb4fc31 ("ASoC: soc-core: remove rtd NULL check from soc_free_pcm_runtime()")
CC Kuninori Morimoto <[email protected]>

---

 soc-core.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/soc-core.c +1 -2
@@ -639,8 +639,7 @@ static struct snd_soc_pcm_runtime *soc_n
 
 static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 {
-	if (rtd->codec_dais)
-		kfree(rtd->codec_dais);
+	kfree(rtd->codec_dais);
 	snd_soc_rtdcom_del_all(rtd);
 	kfree(rtd);
 }
#5 lore raw

Re: [PATCH] ASoC: soc-core: fix ifnullfree.cocci warnings

Hi

Quoted 8 lines

sound/soc/soc-core.c:643:2-7: WARNING: NULL check before freeing functions like kfree, debugfs_remove, debugfs_remove_recursive or usb_free_urb is not needed. Maybe consider reorganizing relevant code to avoid passing NULL values.

NULL check before some freeing functions is not needed.

Based on checkpatch warning
"kfree(NULL) is safe this check is probably not required" and kfreeaddr.cocci by Julia Lawall.

Quoted 6 lines

Generated by: scripts/coccinelle/free/ifnullfree.cocci

Fixes 7e74acb4fc31 ("ASoC: soc-core: remove rtd NULL check from soc_free_pcm_runtime()")
CC Kuninori Morimoto <[email protected]>

---