From: Alexey Dobriyan <adobriyan@gmail.com>
To: filipayazi@gmail.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kdb: use kstrto instead of simple_strto
Date: Sun, 31 May 2015 15:29:26 +0300 [thread overview]
Message-ID: <20150531122926.GA3188@p183.telecom.by> (raw)
> Replace obsolete simple_strto* calls with appropriate kstrto*
> functions.
> static int kdb_kill(int argc, const char **argv)
> {
> long sig, pid;
> - char *endp;
> struct task_struct *p;
> struct siginfo info;
>
> if (argc != 2)
> return KDB_ARGCOUNT;
>
> - sig = simple_strtol(argv[1], &endp, 0);
> - if (*endp)
> + if (kstrtol(argv[1], 0, &sig) != 0)
> return KDB_BADINT;
> if (sig >= 0) {
> kdb_printf("Invalid signal parameter.<-signal>\n");
> <at> <at> -2453,8 +2435,7 <at> <at> static int kdb_kill(int argc, const char **argv)
> }
> sig = -sig;
>
> - pid = simple_strtol(argv[2], &endp, 0);
> - if (*endp)
> + if (kstrtol(argv[2], 0, &pid) != 0)
> return KDB_BADINT;
> if (pid <= 0) {
> kdb_printf("Process ID must be large than 0.\n");
This patch does easy mistake, namely trivial switch from simple_strtoul() to kstrtoul().
But you have to remember that there are NO simple_strtoint() or something like that,
so real type of data is anchor not function name.
In the code above data are "sig" and "pid" which are "int" or "unsigned int" at most.
Later "sig" is negated, so "int sig" is OK.
Pids are always unsigned logically so "unsigned int" is correct.
Don't be afraid to switch type of variable to correct one. Most of
the time "unsigned long foo" is wrong becase C-derived api didn't offer
anything better.
next reply other threads:[~2015-05-31 12:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-31 12:29 Alexey Dobriyan [this message]
2015-05-31 17:38 ` [PATCH] kdb: use kstrto instead of simple_strto Filip Ayazi
-- strict thread matches above, loose matches on Subject: below --
2015-05-31 11:44 Filip Ayazi
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=20150531122926.GA3188@p183.telecom.by \
--to=adobriyan@gmail.com \
--cc=filipayazi@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.