[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1433199909-8319-1-git-send-email-filipayazi@gmail.com>
Date: Tue, 2 Jun 2015 01:05:09 +0200
From: Filip Ayazi <filipayazi@...il.com>
To: daniel.thompson@...aro.org, jason.wessel@...driver.com
Cc: adobriyan@...il.com, linux-kernel@...r.kernel.org,
kgdb-bugreport@...ts.sourceforge.net,
Filip Ayazi <filipayazi@...il.com>
Subject: [PATCH v3] kdb: use kstrto* instead of simple_strto
Replace simple_strto with appropriate kstrto functions as recommended
by checkpatch, removing no longer required variables.
Change pid, sig types from long to pid_t, int respectively.
Signed-off-by: Filip Ayazi <filipayazi@...il.com>
Reviewed-by: Daniel Thompson <daniel.thompson@...aro.org>
---
changes from v2:
store kstrto return value in a variable instead of calling it within if itself
delete != 0 from ifs
change pid type to pid_t, use kstrtoint for parsing
remove another temporary variable (val in kdbgetularg)
(All pointed out by Daniel Thompson, who reviewed v2)
kernel/debug/kdb/kdb_main.c | 74 +++++++++++++++++----------------------------
1 file changed, 28 insertions(+), 46 deletions(-)
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 4121345..513250c 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -289,6 +289,7 @@ static char *kdballocenv(size_t bytes)
static int kdbgetulenv(const char *match, unsigned long *value)
{
char *ep;
+ int err;
ep = kdbgetenv(match);
if (!ep)
@@ -296,7 +297,9 @@ static int kdbgetulenv(const char *match, unsigned long *value)
if (strlen(ep) == 0)
return KDB_NOENVVALUE;
- *value = simple_strtoul(ep, NULL, 0);
+ err = kstrtoul(ep, 0, value);
+ if (err)
+ return KDB_BADINT;
return 0;
}
@@ -334,41 +337,22 @@ int kdbgetintenv(const char *match, int *value)
*/
int kdbgetularg(const char *arg, unsigned long *value)
{
- char *endp;
- unsigned long val;
-
- val = simple_strtoul(arg, &endp, 0);
-
- if (endp == arg) {
- /*
- * Also try base 16, for us folks too lazy to type the
- * leading 0x...
- */
- val = simple_strtoul(arg, &endp, 16);
- if (endp == arg)
+ /*
+ * Also try base 16, for us folks too lazy to type the
+ * leading 0x...
+ */
+ if (kstrtoul(arg, 0, value))
+ if (kstrtoul(arg, 16, value))
return KDB_BADINT;
- }
-
- *value = val;
return 0;
}
int kdbgetu64arg(const char *arg, u64 *value)
{
- char *endp;
- u64 val;
-
- val = simple_strtoull(arg, &endp, 0);
-
- if (endp == arg) {
-
- val = simple_strtoull(arg, &endp, 16);
- if (endp == arg)
+ if (kstrtoull(arg, 0, value))
+ if (kstrtoull(arg, 16, value))
return KDB_BADINT;
- }
-
- *value = val;
return 0;
}
@@ -379,7 +363,7 @@ int kdbgetu64arg(const char *arg, u64 *value)
*/
int kdb_set(int argc, const char **argv)
{
- int i;
+ int i, err;
char *ep;
size_t varlen, vallen;
@@ -402,10 +386,9 @@ int kdb_set(int argc, const char **argv)
*/
if (strcmp(argv[1], "KDBDEBUG") == 0) {
unsigned int debugflags;
- char *cp;
- debugflags = simple_strtoul(argv[2], &cp, 0);
- if (cp == argv[2] || debugflags & ~KDB_DEBUG_FLAG_MASK) {
+ err = kstrtouint(argv[2], 0, &debugflags);
+ if (err || debugflags & ~KDB_DEBUG_FLAG_MASK) {
kdb_printf("kdb: illegal debug flags '%s'\n",
argv[2]);
return 0;
@@ -1588,10 +1571,8 @@ static int kdb_md(int argc, const char **argv)
if (!argv[0][3])
valid = 1;
else if (argv[0][3] == 'c' && argv[0][4]) {
- char *p;
- repeat = simple_strtoul(argv[0] + 4, &p, 10);
+ valid = !kstrtoint(argv[0]+4, 10, &repeat);
mdcount = ((repeat * bytesperword) + 15) / 16;
- valid = !*p;
}
last_repeat = repeat;
} else if (strcmp(argv[0], "md") == 0)
@@ -2080,6 +2061,7 @@ static int kdb_dmesg(int argc, const char **argv)
{
int diag;
int logging;
+ int err;
int lines = 0;
int adjust = 0;
int n = 0;
@@ -2091,13 +2073,12 @@ static int kdb_dmesg(int argc, const char **argv)
if (argc > 2)
return KDB_ARGCOUNT;
if (argc) {
- char *cp;
- lines = simple_strtol(argv[1], &cp, 0);
- if (*cp)
+ err = kstrtoint(argv[1], 0, &lines);
+ if (err)
lines = 0;
if (argc > 1) {
- adjust = simple_strtoul(argv[2], &cp, 0);
- if (*cp || adjust < 0)
+ err = kstrtoint(argv[2], 0, &adjust);
+ if (err || adjust < 0)
adjust = 0;
}
}
@@ -2436,16 +2417,17 @@ static int kdb_help(int argc, const char **argv)
*/
static int kdb_kill(int argc, const char **argv)
{
- long sig, pid;
- char *endp;
+ pid_t pid;
+ int sig;
+ int err;
struct task_struct *p;
struct siginfo info;
if (argc != 2)
return KDB_ARGCOUNT;
- sig = simple_strtol(argv[1], &endp, 0);
- if (*endp)
+ err = kstrtoint(argv[1], 0, &sig);
+ if (err)
return KDB_BADINT;
if (sig >= 0) {
kdb_printf("Invalid signal parameter.<-signal>\n");
@@ -2453,8 +2435,8 @@ static int kdb_kill(int argc, const char **argv)
}
sig = -sig;
- pid = simple_strtol(argv[2], &endp, 0);
- if (*endp)
+ err = kstrtoint(argv[2], 0, &pid);
+ if (err)
return KDB_BADINT;
if (pid <= 0) {
kdb_printf("Process ID must be large than 0.\n");
--
1.9.1
--
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