sh: platform_early: use strscpy in sh_early_platform_driver_register
PATCH 1/1 sh: platform_early: use strscpy in sh_early_platform_driver_register
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 <[email protected]>
--- arch/sh/drivers/platform_early.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/sh/drivers/platform_early.c +6 -6
@@ -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 *eplist_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 *epif (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 ;