From: Mikulas Patocka <mpatocka@redhat.com>
To: Dipendra Khadka <kdipendra88@gmail.com>
Cc: agk@redhat.com, snitzer@kernel.org, dm-devel@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Return error code for failure input for sscanf in parse_cblock_range()
Date: Mon, 23 Sep 2024 15:26:56 +0200 (CEST) [thread overview]
Message-ID: <5c258e04-10b4-749d-6f15-94a432ab652e@redhat.com> (raw)
In-Reply-To: <20240922164702.49615-1-kdipendra88@gmail.com>
Hi
I skimmed through the sscanf source code and it seems that it can't return
a negative value at all.
I think, this should be:
r = sscanf(str, "%llu-%llu%c", &b, &e, &dummy);
if (r != 2)
return -EINVAL;
Mikulas
On Sun, 22 Sep 2024, Dipendra Khadka wrote:
> Smatch reported following:
> '''
> drivers/md/dm-cache-target.c:3204 parse_cblock_range() warn: sscanf doesn't return error codes
> drivers/md/dm-cache-target.c:3217 parse_cblock_range() warn: sscanf doesn't return error codes
> '''
>
> Since, the only negative value that is returned by sscanf is -1.
> Returning -ENVAL when sscanf returns -1.
>
> Signed-off-by: Dipendra Khadka <kdipendra88@gmail.com>
> ---
> drivers/md/dm-cache-target.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
> index 17f0fab1e254..c35d65e310d6 100644
> --- a/drivers/md/dm-cache-target.c
> +++ b/drivers/md/dm-cache-target.c
> @@ -3200,8 +3200,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,
> * Try and parse form (ii) first.
> */
> r = sscanf(str, "%llu-%llu%c", &b, &e, &dummy);
> - if (r < 0)
> - return r;
> + if (r == -1)
> + return -EINVAL;
>
> if (r == 2) {
> result->begin = to_cblock(b);
> @@ -3213,8 +3213,8 @@ static int parse_cblock_range(struct cache *cache, const char *str,
> * That didn't work, try form (i).
> */
> r = sscanf(str, "%llu%c", &b, &dummy);
> - if (r < 0)
> - return r;
> + if (r == -1)
> + return -EINVAL;
>
> if (r == 1) {
> result->begin = to_cblock(b);
> --
> 2.43.0
>
prev parent reply other threads:[~2024-09-23 13:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-22 16:47 Dipendra Khadka
2024-09-23 9:40 ` Ming-Hung Tsai
2024-09-23 15:09 ` Mikulas Patocka
2024-09-23 15:35 ` Dipendra Khadka
2024-09-23 15:59 ` Mikulas Patocka
2024-09-23 16:05 ` Dipendra Khadka
2024-09-23 13:26 ` Mikulas Patocka [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=5c258e04-10b4-749d-6f15-94a432ab652e@redhat.com \
--to=mpatocka@redhat.com \
--cc=agk@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=kdipendra88@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=snitzer@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®