Linux LED subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ahmad Byagowi" <ahmadexp@gmail.com>
Cc: robh@kernel.org, lee@kernel.org, conor+dt@kernel.org,
	devicetree@vger.kernel.org, linux-leds@vger.kernel.org
Subject: Re: [RFC net-next 4/4] ptp: ocp: Add R4006 I2C peripheral topology
Date: Mon, 03 Aug 2026 15:46:42 +0000	[thread overview]
Message-ID: <20260803154642.8FB6F1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <25f255ac12a006059e0a442a5d750c31e9da1ae2.1785684064.git.ahmadexp@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] Repeated failures in firmware node registration inside `ptp_ocp_r4006_init_nodes` will leak `devm`-allocated memory because the function is called from a retriable workqueue.

Pre-existing issues:
- [High] Lockless access to `dev->driver` in the global I2C notifier parent tree traversal creates a TOCTOU race condition leading to a NULL pointer dereference.
--

--- Patch [4]: [RFC net-next 4/4] ptp: ocp: Add R4006 I2C peripheral topology ---
commit 6482a6be1fc3b33821906c9b60253b2b40290bb4
Author: Ahmad Byagowi <ahmadexp@gmail.com>

    ptp: ocp: Add R4006 I2C peripheral topology

This commit adds support for the R4006 I2C peripheral topology, detecting
the board via EEPROM and describing the topology with software nodes. It
registers standard I2C clients upon adapter appearance and handles I2C
bus notifications for dynamic population.

> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 35e911f1ad78c..b362a7c4dbb5f 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
[ ... ]
> +static int
> +ptp_ocp_r4006_init_nodes(struct ptp_ocp *bp)
> +{
[ ... ]
> +	r4006 = devm_kzalloc(dev, sizeof(*r4006), GFP_KERNEL);
> +	if (!r4006)
> +		return -ENOMEM;
> +
> +	r4006->mux_node.name =
> +		devm_kasprintf(dev, GFP_KERNEL, "ocp%d-r4006-mux", bp->id);
[ ... ]
> +	ret = software_node_register_node_group(r4006->node_group);
> +	if (ret)
> +		return dev_err_probe(dev, ret,
> +				     "failed to register R4006 firmware nodes\n");
> +
> +	r4006->registered = true;
> +	bp->r4006 = r4006;
> +	return 0;
> +}

[Severity: Medium]
Will this leak devm-allocated memory on failure? 

Since ptp_ocp_r4006_init_nodes() is called from ptp_ocp_i2c_work() (which
can be dynamically re-triggered by I2C bus notifications), any deterministic
failure in software_node_register_node_group() will cause an early return
without freeing the memory allocated via devm_kzalloc() and
devm_kasprintf() earlier in this function. Could this repeatedly leak
memory on the device's devres list with each worker execution?

[ ... ]
> +static struct ptp_ocp *
> +ptp_ocp_i2c_parent(struct device *child)
> +{
> +	struct device *dev = child;
> +
> +	while ((dev = dev->parent))
> +		if (dev->driver && !strcmp(dev->driver->name, KBUILD_MODNAME))
> +			return dev_get_drvdata(dev);
> +
> +	return NULL;
> +}

[Severity: High]
This is a pre-existing issue, but does this lockless check of dev->driver
risk a NULL pointer dereference?

If a parent device is concurrently unbinding while this global I2C notifier
is traversing the tree, the driver core clears its dev->driver pointer.
If dev->driver is evaluated as non-NULL but becomes NULL right before
strcmp() accesses dev->driver->name, it could crash the kernel.

Should we be taking the device_lock() before evaluating dev->driver?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1785684064.git.ahmadexp@gmail.com?part=4

      reply	other threads:[~2026-08-03 15:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02 15:46 [RFC net-next 0/4] ptp: ocp: Add R4006 I2C peripheral support Ahmad Byagowi
2026-08-02 15:46 ` [RFC net-next 1/4] dt-bindings: leds: Add IS32FL3207 controller Ahmad Byagowi
2026-08-03 15:46   ` sashiko-bot
2026-08-02 15:46 ` [RFC net-next 2/4] leds: rgb: Add IS32FL3207 controller driver Ahmad Byagowi
2026-08-03 15:46   ` sashiko-bot
2026-08-02 15:46 ` [RFC net-next 3/4] i2c: mux: Propagate software nodes to channel adapters Ahmad Byagowi
2026-08-03 15:46   ` sashiko-bot
2026-08-02 15:46 ` [RFC net-next 4/4] ptp: ocp: Add R4006 I2C peripheral topology Ahmad Byagowi
2026-08-03 15:46   ` sashiko-bot [this message]

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=20260803154642.8FB6F1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ahmadexp@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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