aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>2014-04-07 18:38:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-07 19:36:02 -0400
commit56b4e8cb85827a2ccc4752a2a7148e56b62b7e96 (patch)
tree48a9d05f13fd1c1dedf768879ebb4c05c7cf2fed /drivers
parent60a726e33375a1096e85399cfa1327081b4c38be (diff)
zram: use scnprintf() in attrs show() methods
sysfs.txt documentation lists the following requirements: - The buffer will always be PAGE_SIZE bytes in length. On i386, this is 4096. - show() methods should return the number of bytes printed into the buffer. This is the return value of scnprintf(). - show() should always use scnprintf(). Use scnprintf() in show() functions. Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Acked-by: Minchan Kim <minchan@kernel.org> Cc: Jerome Marchand <jmarchan@redhat.com> Cc: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/block/zram/zcomp.c8
-rw-r--r--drivers/block/zram/zram_drv.c12
2 files changed, 11 insertions, 9 deletions
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index b0e7592c44d8..f1ff39a3d1c1 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -275,12 +275,14 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
275 275
276 while (backends[i]) { 276 while (backends[i]) {
277 if (sysfs_streq(comp, backends[i]->name)) 277 if (sysfs_streq(comp, backends[i]->name))
278 sz += sprintf(buf + sz, "[%s] ", backends[i]->name); 278 sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2,
279 "[%s] ", backends[i]->name);
279 else 280 else
280 sz += sprintf(buf + sz, "%s ", backends[i]->name); 281 sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2,
282 "%s ", backends[i]->name);
281 i++; 283 i++;
282 } 284 }
283 sz += sprintf(buf + sz, "\n"); 285 sz += scnprintf(buf + sz, PAGE_SIZE - sz, "\n");
284 return sz; 286 return sz;
285} 287}
286 288
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 80a1cfca1bf0..15e7b8e64cbb 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -48,7 +48,7 @@ static ssize_t zram_attr_##name##_show(struct device *d, \
48 struct device_attribute *attr, char *b) \ 48 struct device_attribute *attr, char *b) \
49{ \ 49{ \
50 struct zram *zram = dev_to_zram(d); \ 50 struct zram *zram = dev_to_zram(d); \
51 return sprintf(b, "%llu\n", \ 51 return scnprintf(b, PAGE_SIZE, "%llu\n", \
52 (u64)atomic64_read(&zram->stats.name)); \ 52 (u64)atomic64_read(&zram->stats.name)); \
53} \ 53} \
54static struct device_attribute dev_attr_##name = \ 54static struct device_attribute dev_attr_##name = \
@@ -69,7 +69,7 @@ static ssize_t disksize_show(struct device *dev,
69{ 69{
70 struct zram *zram = dev_to_zram(dev); 70 struct zram *zram = dev_to_zram(dev);
71 71
72 return sprintf(buf, "%llu\n", zram->disksize); 72 return scnprintf(buf, PAGE_SIZE, "%llu\n", zram->disksize);
73} 73}
74 74
75static ssize_t initstate_show(struct device *dev, 75static ssize_t initstate_show(struct device *dev,
@@ -82,7 +82,7 @@ static ssize_t initstate_show(struct device *dev,
82 val = init_done(zram); 82 val = init_done(zram);
83 up_read(&zram->init_lock); 83 up_read(&zram->init_lock);
84 84
85 return sprintf(buf, "%u\n", val); 85 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
86} 86}
87 87
88static ssize_t orig_data_size_show(struct device *dev, 88static ssize_t orig_data_size_show(struct device *dev,
@@ -90,7 +90,7 @@ static ssize_t orig_data_size_show(struct device *dev,
90{ 90{
91 struct zram *zram = dev_to_zram(dev); 91 struct zram *zram = dev_to_zram(dev);
92 92
93 return sprintf(buf, "%llu\n", 93 return scnprintf(buf, PAGE_SIZE, "%llu\n",
94 (u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT); 94 (u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT);
95} 95}
96 96
@@ -106,7 +106,7 @@ static ssize_t mem_used_total_show(struct device *dev,
106 val = zs_get_total_size_bytes(meta->mem_pool); 106 val = zs_get_total_size_bytes(meta->mem_pool);
107 up_read(&zram->init_lock); 107 up_read(&zram->init_lock);
108 108
109 return sprintf(buf, "%llu\n", val); 109 return scnprintf(buf, PAGE_SIZE, "%llu\n", val);
110} 110}
111 111
112static ssize_t max_comp_streams_show(struct device *dev, 112static ssize_t max_comp_streams_show(struct device *dev,
@@ -119,7 +119,7 @@ static ssize_t max_comp_streams_show(struct device *dev,
119 val = zram->max_comp_streams; 119 val = zram->max_comp_streams;
120 up_read(&zram->init_lock); 120 up_read(&zram->init_lock);
121 121
122 return sprintf(buf, "%d\n", val); 122 return scnprintf(buf, PAGE_SIZE, "%d\n", val);
123} 123}
124 124
125static ssize_t max_comp_streams_store(struct device *dev, 125static ssize_t max_comp_streams_store(struct device *dev,