Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: Frank Li <Frank.Li@nxp.com>
To: gregkh@linuxfoundation.org, rafael@kernel.org,
	hanguidong02@gmail.com, ysato@users.sourceforge.jp,
	dalias@libc.org, glaubitz@physik.fu-berlin.de,
	abelvesa@kernel.org, srini@kernel.org, s.nawrocki@samsung.com,
	nuno.sa@analog.com
Cc: Frank Li <frank.li@nxp.com>,
	driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
	imx@lists.linux.dev, linux-hwmon@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, linux-sound@vger.kernel.org,
	linux-sh@vger.kernel.org, Danilo Krummrich <dakr@kernel.org>
Subject: Re: [PATCH v2 1/4] driver core: generalize driver_override in struct device
Date: Tue,  3 Mar 2026 16:01:05 -0500	[thread overview]
Message-ID: <20260303210131.2966214-10-Frank.Li@nxp.com> (raw)
In-Reply-To: <20260303115720.48783-2-dakr@kernel.org>

From: Frank Li (AI-BOT) <frank.li@nxp.com>

AI bot review and may be useless.

> +static ssize_t driver_override_store(struct device *dev,
> +				     struct device_attribute *attr,
> +				     const char *buf, size_t count)
> +{
> +	int ret;
> +
> +	ret = __device_set_driver_override(dev, buf, count);
> +	if (ret)
> +		return ret;
> +
> +	return count;
> +}

Potential issue: if __device_set_driver_override() succeeds but
modifies state, returning 'count' may not reflect actual bytes
consumed if buf contains embedded nulls. Consider documenting
expected behavior or validating input length upfront.

> +static ssize_t driver_override_show(struct device *dev,
> +				    struct device_attribute *attr, char *buf)
> +{
> +	guard(spinlock)(&dev->driver_override.lock);
> +	return sysfs_emit(buf, "%s\n", dev->driver_override.name);
> +}

Potential NULL dereference: if dev->driver_override.name is NULL,
sysfs_emit() will print "(null)". Add explicit check or document
that NULL is acceptable output.

> +	if (sp->bus->driver_override) {
> +		error = device_add_group(dev, &driver_override_dev_group);
> +		if (error)
> +			goto out_groups;
> +	}

Error path bug: on device_add_group() failure, code jumps to
out_groups but should jump to out_override (which doesn't exist
yet). This leaks the sysfs link created below. Reorder or add
intermediate label.

> +	error = sysfs_create_link(&sp->devices_kset->kobj, &dev->kobj, dev_name(dev));
> +	if (error)
> -		goto out_groups;
> +		goto out_override;

Good: label renamed to match new cleanup order.

> +out_override:
> +	if (dev->bus->driver_override)
> +		device_remove_group(dev, &driver_override_dev_group);

Potential issue: dev->bus may be NULL or different from sp->bus at
this point. Use sp->bus for consistency with the add path above.

> +int __device_set_driver_override(struct device *dev, const char *s, size_t len)
> +{
> +	const char *new, *old;
> +	char *cp;
> +
> +	if (!s)
> +		return -EINVAL;

Inconsistency: len parameter is passed but then recalculated via
strlen(s) below. If len is meant to be trusted, don't recalculate.
If not, remove the parameter or document why both exist.

> +	len = strlen(s);

This overwrites the len parameter, making the initial bounds check
at PAGE_SIZE potentially useless. Clarify intent: is len from
userspace or always recomputed?

> +	new = kstrndup(s, len, GFP_KERNEL);
> +	if (!new)
> +		return -ENOMEM;
> +
> +	spin_lock(&dev->driver_override.lock);
> +	old = dev->driver_override.name;
> +	if (cp != s) {
> +		dev->driver_override.name = new;
> +		spin_unlock(&dev->driver_override.lock);
> +	} else {
> +		/* "\n" passed - clear override */
> +		dev->driver_override.name = NULL;
> +		spin_unlock(&dev->driver_override.lock);
> +
> +		kfree(new);
> +	}
> +	kfree(old);

Logic is correct but confusing: cp is set only if '\n' is found, so
the condition `if (cp != s)` is checking "was newline NOT at start".
Add a comment explaining the two paths (newline-at-start clears,
otherwise

  reply	other threads:[~2026-03-03 21:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03 11:53 [PATCH v2 0/4] driver core: generalize driver_override infrastructure Danilo Krummrich
2026-03-03 11:53 ` [PATCH v2 1/4] driver core: generalize driver_override in struct device Danilo Krummrich
2026-03-03 21:01   ` Frank Li [this message]
2026-03-04  2:27   ` Gui-Dong Han
2026-03-03 11:53 ` [PATCH v2 2/4] docs: driver-model: document driver_override Danilo Krummrich
2026-03-03 21:01   ` Frank Li
2026-03-03 11:53 ` [PATCH v2 3/4] hwmon: axi-fan: don't use driver_override as IRQ name Danilo Krummrich
2026-03-03 14:53   ` Nuno Sá
2026-03-03 16:23   ` Guenter Roeck
2026-03-03 16:25     ` Danilo Krummrich
2026-03-03 16:57       ` Guenter Roeck
2026-03-03 19:18         ` Danilo Krummrich
2026-03-03 21:01   ` Frank Li
2026-03-03 11:53 ` [PATCH v2 4/4] driver core: platform: use generic driver_override infrastructure Danilo Krummrich
2026-03-03 21:01   ` Frank Li
2026-03-05 12:42   ` Danilo Krummrich
2026-03-12 20:15     ` Danilo Krummrich
2026-03-16 23:56   ` Danilo Krummrich
2026-03-17  5:06     ` Greg KH
2026-03-17  8:36     ` Geert Uytterhoeven
2026-03-03 13:03 ` [PATCH v2 0/4] driver core: generalize " Gui-Dong Han
2026-03-12 15:21 ` Greg KH
2026-03-17 20:17 ` Danilo Krummrich

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=20260303210131.2966214-10-Frank.Li@nxp.com \
    --to=frank.li@nxp.com \
    --cc=abelvesa@kernel.org \
    --cc=dakr@kernel.org \
    --cc=dalias@libc.org \
    --cc=driver-core@lists.linux.dev \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=hanguidong02@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=rafael@kernel.org \
    --cc=s.nawrocki@samsung.com \
    --cc=srini@kernel.org \
    --cc=ysato@users.sourceforge.jp \
    /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