From: Andy Shevchenko <andriy.shevchenko@linux.intel.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-kernel@vger.kernel.org
Subject: [PATCH v2 2/9] pktcdvd: replace sscanf() by kstrtoul()
Date: Fri, 10 Mar 2023 18:45:42 +0200 [thread overview]
Message-ID: <20230310164549.22133-3-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230310164549.22133-1-andriy.shevchenko@linux.intel.com>
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;
}
static DEVICE_ATTR_RW(congestion_off);
@@ -266,15 +267,16 @@ static ssize_t congestion_on_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_on = 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_on = val;
+ init_write_congestion_marks(&pd->write_congestion_off, &pd->write_congestion_on);
+ spin_unlock(&pd->lock);
return len;
}
static DEVICE_ATTR_RW(congestion_on);
--
2.39.1
next prev parent reply other threads:[~2023-03-10 16:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 16:45 [PATCH v2 0/9] pktdvd: Clean up the driver Andy Shevchenko
2023-03-10 16:45 ` [PATCH v2 1/9] pktcdvd: Get rid of custom printing macros Andy Shevchenko
2023-03-10 16:45 ` Andy Shevchenko [this message]
2023-03-10 16:45 ` [PATCH v2 3/9] pktcdvd: use sysfs_emit() to instead of scnprintf() Andy Shevchenko
2023-03-10 16:45 ` [PATCH v2 4/9] pktcdvd: Get rid of pkt_seq_show() forward declaration Andy Shevchenko
2023-03-10 16:45 ` [PATCH v2 5/9] pktcdvd: Drop redundant castings for sector_t Andy Shevchenko
2023-03-10 16:45 ` [PATCH v2 6/9] pktcdvd: Use DEFINE_SHOW_ATTRIBUTE() to simplify code Andy Shevchenko
2023-03-10 16:45 ` [PATCH v2 7/9] pktcdvd: Use put_unaligned_be16() and get_unaligned_be16() Andy Shevchenko
2023-03-10 16:45 ` [PATCH v2 8/9] pktcdvd: Get rid of redundant 'else' Andy Shevchenko
2023-03-10 16:45 ` [PATCH v2 9/9] pktcdvd: Sort headers Andy Shevchenko
2023-06-06 14:58 ` [PATCH v2 0/9] pktdvd: Clean up the driver Andy Shevchenko
2023-06-06 20:23 ` Jens Axboe
2023-06-07 20:08 ` Andy Shevchenko
2023-06-07 20:21 ` Jens Axboe
2023-06-07 20:28 ` Jens Axboe
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=20230310164549.22133-3-andriy.shevchenko@linux.intel.com \
--to=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