From: Filip Ayazi <filipayazi@gmail.com>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kdb: use kstrto instead of simple_strto
Date: Sun, 31 May 2015 19:38:01 +0200 [thread overview]
Message-ID: <556B46F9.2060806@gmail.com> (raw)
In-Reply-To: <20150531122926.GA3188@p183.telecom.by>
On 05/31/2015 02:29 PM, Alexey Dobriyan wrote:
>> 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.
Thank you for the feedback, I know there is no simple_strtoint and the patch
uses kstrtoint/uint where the variable is declared as int/unsigned int
(not doing
so would cause compilation warnings).
> 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.
pid and sig variables are declared as long, I didn't know why so I
didn't change
that, I will change their types to uint and int as you said and resend
the patch soon.
next prev parent reply other threads:[~2015-05-31 17:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-31 12:29 [PATCH] kdb: use kstrto instead of simple_strto Alexey Dobriyan
2015-05-31 17:38 ` Filip Ayazi [this message]
-- 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=556B46F9.2060806@gmail.com \
--to=filipayazi@gmail.com \
--cc=adobriyan@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox