public inbox for imx@lists.linux.dev
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Geert Uytterhoeven" <geert@linux-m68k.org>
Cc: <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>,
	<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>
Subject: Re: [PATCH 1/3] driver core: generalize driver_override in struct device
Date: Mon, 02 Mar 2026 11:26:01 +0100	[thread overview]
Message-ID: <DGS82WWLXPJ0.2EH4VJSF30UR5@kernel.org> (raw)
In-Reply-To: <CAMuHMdUi3uNoDJ67WkNSKn=BD1F7D1Ot=gz4TwFPvaaYmKaNcg@mail.gmail.com>

On Mon Mar 2, 2026 at 11:00 AM CET, Geert Uytterhoeven wrote:
>> --- a/drivers/base/dd.c
>> +++ b/drivers/base/dd.c
>> @@ -381,6 +381,66 @@ static void __exit deferred_probe_exit(void)
>>  }
>>  __exitcall(deferred_probe_exit);
>>
>> +int __device_set_driver_override(struct device *dev, const char *s, size_t len)
>> +{
>> +       const char *new, *old;
>> +       char *cp;
>> +
>> +       if (!s)
>> +               return -EINVAL;
>> +
>> +       /*
>> +        * The stored value will be used in sysfs show callback (sysfs_emit()),
>> +        * which has a length limit of PAGE_SIZE and adds a trailing newline.
>> +        * Thus we can store one character less to avoid truncation during sysfs
>> +        * show.
>> +        */
>> +       if (len >= (PAGE_SIZE - 1))
>> +               return -EINVAL;
>> +
>> +       /*
>> +        * Compute the real length of the string in case userspace sends us a
>> +        * bunch of \0 characters like python likes to do.
>> +        */
>> +       len = strlen(s);
>> +
>
> The newline case below is is basically the same case as the empty
> string.  Hence if you would move the newline check here:
>
>     if (len) {
>             cp = strnchr(s, len, '\n');
>             if (cp)
>                     len = cp - s;
>     }
>
> then the "cp != s" check below is no longer needed.
>
>> +       if (!len) {
>> +               /* Empty string passed - clear override */
>> +               spin_lock(&dev->driver_override.lock);
>> +               old = dev->driver_override.name;
>> +               dev->driver_override.name = NULL;
>> +               spin_unlock(&dev->driver_override.lock);
>> +               kfree(old);
>> +
>> +               return 0;
>> +       }
>
> Also, this block can be eliminated completely...
>
>> +
>> +       cp = strnchr(s, len, '\n');
>> +       if (cp)
>> +               len = cp - s;
>> +
>> +       new = kstrndup(s, len, GFP_KERNEL);
>> +       if (!new)
>> +               return -ENOMEM;
>
> ... by pre-initializing new to NULL, and making the allocation of new
> conditional on len being non-zero.
>
>> +
>> +       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);
>> +
>> +       return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(__device_set_driver_override);

This is essentially a copy of driver_set_override(). Except for the required
minor changes I intentionally kept it "as is" as it will go through -fixes and
we know it works properly.

Do you mind sending a follow-up patch with your suggested improvements?

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

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02  0:25 [PATCH 0/3] driver core: generalize driver_override infrastructure Danilo Krummrich
2026-03-02  0:25 ` [PATCH 1/3] driver core: generalize driver_override in struct device Danilo Krummrich
2026-03-02  7:35   ` Gui-Dong Han
2026-03-02  8:36   ` Gui-Dong Han
2026-03-02 10:05     ` Danilo Krummrich
2026-03-02 11:04       ` Gui-Dong Han
2026-03-02 10:00   ` Geert Uytterhoeven
2026-03-02 10:26     ` Danilo Krummrich [this message]
2026-03-02 10:38       ` Geert Uytterhoeven
2026-03-02 11:03         ` Danilo Krummrich
2026-03-02 10:23   ` Armin Wolf
2026-03-02 16:28     ` Danilo Krummrich
2026-03-02  0:25 ` [PATCH 2/3] hwmon: axi-fan: don't use driver_override as IRQ name Danilo Krummrich
2026-03-02  0:51   ` Guenter Roeck
2026-03-02 10:00     ` Danilo Krummrich
2026-03-02 11:02     ` Nuno Sá
2026-03-02  0:25 ` [PATCH 3/3] driver core: platform: use generic driver_override infrastructure Danilo Krummrich
2026-03-02  8:55   ` Gui-Dong Han
2026-03-02  9:41 ` [PATCH 0/3] driver core: generalize " Gui-Dong Han
2026-03-02 10:12   ` Danilo Krummrich
2026-03-02 10:59     ` Gui-Dong Han

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=DGS82WWLXPJ0.2EH4VJSF30UR5@kernel.org \
    --to=dakr@kernel.org \
    --cc=abelvesa@kernel.org \
    --cc=dalias@libc.org \
    --cc=driver-core@lists.linux.dev \
    --cc=geert@linux-m68k.org \
    --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