lkml.org 
[lkml]   [2026]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] sh: platform_early: use strscpy in sh_early_platform_driver_register
Date
Use strscpy() to copy the early parameter to the destination buffer
instead of using memcpy() followed by a manual NUL termination. This
also makes the explicit ->bufsize guard unnecessary, remove it.

Return early when the parameter is NULL to avoid unnecessarily calling
strlen() on the driver name.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/sh/drivers/platform_early.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/sh/drivers/platform_early.c b/arch/sh/drivers/platform_early.c
index ca73442a03a6..9600787ee181 100644
--- a/arch/sh/drivers/platform_early.c
+++ b/arch/sh/drivers/platform_early.c
@@ -3,6 +3,7 @@
#include <asm/platform_early.h>
#include <linux/mod_devicetable.h>
#include <linux/pm.h>
+#include <linux/string.h>

static __initdata LIST_HEAD(sh_early_platform_driver_list);
static __initdata LIST_HEAD(sh_early_platform_device_list);
@@ -74,12 +75,15 @@ int __init sh_early_platform_driver_register(struct sh_early_platform_driver *ep
list_add_tail(&epdrv->list, &sh_early_platform_driver_list);
}

+ if (!buf)
+ return 0;
+
/* If the user has specified device then make sure the driver
* gets prioritized. The driver of the last device specified on
* command line will be put first on the list.
*/
n = strlen(epdrv->pdrv->driver.name);
- if (buf && !strncmp(buf, epdrv->pdrv->driver.name, n)) {
+ if (!strncmp(buf, epdrv->pdrv->driver.name, n)) {
list_move(&epdrv->list, &sh_early_platform_driver_list);

/* Allow passing parameters after device name */
@@ -99,11 +103,7 @@ int __init sh_early_platform_driver_register(struct sh_early_platform_driver *ep
if (buf[n] == ',')
n++;

- if (epdrv->bufsize) {
- memcpy(epdrv->buffer, &buf[n],
- min_t(int, epdrv->bufsize, strlen(&buf[n]) + 1));
- epdrv->buffer[epdrv->bufsize - 1] = '\0';
- }
+ strscpy(epdrv->buffer, &buf[n], epdrv->bufsize);
}

return 0;
\
 
 \ /
  Last update: 2026-05-05 11:05    [W:0.039 / U:5.805 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog