All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zijie Zhao <zzjas98@gmail.com>
To: srinivas.kandagatla@linaro.org, bgoswami@quicinc.com,
	lgirdwood@gmail.com, broonie@kernel.org
Cc: alsa-devel@alsa-project.org, chenyuan0y@gmail.com
Subject: [sound/soc/qcom] Question about memory allocation in asoc_qcom_lpass_cpu_platform_probe
Date: Wed, 20 Mar 2024 15:56:10 -0500	[thread overview]
Message-ID: <baf5dfd4-0ec0-47af-8c27-ca71f242244d@gmail.com> (raw)

Dear QCOM AUDIO maintainers,

We encountered an usual usage of devm_kzalloc while performing a 
static analysis for kernel code.

https://elixir.bootlin.com/linux/v6.8/source/sound/soc/qcom/lpass-cpu.c#L1239
```
int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev)
{
	...

	drvdata = devm_kzalloc(dev, sizeof(struct lpass_data), GFP_KERNEL);
	if (!drvdata)
		return -ENOMEM;
	...

	/* Allocation for i2sctl regmap fields */
	drvdata->i2sctl = devm_kzalloc(&pdev->dev, sizeof(struct lpaif_i2sctl),
					GFP_KERNEL);

	/* Initialize bitfields for dai I2SCTL register */
	ret = lpass_cpu_init_i2sctl_bitfields(dev, drvdata->i2sctl,
						drvdata->lpaif_map);
	if (ret) {
		dev_err(dev, "error init i2sctl field: %d\n", ret);
		return ret;
	}
	...
}
```

```
static int lpass_cpu_init_i2sctl_bitfields(struct device *dev,
			struct lpaif_i2sctl *i2sctl, struct regmap *map)
{
	struct lpass_data *drvdata = dev_get_drvdata(dev);
	const struct lpass_variant *v = drvdata->variant;

	i2sctl->loopback = devm_regmap_field_alloc(dev, map, v->loopback);
	...
}
```

Here devm_kzalloc might return NULL for drvdata->i2sctl if 
out-of-memory. Then i2sctl->loopback will cause segfault since i2sctl 
is never checked against NULL. Would a NULL check needed here? Like 
the drvdata above.

Please let us know if we missed any key information or assumption! We 
appreciate your time!

Best,
Zijie



                 reply	other threads:[~2024-03-24  9:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=baf5dfd4-0ec0-47af-8c27-ca71f242244d@gmail.com \
    --to=zzjas98@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=bgoswami@quicinc.com \
    --cc=broonie@kernel.org \
    --cc=chenyuan0y@gmail.com \
    --cc=lgirdwood@gmail.com \
    --cc=srinivas.kandagatla@linaro.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.