All of lore.kernel.org
 help / color / mirror / Atom feed
* [sound/soc/qcom] Question about memory allocation in asoc_qcom_lpass_cpu_platform_probe
@ 2024-03-20 20:56 Zijie Zhao
  0 siblings, 0 replies; only message in thread
From: Zijie Zhao @ 2024-03-20 20:56 UTC (permalink / raw)
  To: srinivas.kandagatla, bgoswami, lgirdwood, broonie; +Cc: alsa-devel, chenyuan0y

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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-24  9:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-20 20:56 [sound/soc/qcom] Question about memory allocation in asoc_qcom_lpass_cpu_platform_probe Zijie Zhao

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.