From: David Laight <David.Laight@ACULAB.COM>
To: 'Andy Shevchenko' <andriy.shevchenko@linux.intel.com>,
Jens Axboe <axboe@kernel.dk>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v1 2/9] pktcdvd: replace sscanf() by kstrtoul()
Date: Thu, 19 Jan 2023 22:40:12 +0000 [thread overview]
Message-ID: <4f4c89f2c0924f05a894a1457c63ee4c@AcuMS.aculab.com> (raw)
In-Reply-To: <20230119220809.5518-2-andriy.shevchenko@linux.intel.com>
From: Andy Shevchenko
> Sent: 19 January 2023 22:08
>
> The checkpatch.pl warns: "Prefer kstrto<type> to single variable sscanf".
> Fix the code accordingly.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/block/pktcdvd.c | 34 ++++++++++++++++++----------------
> 1 file changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
> index 0ec8dc8ee5ed..ad4336ae9927 100644
> --- a/drivers/block/pktcdvd.c
> +++ b/drivers/block/pktcdvd.c
> @@ -236,15 +236,16 @@ static ssize_t congestion_off_store(struct device *dev,
> const char *buf, size_t len)
> {
> struct pktcdvd_device *pd = dev_get_drvdata(dev);
> - int val;
> + int val, ret;
>
> - if (sscanf(buf, "%d", &val) == 1) {
> - spin_lock(&pd->lock);
> - pd->write_congestion_off = val;
> - init_write_congestion_marks(&pd->write_congestion_off,
> - &pd->write_congestion_on);
> - spin_unlock(&pd->lock);
> - }
> + ret = kstrtoint(buf, 10, &val);
> + if (ret)
> + return ret;
> +
> + spin_lock(&pd->lock);
> + pd->write_congestion_off = val;
> + init_write_congestion_marks(&pd->write_congestion_off, &pd->write_congestion_on);
> + spin_unlock(&pd->lock);
> return len;
> }
These don't look directly equivalent.
The sscanf() version silently ignores trailing characters.
I think kstrtoint() will generate an error.
Have you actually checked that the caller allows for
an error return.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2023-01-19 22:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-19 22:08 [PATCH v1 1/9] pktcdvd: Get rid of custom printing macros Andy Shevchenko
2023-01-19 22:08 ` [PATCH v1 2/9] pktcdvd: replace sscanf() by kstrtoul() Andy Shevchenko
2023-01-19 22:40 ` David Laight [this message]
2023-01-20 11:47 ` 'Andy Shevchenko'
2023-01-19 22:08 ` [PATCH v1 3/9] pktcdvd: use sysfs_emit() to instead of scnprintf() Andy Shevchenko
2023-01-20 7:27 ` Greg Kroah-Hartman
2023-01-19 22:08 ` [PATCH v1 4/9] pktcdvd: Get rid of pkt_seq_show() forward declaration Andy Shevchenko
2023-01-20 7:27 ` Greg Kroah-Hartman
2023-01-19 22:08 ` [PATCH v1 5/9] pktcdvd: Drop redundant castings for sector_t Andy Shevchenko
2023-01-20 7:28 ` Greg Kroah-Hartman
2023-01-19 22:08 ` [PATCH v1 6/9] pktcdvd: Use DEFINE_SHOW_ATTRIBUTE() to simplify code Andy Shevchenko
2023-01-20 7:26 ` Greg Kroah-Hartman
2023-01-19 22:08 ` [PATCH v1 7/9] pktcdvd: Use put_unaligned_be16() and get_unaligned_be16() Andy Shevchenko
2023-01-19 22:08 ` [PATCH v1 8/9] pktcdvd: Get rid of redundant 'else' Andy Shevchenko
2023-01-20 7:26 ` Greg Kroah-Hartman
2023-01-19 22:08 ` [PATCH v1 9/9] pktcdvd: Sort headers Andy Shevchenko
2023-01-20 7:28 ` Greg Kroah-Hartman
2023-01-20 7:24 ` [PATCH v1 1/9] pktcdvd: Get rid of custom printing macros Greg Kroah-Hartman
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=4f4c89f2c0924f05a894a1457c63ee4c@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=axboe@kernel.dk \
--cc=gregkh@linuxfoundation.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®