mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cezary Rojewski <cezary.rojewski@intel.com>
To: <phucduc.bui@gmail.com>
Cc: <linux-sound@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	"Takashi Iwai" <tiwai@suse.com>, Mark Brown <broonie@kernel.org>,
	Jaroslav Kysela <perex@perex.cz>,
	Liam Girdwood <lgirdwood@gmail.com>
Subject: Re: [PATCH] ASoC: core: add snd_BUG_ON() check in devm_snd_soc_register_card()
Date: Mon, 3 Aug 2026 12:50:10 +0200	[thread overview]
Message-ID: <f7c2eafb-84c0-4c4d-a359-8c80ed989c24@intel.com> (raw)
In-Reply-To: <20260803102739.55569-1-phucduc.bui@gmail.com>

On 8/3/2026 12:27 PM, phucduc.bui@gmail.com wrote:
> From: bui duc phuc <phucduc.bui@gmail.com>
> 
> card is dereferenced immediately, so passing NULL results in a NULL
> pointer dereference. A NULL dev is silently accepted, defeating the
> documented automatic-unregistration semantics of this devm variant.
> 
> Add snd_BUG_ON() checks on both arguments to catch API misuse early.
> 
> Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
> ---
>   sound/soc/soc-devres.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/sound/soc/soc-devres.c b/sound/soc/soc-devres.c
> index 718165ba84ac..3e946196022a 100644
> --- a/sound/soc/soc-devres.c
> +++ b/sound/soc/soc-devres.c
> @@ -59,6 +59,9 @@ EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
>    */
>   int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
>   {
> +	if (snd_BUG_ON(!dev || !card))
> +		return -EINVAL;
> +
>   	card->devres_dev = dev;
>   	return snd_soc_register_card(card);
>   }

Not sure whether we need such defenses. If we are to follow such 
approach, many ASoC-driver APIs require BUG_ON/WARN_ON() update.

register_card() is typically called as a last step, once 'card' is 
already allocated. At the same time, the register_card() typically 
occurs in probe() context of given device so we're always certain the 
'dev' is not NULL.

TLDR: this is not a UAPI, (obvious) NULL-checks can be skipped.

  reply	other threads:[~2026-08-03 10:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 10:27 phucduc.bui
2026-08-03 10:50 ` Cezary Rojewski [this message]
2026-08-03 11:58   ` Bui Duc Phuc
2026-08-03 20:42     ` Cezary Rojewski
2026-08-04  3:19       ` Bui Duc Phuc
2026-08-04 11:27         ` Cezary Rojewski
2026-08-04 14:02           ` Bui Duc Phuc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f7c2eafb-84c0-4c4d-a359-8c80ed989c24@intel.com \
    --to=cezary.rojewski@intel.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=phucduc.bui@gmail.com \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®