From: Thorsten Blum Date: Sun, 23 Nov 2025 18:21:02 +0000 (+0100) Subject: mtd: sm_ftl: Replace deprecated strncpy with sysfs_emit in sm_attr_show X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f3dc4d9898bc98e3cf569f038d90a5fec7bfc44a;p=thirdparty%2Flinux.git mtd: sm_ftl: Replace deprecated strncpy with sysfs_emit in sm_attr_show 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 Signed-off-by: Miquel Raynal --- diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c index abc7b186353ff..987d481bf2657 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); }