diff mbox series

[drivers/mtd,v2,2/2] mtd: mtdpart: Convert sysfs sprintf/snprintf family to sysfs_emit

Message ID 1618220144-33839-3-git-send-email-tiantao6@hisilicon.com
State Accepted
Delegated to: Miquel Raynal
Headers show
Series convert sysfs sprintf/snprintf/scnprintf to sysfs_emit | expand

Commit Message

tiantao \(H\) April 12, 2021, 9:35 a.m. UTC
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>
---
 drivers/mtd/mtdpart.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Miquel Raynal May 10, 2021, 9:09 a.m. UTC | #1
On Mon, 2021-04-12 at 09:35:44 UTC, Tian Tao wrote:
> 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>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel
diff mbox series

Patch

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 665fd90..66a67c6 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -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);