Skip to content

Commit f3dc4d9

Browse files
tobluxmiquelraynal
authored andcommitted
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 <thorsten.blum@linux.dev> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent c909fec commit f3dc4d9

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

drivers/mtd/sm_ftl.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
4444
struct sm_sysfs_attribute *sm_attr =
4545
container_of(attr, struct sm_sysfs_attribute, dev_attr);
4646

47-
strncpy(buf, sm_attr->data, sm_attr->len);
48-
return sm_attr->len;
47+
return sysfs_emit(buf, "%.*s", sm_attr->len, sm_attr->data);
4948
}
5049

5150

0 commit comments

Comments
 (0)