From: Minchan Kim <minchan@kernel.org>
To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Jerome Marchand <jmarchan@redhat.com>,
Nitin Gupta <ngupta@vflare.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] zram: use scnprintf() in attrs show() methods
Date: Mon, 10 Mar 2014 11:09:14 +0900 [thread overview]
Message-ID: <20140310020914.GE14370@bbox> (raw)
In-Reply-To: <1394393228-14713-1-git-send-email-sergey.senozhatsky@gmail.com>
On Sun, Mar 09, 2014 at 10:27:08PM +0300, Sergey Senozhatsky wrote:
> 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>
> ---
> drivers/block/zram/zcomp.c | 8 +++++---
> drivers/block/zram/zram_drv.c | 12 ++++++------
> 2 files changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
> index 92a83df..ffcaff7 100644
> --- a/drivers/block/zram/zcomp.c
> +++ b/drivers/block/zram/zcomp.c
> @@ -274,12 +274,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;
> }
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 7631ef0..e6ff420 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -47,7 +47,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 = \
> @@ -68,7 +68,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,
> @@ -81,7 +81,7 @@ 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,
> @@ -89,7 +89,7 @@ static ssize_t orig_data_size_show(struct device *dev,
> {
> 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);
> }
>
> @@ -105,7 +105,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,
> @@ -118,7 +118,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,
> --
> 1.9.0.477.g83111a0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
Kind regards,
Minchan Kim
prev parent reply other threads:[~2014-03-10 2:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-09 19:27 [PATCH] zram: use scnprintf() in attrs show() methods Sergey Senozhatsky
2014-03-10 2:09 ` Minchan Kim [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140310020914.GE14370@bbox \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=jmarchan@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ngupta@vflare.org \
--cc=sergey.senozhatsky@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox