]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
driver core: simplify __device_set_driver_override() clearing logic
authorGui-Dong Han <hanguidong02@gmail.com>
Wed, 25 Mar 2026 09:09:05 +0000 (17:09 +0800)
committerDanilo Krummrich <dakr@kernel.org>
Mon, 30 Mar 2026 12:45:51 +0000 (14:45 +0200)
commit3210dabba4e4aff7395b68914bad95153dda6db7
treecfe2fdc39ae1736cde2ceda16b8d3acb237ffb1b
parenta1fa010b3c9f0adae252986ddb54a449df45f700
driver core: simplify __device_set_driver_override() clearing logic

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@linux-m68k.org>
Link: https://lore.kernel.org/driver-core/DGS82WWLXPJ0.2EH4VJSF30UR5@kernel.org/
Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>
Link: https://patch.msgid.link/20260325090905.169000-1-hanguidong02@gmail.com
[ Narrow cp's scope to the newline handling block; use scoped_guard().
  - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
drivers/base/dd.c