Skip to content

Commit d338b13

Browse files
andy-shevtorvalds
authored andcommitted
dynamic_debug: reuse generic string_unescape function
There is kernel function to do the job in generic way. Let's use it. Signed-off-by: Andy Shevchenko <[email protected]> Cc: Jason Baron <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 576d742 commit d338b13

File tree

1 file changed

+5
-43
lines changed

1 file changed

+5
-43
lines changed

lib/dynamic_debug.c

+5-43
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/sysctl.h>
2525
#include <linux/ctype.h>
2626
#include <linux/string.h>
27+
#include <linux/string_helpers.h>
2728
#include <linux/uaccess.h>
2829
#include <linux/dynamic_debug.h>
2930
#include <linux/debugfs.h>
@@ -276,47 +277,6 @@ static inline int parse_lineno(const char *str, unsigned int *val)
276277
return 0;
277278
}
278279

279-
/*
280-
* Undo octal escaping in a string, inplace. This is useful to
281-
* allow the user to express a query which matches a format
282-
* containing embedded spaces.
283-
*/
284-
static char *unescape(char *str)
285-
{
286-
char *in = str;
287-
char *out = str;
288-
289-
while (*in) {
290-
if (*in == '\\') {
291-
if (in[1] == '\\') {
292-
*out++ = '\\';
293-
in += 2;
294-
continue;
295-
} else if (in[1] == 't') {
296-
*out++ = '\t';
297-
in += 2;
298-
continue;
299-
} else if (in[1] == 'n') {
300-
*out++ = '\n';
301-
in += 2;
302-
continue;
303-
} else if (isodigit(in[1]) &&
304-
isodigit(in[2]) &&
305-
isodigit(in[3])) {
306-
*out++ = (((in[1] - '0') << 6) |
307-
((in[2] - '0') << 3) |
308-
(in[3] - '0'));
309-
in += 4;
310-
continue;
311-
}
312-
}
313-
*out++ = *in++;
314-
}
315-
*out = '\0';
316-
317-
return str;
318-
}
319-
320280
static int check_set(const char **dest, char *src, char *name)
321281
{
322282
int rc = 0;
@@ -370,8 +330,10 @@ static int ddebug_parse_query(char *words[], int nwords,
370330
} else if (!strcmp(words[i], "module")) {
371331
rc = check_set(&query->module, words[i+1], "module");
372332
} else if (!strcmp(words[i], "format")) {
373-
rc = check_set(&query->format, unescape(words[i+1]),
374-
"format");
333+
string_unescape_inplace(words[i+1], UNESCAPE_SPACE |
334+
UNESCAPE_OCTAL |
335+
UNESCAPE_SPECIAL);
336+
rc = check_set(&query->format, words[i+1], "format");
375337
} else if (!strcmp(words[i], "line")) {
376338
char *first = words[i+1];
377339
char *last = strchr(first, '-');

0 commit comments

Comments
 (0)