[PATCH RESEND v8 05/10] nvmem: qcom-spmi-sdam: Migrate to devm_spmi_subdevice_alloc_and_add()
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Mon May 11 21:14:01 PDT 2026
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unconditional cast of `dev->parent` to `struct spmi_device` without type checking causes a kernel panic on malformed device topology.
--
commit aa83048e771ba8a6fcbb09d6d04cc6bb0abc5859
Author: AngeloGioacchino Del Regno <angelogioacchino.delregno at collabora.com>
nvmem: qcom-spmi-sdam: Migrate to devm_spmi_subdevice_alloc_and_add()
This commit migrates the SDAM driver to register its own SPMI sub-device
and initialize a dedicated regmap. This allows the regmap API to handle
the base address offsets automatically instead of manually adding the base
address to every read/write call.
> diff --git a/drivers/nvmem/qcom-spmi-sdam.c b/drivers/nvmem/qcom-spmi-sdam.c
> --- a/drivers/nvmem/qcom-spmi-sdam.c
> +++ b/drivers/nvmem/qcom-spmi-sdam.c
[ ... ]
> @@ -110,8 +110,17 @@ static int sdam_write(void *priv, unsigned int offset, void *val,
>
> static int sdam_probe(struct platform_device *pdev)
> {
[ ... ]
> @@ -119,19 +128,23 @@ static int sdam_probe(struct platform_device *pdev)
> if (!sdam)
> return -ENOMEM;
>
> - sdam->regmap = dev_get_regmap(pdev->dev.parent, NULL);
> - if (!sdam->regmap) {
> - dev_err(&pdev->dev, "Failed to get regmap handle\n");
> - return -ENXIO;
> - }
> + sparent = to_spmi_device(dev->parent);
> + sub_sdev = devm_spmi_subdevice_alloc_and_add(dev, sparent);
Could this lead to a kernel panic if the device is instantiated with a
malformed device tree?
If the device is placed at the root node where dev->parent is NULL, or under
a non-SPMI bus, to_spmi_device() will return an invalid spmi_device pointer
because it unconditionally casts dev->parent.
Passing this invalid pointer to devm_spmi_subdevice_alloc_and_add() would cause
a crash when it accesses the spmi_device fields.
The previous implementation safely handled this by calling dev_get_regmap(),
which returns NULL on an invalid parent and gracefully fails with -ENXIO.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260511100805.121432-1-angelogioacchino.delregno@collabora.com?part=5
More information about the linux-phy
mailing list