Skip to content

Commit

Permalink
zram: use scnprintf() in attrs show() methods
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Minchan Kim <[email protected]>
Cc: Jerome Marchand <[email protected]>
Cc: Nitin Gupta <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
sergey-senozhatsky authored and torvalds committed Apr 7, 2014
1 parent 60a726e commit 56b4e8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions drivers/block/zram/zcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,14 @@ ssize_t zcomp_available_show(const char *comp, char *buf)

while (backends[i]) {
if (sysfs_streq(comp, backends[i]->name))
sz += sprintf(buf + sz, "[%s] ", backends[i]->name);
sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2,
"[%s] ", backends[i]->name);
else
sz += sprintf(buf + sz, "%s ", backends[i]->name);
sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2,
"%s ", backends[i]->name);
i++;
}
sz += sprintf(buf + sz, "\n");
sz += scnprintf(buf + sz, PAGE_SIZE - sz, "\n");
return sz;
}

Expand Down
12 changes: 6 additions & 6 deletions drivers/block/zram/zram_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static ssize_t zram_attr_##name##_show(struct device *d, \
struct device_attribute *attr, char *b) \
{ \
struct zram *zram = dev_to_zram(d); \
return sprintf(b, "%llu\n", \
return scnprintf(b, PAGE_SIZE, "%llu\n", \
(u64)atomic64_read(&zram->stats.name)); \
} \
static struct device_attribute dev_attr_##name = \
Expand All @@ -69,7 +69,7 @@ static ssize_t disksize_show(struct device *dev,
{
struct zram *zram = dev_to_zram(dev);

return sprintf(buf, "%llu\n", zram->disksize);
return scnprintf(buf, PAGE_SIZE, "%llu\n", zram->disksize);
}

static ssize_t initstate_show(struct device *dev,
Expand All @@ -82,15 +82,15 @@ static ssize_t initstate_show(struct device *dev,
val = init_done(zram);
up_read(&zram->init_lock);

return sprintf(buf, "%u\n", val);
return scnprintf(buf, PAGE_SIZE, "%u\n", val);
}

static ssize_t orig_data_size_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct zram *zram = dev_to_zram(dev);

return sprintf(buf, "%llu\n",
return scnprintf(buf, PAGE_SIZE, "%llu\n",
(u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT);
}

Expand All @@ -106,7 +106,7 @@ static ssize_t mem_used_total_show(struct device *dev,
val = zs_get_total_size_bytes(meta->mem_pool);
up_read(&zram->init_lock);

return sprintf(buf, "%llu\n", val);
return scnprintf(buf, PAGE_SIZE, "%llu\n", val);
}

static ssize_t max_comp_streams_show(struct device *dev,
Expand All @@ -119,7 +119,7 @@ static ssize_t max_comp_streams_show(struct device *dev,
val = zram->max_comp_streams;
up_read(&zram->init_lock);

return sprintf(buf, "%d\n", val);
return scnprintf(buf, PAGE_SIZE, "%d\n", val);
}

static ssize_t max_comp_streams_store(struct device *dev,
Expand Down

0 comments on commit 56b4e8c

Please sign in to comment.