Skip to content

Commit f89a687

Browse files
committed
Merge tag 'kgdb-6.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux
Pull kgdb updates from Daniel Thompson: "A relatively modest collection of changes: - Adopt kstrtoint() and kstrtol() instead of the simple_strtoXX family for better error checking of user input. - Align the print behavour when breakpoints are enabled and disabled by adopting the current behaviour of breakpoint disable for both. - Remove some of the (rather odd and user hostile) hex fallbacks and require kdb users to prefix with 0x instead. - Tidy up (and fix) control code handling in kdb's keyboard code. This makes the control code handling at the keyboard behave the same way as it does via the UART. - Switch my own entry in MAINTAINERS to my @kernel.org address" * tag 'kgdb-6.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux: kdb: fix ctrl+e/a/f/b/d/p/n broken in keyboard mode MAINTAINERS: Use Daniel Thompson's korg address for kgdb work kdb: Fix breakpoint enable to be silent if already enabled kdb: Remove fallback interpretation of arbitrary numbers as hex trace: kdb: Replace simple_strtoul with kstrtoul in kdb_ftdump kdb: Replace the use of simple_strto with safer kstrto in kdb_main
2 parents aad3a0d + 24b2455 commit f89a687

File tree

5 files changed

+51
-72
lines changed

5 files changed

+51
-72
lines changed

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12670,7 +12670,7 @@ F: samples/kfifo/
1267012670

1267112671
KGDB / KDB /debug_core
1267212672
M: Jason Wessel <[email protected]>
12673-
M: Daniel Thompson <daniel.thompson@linaro.org>
12673+
M: Daniel Thompson <danielt@kernel.org>
1267412674
R: Douglas Anderson <[email protected]>
1267512675
1267612676
S: Maintained

kernel/debug/kdb/kdb_bp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,15 @@ static int kdb_bc(int argc, const char **argv)
460460

461461
break;
462462
case KDBCMD_BE:
463+
if (bp->bp_enabled)
464+
break;
465+
463466
bp->bp_enabled = 1;
464467

465468
kdb_printf("Breakpoint %d at "
466-
kdb_bfd_vma_fmt " enabled",
469+
kdb_bfd_vma_fmt " enabled\n",
467470
i, bp->bp_addr);
468471

469-
kdb_printf("\n");
470472
break;
471473
case KDBCMD_BD:
472474
if (!bp->bp_enabled)

kernel/debug/kdb/kdb_keyboard.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#define KBD_STAT_OBF 0x01 /* Keyboard output buffer full */
2626
#define KBD_STAT_MOUSE_OBF 0x20 /* Mouse output buffer full */
2727

28+
#define CTRL(c) ((c) - 64)
29+
2830
static int kbd_exists;
2931
static int kbd_last_ret;
3032

@@ -123,24 +125,24 @@ int kdb_get_kbd_char(void)
123125
return 8;
124126
}
125127

126-
/* Special Key */
128+
/* Translate special keys to equivalent CTRL control characters */
127129
switch (scancode) {
128130
case 0xF: /* Tab */
129-
return 9;
131+
return CTRL('I');
130132
case 0x53: /* Del */
131-
return 4;
133+
return CTRL('D');
132134
case 0x47: /* Home */
133-
return 1;
135+
return CTRL('A');
134136
case 0x4F: /* End */
135-
return 5;
137+
return CTRL('E');
136138
case 0x4B: /* Left */
137-
return 2;
139+
return CTRL('B');
138140
case 0x48: /* Up */
139-
return 16;
141+
return CTRL('P');
140142
case 0x50: /* Down */
141-
return 14;
143+
return CTRL('N');
142144
case 0x4D: /* Right */
143-
return 6;
145+
return CTRL('F');
144146
}
145147

146148
if (scancode == 0xe0)
@@ -172,6 +174,19 @@ int kdb_get_kbd_char(void)
172174
switch (KTYP(keychar)) {
173175
case KT_LETTER:
174176
case KT_LATIN:
177+
switch (keychar) {
178+
/* non-printable supported control characters */
179+
case CTRL('A'): /* Home */
180+
case CTRL('B'): /* Left */
181+
case CTRL('D'): /* Del */
182+
case CTRL('E'): /* End */
183+
case CTRL('F'): /* Right */
184+
case CTRL('I'): /* Tab */
185+
case CTRL('N'): /* Down */
186+
case CTRL('P'): /* Up */
187+
return keychar;
188+
}
189+
175190
if (isprint(keychar))
176191
break; /* printable characters */
177192
fallthrough;

kernel/debug/kdb/kdb_main.c

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ static int kdbgetulenv(const char *match, unsigned long *value)
306306
return KDB_NOTENV;
307307
if (strlen(ep) == 0)
308308
return KDB_NOENVVALUE;
309-
310-
*value = simple_strtoul(ep, NULL, 0);
309+
if (kstrtoul(ep, 0, value))
310+
return KDB_BADINT;
311311

312312
return 0;
313313
}
@@ -402,42 +402,15 @@ static void kdb_printenv(void)
402402
*/
403403
int kdbgetularg(const char *arg, unsigned long *value)
404404
{
405-
char *endp;
406-
unsigned long val;
407-
408-
val = simple_strtoul(arg, &endp, 0);
409-
410-
if (endp == arg) {
411-
/*
412-
* Also try base 16, for us folks too lazy to type the
413-
* leading 0x...
414-
*/
415-
val = simple_strtoul(arg, &endp, 16);
416-
if (endp == arg)
417-
return KDB_BADINT;
418-
}
419-
420-
*value = val;
421-
405+
if (kstrtoul(arg, 0, value))
406+
return KDB_BADINT;
422407
return 0;
423408
}
424409

425410
int kdbgetu64arg(const char *arg, u64 *value)
426411
{
427-
char *endp;
428-
u64 val;
429-
430-
val = simple_strtoull(arg, &endp, 0);
431-
432-
if (endp == arg) {
433-
434-
val = simple_strtoull(arg, &endp, 16);
435-
if (endp == arg)
436-
return KDB_BADINT;
437-
}
438-
439-
*value = val;
440-
412+
if (kstrtou64(arg, 0, value))
413+
return KDB_BADINT;
441414
return 0;
442415
}
443416

@@ -473,10 +446,10 @@ int kdb_set(int argc, const char **argv)
473446
*/
474447
if (strcmp(argv[1], "KDBDEBUG") == 0) {
475448
unsigned int debugflags;
476-
char *cp;
449+
int ret;
477450

478-
debugflags = simple_strtoul(argv[2], &cp, 0);
479-
if (cp == argv[2] || debugflags & ~KDB_DEBUG_FLAG_MASK) {
451+
ret = kstrtouint(argv[2], 0, &debugflags);
452+
if (ret || debugflags & ~KDB_DEBUG_FLAG_MASK) {
480453
kdb_printf("kdb: illegal debug flags '%s'\n",
481454
argv[2]);
482455
return 0;
@@ -1619,10 +1592,10 @@ static int kdb_md(int argc, const char **argv)
16191592
if (!argv[0][3])
16201593
valid = 1;
16211594
else if (argv[0][3] == 'c' && argv[0][4]) {
1622-
char *p;
1623-
repeat = simple_strtoul(argv[0] + 4, &p, 10);
1595+
if (kstrtouint(argv[0] + 4, 10, &repeat))
1596+
return KDB_BADINT;
16241597
mdcount = ((repeat * bytesperword) + 15) / 16;
1625-
valid = !*p;
1598+
valid = 1;
16261599
}
16271600
last_repeat = repeat;
16281601
} else if (strcmp(argv[0], "md") == 0)
@@ -2083,15 +2056,10 @@ static int kdb_dmesg(int argc, const char **argv)
20832056
if (argc > 2)
20842057
return KDB_ARGCOUNT;
20852058
if (argc) {
2086-
char *cp;
2087-
lines = simple_strtol(argv[1], &cp, 0);
2088-
if (*cp)
2059+
if (kstrtoint(argv[1], 0, &lines))
20892060
lines = 0;
2090-
if (argc > 1) {
2091-
adjust = simple_strtoul(argv[2], &cp, 0);
2092-
if (*cp || adjust < 0)
2093-
adjust = 0;
2094-
}
2061+
if (argc > 1 && (kstrtoint(argv[2], 0, &adjust) || adjust < 0))
2062+
adjust = 0;
20952063
}
20962064

20972065
/* disable LOGGING if set */
@@ -2428,23 +2396,20 @@ static int kdb_help(int argc, const char **argv)
24282396
static int kdb_kill(int argc, const char **argv)
24292397
{
24302398
long sig, pid;
2431-
char *endp;
24322399
struct task_struct *p;
24332400

24342401
if (argc != 2)
24352402
return KDB_ARGCOUNT;
24362403

2437-
sig = simple_strtol(argv[1], &endp, 0);
2438-
if (*endp)
2404+
if (kstrtol(argv[1], 0, &sig))
24392405
return KDB_BADINT;
24402406
if ((sig >= 0) || !valid_signal(-sig)) {
24412407
kdb_printf("Invalid signal parameter.<-signal>\n");
24422408
return 0;
24432409
}
24442410
sig = -sig;
24452411

2446-
pid = simple_strtol(argv[2], &endp, 0);
2447-
if (*endp)
2412+
if (kstrtol(argv[2], 0, &pid))
24482413
return KDB_BADINT;
24492414
if (pid <= 0) {
24502415
kdb_printf("Process ID must be large than 0.\n");

kernel/trace/trace_kdb.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,19 @@ static int kdb_ftdump(int argc, const char **argv)
9696
{
9797
int skip_entries = 0;
9898
long cpu_file;
99-
char *cp;
99+
int err;
100100
int cnt;
101101
int cpu;
102102

103103
if (argc > 2)
104104
return KDB_ARGCOUNT;
105105

106-
if (argc) {
107-
skip_entries = simple_strtol(argv[1], &cp, 0);
108-
if (*cp)
109-
skip_entries = 0;
110-
}
106+
if (argc && kstrtoint(argv[1], 0, &skip_entries))
107+
return KDB_BADINT;
111108

112109
if (argc == 2) {
113-
cpu_file = simple_strtol(argv[2], &cp, 0);
114-
if (*cp || cpu_file >= NR_CPUS || cpu_file < 0 ||
110+
err = kstrtol(argv[2], 0, &cpu_file);
111+
if (err || cpu_file >= NR_CPUS || cpu_file < 0 ||
115112
!cpu_online(cpu_file))
116113
return KDB_BADINT;
117114
} else {

0 commit comments

Comments
 (0)