Skip to content

Commit fd89cfb

Browse files
watologo1gregkh
authored andcommitted
Dynamic Debug: Split out query string parsing/setup from proc_write
The parsing and applying of dynamic debug strings is not only useful for /sys/../dynamic_debug/control write access, but can also be used for boot parameter parsing. The boot parameter is introduced in a follow up patch. Signed-off-by: Thomas Renninger <trenn@suse.de> Acked-by: jbaron@redhat.com Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent f6f94e2 commit fd89cfb

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

‎lib/dynamic_debug.c‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -429,19 +429,36 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
429429
return 0;
430430
}
431431

432+
static int ddebug_exec_query(char *query_string)
433+
{
434+
unsigned int flags = 0, mask = 0;
435+
struct ddebug_query query;
436+
#define MAXWORDS 9
437+
int nwords;
438+
char *words[MAXWORDS];
439+
440+
nwords = ddebug_tokenize(query_string, words, MAXWORDS);
441+
if (nwords <= 0)
442+
return -EINVAL;
443+
if (ddebug_parse_query(words, nwords-1, &query))
444+
return -EINVAL;
445+
if (ddebug_parse_flags(words[nwords-1], &flags, &mask))
446+
return -EINVAL;
447+
448+
/* actually go and implement the change */
449+
ddebug_change(&query, flags, mask);
450+
return 0;
451+
}
452+
432453
/*
433454
* File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the
434455
* command text from userspace, parses and executes it.
435456
*/
436457
static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
437458
size_t len, loff_t *offp)
438459
{
439-
unsigned int flags = 0, mask = 0;
440-
struct ddebug_query query;
441-
#define MAXWORDS 9
442-
int nwords;
443-
char *words[MAXWORDS];
444460
char tmpbuf[256];
461+
int ret;
445462

446463
if (len == 0)
447464
return 0;
@@ -455,16 +472,9 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
455472
printk(KERN_INFO "%s: read %d bytes from userspace\n",
456473
__func__, (int)len);
457474

458-
nwords = ddebug_tokenize(tmpbuf, words, MAXWORDS);
459-
if (nwords <= 0)
460-
return -EINVAL;
461-
if (ddebug_parse_query(words, nwords-1, &query))
462-
return -EINVAL;
463-
if (ddebug_parse_flags(words[nwords-1], &flags, &mask))
464-
return -EINVAL;
465-
466-
/* actually go and implement the change */
467-
ddebug_change(&query, flags, mask);
475+
ret = ddebug_exec_query(tmpbuf);
476+
if (ret)
477+
return ret;
468478

469479
*offp += len;
470480
return len;

0 commit comments

Comments
 (0)