* [PATCH] mtd: sm_ftl: Replace deprecated strncpy with sysfs_emit in sm_attr_show
@ 2025-11-23 18:21 Thorsten Blum
2025-11-29 12:51 ` Miquel Raynal
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-11-23 18:21 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
Cc: Thorsten Blum, linux-mtd, linux-kernel
strncpy() is deprecated [1] for NUL-terminated destination buffers
because it does not guarantee NUL termination. It also unnecessarily
NUL-pads the destination buffer if the source is shorter. Replace it
with sysfs_emit() using the "%.*s" format specifier and supply the
length 'sm_attr->len' to improve sm_attr_show().
Return the number of characters actually written to 'buf' instead of
'sm_attr->len'.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/mtd/sm_ftl.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
index abc7b186353f..987d481bf265 100644
--- a/drivers/mtd/sm_ftl.c
+++ b/drivers/mtd/sm_ftl.c
@@ -44,8 +44,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
struct sm_sysfs_attribute *sm_attr =
container_of(attr, struct sm_sysfs_attribute, dev_attr);
- strncpy(buf, sm_attr->data, sm_attr->len);
- return sm_attr->len;
+ return sysfs_emit(buf, "%.*s", sm_attr->len, sm_attr->data);
}
--
2.51.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd: sm_ftl: Replace deprecated strncpy with sysfs_emit in sm_attr_show
2025-11-23 18:21 [PATCH] mtd: sm_ftl: Replace deprecated strncpy with sysfs_emit in sm_attr_show Thorsten Blum
@ 2025-11-29 12:51 ` Miquel Raynal
0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2025-11-29 12:51 UTC (permalink / raw)
To: Richard Weinberger, Vignesh Raghavendra, Thorsten Blum
Cc: linux-mtd, linux-kernel
On Sun, 23 Nov 2025 19:21:02 +0100, Thorsten Blum wrote:
> strncpy() is deprecated [1] for NUL-terminated destination buffers
> because it does not guarantee NUL termination. It also unnecessarily
> NUL-pads the destination buffer if the source is shorter. Replace it
> with sysfs_emit() using the "%.*s" format specifier and supply the
> length 'sm_attr->len' to improve sm_attr_show().
>
> Return the number of characters actually written to 'buf' instead of
> 'sm_attr->len'.
>
> [...]
Applied to mtd/next, thanks!
[1/1] mtd: sm_ftl: Replace deprecated strncpy with sysfs_emit in sm_attr_show
commit: f3dc4d9898bc98e3cf569f038d90a5fec7bfc44a
Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).
Kind regards,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-29 12:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-23 18:21 [PATCH] mtd: sm_ftl: Replace deprecated strncpy with sysfs_emit in sm_attr_show Thorsten Blum
2025-11-29 12:51 ` Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox