[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150531122926.GA3188@p183.telecom.by>
Date: Sun, 31 May 2015 15:29:26 +0300
From: Alexey Dobriyan <adobriyan@...il.com>
To: filipayazi@...il.com
Cc: linux-kernel@...r.kernel.org
Subject: Re: [PATCH] kdb: use kstrto instead of simple_strto
> 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists