Re: [PATCH] driver core: simplify __device_set_driver_override() clearing logic

From: Danilo Krummrich

Date: Mon Mar 30 2026 - 10:04:11 EST


On Wed Mar 25, 2026 at 10:09 AM CET, Gui-Dong Han wrote:
> Currently, __device_set_driver_override() handles clearing the override
> via empty string ("") and newline ("\n") in two separate paths. The "\n"
> case also performs an unnecessary memory allocation and immediate free.
>
> Simplify the logic by initializing 'new' to NULL and only allocating
> memory if the string length remains non-zero after stripping the
> trailing newline.
>
> Reduce code size, improve readability, and avoid unnecessary memory
> operations.
>
> No functional change intended.
>
> Suggested-by: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> Link: https://lore.kernel.org/driver-core/DGS82WWLXPJ0.2EH4VJSF30UR5@xxxxxxxxxx/
> Signed-off-by: Gui-Dong Han <hanguidong02@xxxxxxxxx>

Applied to driver-core-testing, thanks!

[ Narrow cp's scope to the newline handling block; use scoped_guard().
- Danilo ]