Skip to contentSkip to conversation

mtd: sm_ftl: Replace deprecated strncpy with sysfs_emit in sm_attr_show

PATCH Applied Thorsten Blum 2 participants 2 messages Nov 23, 2025 – Nov 29, 2025 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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'.

---
 drivers/mtd/sm_ftl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/sm_ftl.c +1 -2
index abc7b186353f..987d481bf265 100644
@@ -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);
 }
 
 
Signature · 1 line
2.51.1
maintainer Applied
#1 lore raw
Quoted 10 lines · Thorsten Blum

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