Skip to content

Commit 8037072

Browse files
jimcgregkh
authored andcommitted
dyndbg: refactor parse_linerange out of ddebug_parse_query
Make the code-block reusable to later handle "file foo.c:101-200" etc. This is a 99% code move, with reindent, function wrap&call, +pr_debug. no functional changes. Acked-by: <[email protected]> Signed-off-by: Jim Cromie <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f62fc08 commit 8037072

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

lib/dynamic_debug.c

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,41 @@ static inline int parse_lineno(const char *str, unsigned int *val)
291291
return 0;
292292
}
293293

294+
static int parse_linerange(struct ddebug_query *query, const char *first)
295+
{
296+
char *last = strchr(first, '-');
297+
298+
if (query->first_lineno || query->last_lineno) {
299+
pr_err("match-spec: line used 2x\n");
300+
return -EINVAL;
301+
}
302+
if (last)
303+
*last++ = '\0';
304+
if (parse_lineno(first, &query->first_lineno) < 0)
305+
return -EINVAL;
306+
if (last) {
307+
/* range <first>-<last> */
308+
if (parse_lineno(last, &query->last_lineno) < 0)
309+
return -EINVAL;
310+
311+
/* special case for last lineno not specified */
312+
if (query->last_lineno == 0)
313+
query->last_lineno = UINT_MAX;
314+
315+
if (query->last_lineno < query->first_lineno) {
316+
pr_err("last-line:%d < 1st-line:%d\n",
317+
query->last_lineno,
318+
query->first_lineno);
319+
return -EINVAL;
320+
}
321+
} else {
322+
query->last_lineno = query->first_lineno;
323+
}
324+
vpr_info("parsed line %d-%d\n", query->first_lineno,
325+
query->last_lineno);
326+
return 0;
327+
}
328+
294329
static int check_set(const char **dest, char *src, char *name)
295330
{
296331
int rc = 0;
@@ -348,34 +383,8 @@ static int ddebug_parse_query(char *words[], int nwords,
348383
UNESCAPE_SPECIAL);
349384
rc = check_set(&query->format, words[i+1], "format");
350385
} else if (!strcmp(words[i], "line")) {
351-
char *first = words[i+1];
352-
char *last = strchr(first, '-');
353-
if (query->first_lineno || query->last_lineno) {
354-
pr_err("match-spec: line used 2x\n");
355-
return -EINVAL;
356-
}
357-
if (last)
358-
*last++ = '\0';
359-
if (parse_lineno(first, &query->first_lineno) < 0)
386+
if (parse_linerange(query, words[i+1]))
360387
return -EINVAL;
361-
if (last) {
362-
/* range <first>-<last> */
363-
if (parse_lineno(last, &query->last_lineno) < 0)
364-
return -EINVAL;
365-
366-
/* special case for last lineno not specified */
367-
if (query->last_lineno == 0)
368-
query->last_lineno = UINT_MAX;
369-
370-
if (query->last_lineno < query->first_lineno) {
371-
pr_err("last-line:%d < 1st-line:%d\n",
372-
query->last_lineno,
373-
query->first_lineno);
374-
return -EINVAL;
375-
}
376-
} else {
377-
query->last_lineno = query->first_lineno;
378-
}
379388
} else {
380389
pr_err("unknown keyword \"%s\"\n", words[i]);
381390
return -EINVAL;

0 commit comments

Comments
 (0)