mtd: mtdpart: Convert sysfs sprintf/snprintf family to sysfs_emit
authorTian Tao <tiantao6@hisilicon.com>
Mon, 12 Apr 2021 09:35:44 +0000 (17:35 +0800)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 10 May 2021 08:44:43 +0000 (10:44 +0200)
Use sysfs_emit instead of snprintf to avoid buf overrun,because in
sysfs_emit it strictly checks whether buf is null or buf whether
pagesize aligned, otherwise it returns an error.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/1618220144-33839-3-git-send-email-tiantao6@hisilicon.com
drivers/mtd/mtdpart.c

index 665fd9020b764da7d8c7a69359e57a1bccc78a9e..66a67c6e3cbc0495bbe064adfdb08efb2dc701e3 100644 (file)
@@ -217,7 +217,7 @@ static ssize_t mtd_partition_offset_show(struct device *dev,
 {
        struct mtd_info *mtd = dev_get_drvdata(dev);
 
-       return snprintf(buf, PAGE_SIZE, "%lld\n", mtd->part.offset);
+       return sysfs_emit(buf, "%lld\n", mtd->part.offset);
 }
 
 static DEVICE_ATTR(offset, S_IRUGO, mtd_partition_offset_show, NULL);