diff mbox series

[RFC,05/20] loop: use snprintf for XXX_show()

Message ID 20210202053552.4844-6-chaitanya.kulkarni@wdc.com (mailing list archive)
State New, archived
Headers show
Series loop: cleanup and small improvement | expand

Commit Message

Chaitanya Kulkarni Feb. 2, 2021, 5:35 a.m. UTC
Use snprintf() over sprintf() which allows us to limit the target
buffer size.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/loop.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Johannes Thumshirn Feb. 2, 2021, 11:05 a.m. UTC | #1
On 02/02/2021 06:39, Chaitanya Kulkarni wrote:
> Use snprintf() over sprintf() which allows us to limit the target
> buffer size.

Why not sysfs_emit()?
Chaitanya Kulkarni Feb. 2, 2021, 7:56 p.m. UTC | #2
On 2/2/21 03:05, Johannes Thumshirn wrote:
> On 02/02/2021 06:39, Chaitanya Kulkarni wrote:
>> Use snprintf() over sprintf() which allows us to limit the target
>> buffer size.
> Why not sysfs_emit()?
>
Sure, will add to V1.
diff mbox series

Patch

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index cf2789f7e6ba..3f8d9bdfc16e 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -806,33 +806,35 @@  static ssize_t loop_attr_backing_file_show(struct loop_device *lo, char *buf)
 
 static ssize_t loop_attr_offset_show(struct loop_device *lo, char *buf)
 {
-	return sprintf(buf, "%llu\n", (unsigned long long)lo->lo_offset);
+	return snprintf(buf, PAGE_SIZE,
+			"%llu\n", (unsigned long long)lo->lo_offset);
 }
 
 static ssize_t loop_attr_sizelimit_show(struct loop_device *lo, char *buf)
 {
-	return sprintf(buf, "%llu\n", (unsigned long long)lo->lo_sizelimit);
+	return snprintf(buf, PAGE_SIZE,
+			"%llu\n", (unsigned long long)lo->lo_sizelimit);
 }
 
 static ssize_t loop_attr_autoclear_show(struct loop_device *lo, char *buf)
 {
 	int autoclear = (lo->lo_flags & LO_FLAGS_AUTOCLEAR);
 
-	return sprintf(buf, "%s\n", autoclear ? "1" : "0");
+	return snprintf(buf, PAGE_SIZE, "%s\n", autoclear ? "1" : "0");
 }
 
 static ssize_t loop_attr_partscan_show(struct loop_device *lo, char *buf)
 {
 	int partscan = (lo->lo_flags & LO_FLAGS_PARTSCAN);
 
-	return sprintf(buf, "%s\n", partscan ? "1" : "0");
+	return snprintf(buf, PAGE_SIZE, "%s\n", partscan ? "1" : "0");
 }
 
 static ssize_t loop_attr_dio_show(struct loop_device *lo, char *buf)
 {
 	int dio = (lo->lo_flags & LO_FLAGS_DIRECT_IO);
 
-	return sprintf(buf, "%s\n", dio ? "1" : "0");
+	return snprintf(buf, PAGE_SIZE, "%s\n", dio ? "1" : "0");
 }
 
 LOOP_ATTR_RO(backing_file);