Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "AngeloGioacchino Del Regno" <angelogioacchino.delregno@collabora.com>
Cc: vkoul@kernel.org, olteanv@gmail.com, neil.armstrong@linaro.org,
	linux-phy@lists.infradead.org
Subject: Re: [PATCH RESEND v8 04/10] spmi: Implement spmi_subdevice_alloc_and_add() and devm variant
Date: Tue, 12 May 2026 01:57:59 +0000	[thread overview]
Message-ID: <20260512015800.05451C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260511100805.121432-5-angelogioacchino.delregno@collabora.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Commit message claims to add spmi_subdevice_put_and_remove() but it is missing
- [Medium] Missing reference count on SPMI controller causes potential Use-After-Free (UAF)
- [Low] Format string type mismatch for controller number in device name
--

commit 481d7c4794f3b580a0e0d422d1a5cc8b6a3b1466
Author: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

spmi: Implement spmi_subdevice_alloc_and_add() and devm variant

This commit introduces spmi_subdevice_alloc_and_add() and a devres variant
to manage complex sub-devices on the SPMI bus. It allows PMIC components
sharing a single SID to be represented as sub-devices. The new exports
are placed in the "SPMI" namespace.

> Add new functions aimed at managing sub-devices of a SPMI device
> spmi_subdevice_alloc_and_add() and a spmi_subdevice_put_and_remove()

This isn't a bug, but the commit message mentions
spmi_subdevice_put_and_remove(), while the implemented function is
actually named spmi_subdevice_remove(). Should the commit message be
updated to match the code?

> diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c
> index 91a40ea8031ad..cdf3e99194c4c 100644
> --- a/drivers/spmi/spmi.c
> +++ b/drivers/spmi/spmi.c

[ ... ]

> +struct spmi_subdevice *spmi_subdevice_alloc_and_add(struct spmi_device *sparent)
> +{
> +	struct spmi_subdevice *sub_sdev;
> +	struct spmi_device *sdev;
> +	int ret;
> +
> +	sub_sdev = kzalloc(sizeof(*sub_sdev), GFP_KERNEL);
> +	if (!sub_sdev)
> +		return ERR_PTR(-ENOMEM);
> +
> +	sdev = &sub_sdev->sdev;
> +	sdev->ctrl = sparent->ctrl;

Does this missing reference count on the controller introduce a potential
use-after-free regression?

If the parent PMIC device is removed and drops its reference to the controller,
could the subdevice outlive it and still hold a dangling pointer to
sdev->ctrl? Should this initialization take a reference via
get_device(&sdev->ctrl->dev)?

> +	sdev->usid = sparent->usid;
> +
> +	ret = ida_alloc(&spmi_subdevice_ida, GFP_KERNEL);
> +	if (ret < 0) {
> +		kfree(sub_sdev);
> +		return ERR_PTR(ret);
> +	}
> +	sub_sdev->devid = ret;
> +
> +	device_initialize(&sdev->dev);
> +	sdev->dev.parent = &sparent->dev;
> +	sdev->dev.bus = &spmi_bus_type;
> +	sdev->dev.type = &spmi_subdev_type;
> +
> +	ret = dev_set_name(&sdev->dev, "%d-%02x.%d.auto",
> +			   sdev->ctrl->nr, sdev->usid, sub_sdev->devid);

This isn't a bug, but could the format specifier for sdev->ctrl->nr
cause a type mismatch warning? Looking at struct spmi_controller, nr is
an unsigned int, so should this use %u instead of %d?

> +	if (ret)
> +		goto err_put_dev;
> +
> +	ret = device_add(&sdev->dev);
> +	if (ret) {
> +		dev_err(&sdev->dev, "Can't add device, status %pe\n", ERR_PTR(ret));
> +		goto err_put_dev;
> +	}
> +
> +	return sub_sdev;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260511100805.121432-1-angelogioacchino.delregno@collabora.com?part=4

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  reply	other threads:[~2026-05-12  1:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 10:07 [PATCH RESEND v8 00/10] SPMI: Implement sub-devices and migrate drivers AngeloGioacchino Del Regno
2026-05-11 10:07 ` [PATCH RESEND v8 01/10] spmi: Remove redundant dev_name() print in spmi_device_add() AngeloGioacchino Del Regno
2026-05-11 10:07 ` [PATCH RESEND v8 02/10] spmi: Print error status with %pe format AngeloGioacchino Del Regno
2026-05-11 10:07 ` [PATCH RESEND v8 03/10] spmi: Remove unneeded goto in spmi_device_add() error path AngeloGioacchino Del Regno
2026-05-11 10:07 ` [PATCH RESEND v8 04/10] spmi: Implement spmi_subdevice_alloc_and_add() and devm variant AngeloGioacchino Del Regno
2026-05-12  1:57   ` sashiko-bot [this message]
2026-05-11 10:08 ` [PATCH RESEND v8 05/10] nvmem: qcom-spmi-sdam: Migrate to devm_spmi_subdevice_alloc_and_add() AngeloGioacchino Del Regno
2026-05-12  4:14   ` sashiko-bot
2026-05-11 10:08 ` [PATCH RESEND v8 06/10] power: reset: qcom-pon: " AngeloGioacchino Del Regno
2026-05-11 10:08 ` [PATCH RESEND v8 07/10] phy: qualcomm: eusb2-repeater: " AngeloGioacchino Del Regno
2026-05-12  6:10   ` sashiko-bot
2026-05-11 10:08 ` [PATCH RESEND v8 08/10] misc: qcom-coincell: " AngeloGioacchino Del Regno
2026-05-11 10:08 ` [PATCH RESEND v8 09/10] iio: adc: qcom-spmi-iadc: " AngeloGioacchino Del Regno
2026-05-11 10:08 ` [PATCH RESEND v8 10/10] iio: adc: qcom-spmi-iadc: Remove regmap R/W wrapper functions AngeloGioacchino Del Regno
2026-05-11 13:17 ` [PATCH RESEND v8 00/10] SPMI: Implement sub-devices and migrate drivers Jonathan Cameron

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=20260512015800.05451C2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=sashiko@lists.linux.dev \
    --cc=vkoul@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox