Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf config: Do not die when parsing u64 or int config values

Just warn the user and ignore those values.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-tbf60nj3ierm6hrkhpothymx@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+34 -24
+4 -1
tools/perf/builtin-diff.c
··· 1302 1302 void *cb __maybe_unused) 1303 1303 { 1304 1304 if (!strcmp(var, "diff.order")) { 1305 - sort_compute = perf_config_int(var, value); 1305 + int ret; 1306 + if (perf_config_int(&ret, var, value) < 0) 1307 + return -1; 1308 + sort_compute = ret; 1306 1309 return 0; 1307 1310 } 1308 1311 if (!strcmp(var, "diff.compute")) {
+3 -4
tools/perf/builtin-report.c
··· 94 94 symbol_conf.cumulate_callchain = perf_config_bool(var, value); 95 95 return 0; 96 96 } 97 - if (!strcmp(var, "report.queue-size")) { 98 - rep->queue_size = perf_config_u64(var, value); 99 - return 0; 100 - } 97 + if (!strcmp(var, "report.queue-size")) 98 + return perf_config_u64(&rep->queue_size, var, value); 99 + 101 100 if (!strcmp(var, "report.sort_order")) { 102 101 default_sort_order = strdup(value); 103 102 return 0;
+22 -12
tools/perf/util/config.c
··· 335 335 return 0; 336 336 } 337 337 338 - static void die_bad_config(const char *name) 338 + static void bad_config(const char *name) 339 339 { 340 340 if (config_file_name) 341 - die("bad config value for '%s' in %s", name, config_file_name); 342 - die("bad config value for '%s'", name); 341 + pr_warning("bad config value for '%s' in %s, ignoring...\n", name, config_file_name); 342 + else 343 + pr_warning("bad config value for '%s', ignoring...\n", name); 343 344 } 344 345 345 - u64 perf_config_u64(const char *name, const char *value) 346 + int perf_config_u64(u64 *dest, const char *name, const char *value) 346 347 { 347 348 long long ret = 0; 348 349 349 - if (!perf_parse_llong(value, &ret)) 350 - die_bad_config(name); 351 - return (u64) ret; 350 + if (!perf_parse_llong(value, &ret)) { 351 + bad_config(name); 352 + return -1; 353 + } 354 + 355 + *dest = ret; 356 + return 0; 352 357 } 353 358 354 - int perf_config_int(const char *name, const char *value) 359 + int perf_config_int(int *dest, const char *name, const char *value) 355 360 { 356 361 long ret = 0; 357 - if (!perf_parse_long(value, &ret)) 358 - die_bad_config(name); 359 - return ret; 362 + if (!perf_parse_long(value, &ret)) { 363 + bad_config(name); 364 + return -1; 365 + } 366 + *dest = ret; 367 + return 0; 360 368 } 361 369 362 370 static int perf_config_bool_or_int(const char *name, const char *value, int *is_bool) 363 371 { 372 + int ret; 373 + 364 374 *is_bool = 1; 365 375 if (!value) 366 376 return 1; ··· 381 371 if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off")) 382 372 return 0; 383 373 *is_bool = 0; 384 - return perf_config_int(name, value); 374 + return perf_config_int(&ret, name, value) < 0 ? -1 : ret; 385 375 } 386 376 387 377 int perf_config_bool(const char *name, const char *value)
+2 -2
tools/perf/util/config.h
··· 27 27 typedef int (*config_fn_t)(const char *, const char *, void *); 28 28 int perf_default_config(const char *, const char *, void *); 29 29 int perf_config(config_fn_t fn, void *); 30 - int perf_config_int(const char *, const char *); 31 - u64 perf_config_u64(const char *, const char *); 30 + int perf_config_int(int *dest, const char *, const char *); 31 + int perf_config_u64(u64 *dest, const char *, const char *); 32 32 int perf_config_bool(const char *, const char *); 33 33 int config_error_nonbool(const char *); 34 34 const char *perf_etc_perfconfig(void);
+2 -4
tools/perf/util/data-convert-bt.c
··· 1444 1444 { 1445 1445 struct convert *c = cb; 1446 1446 1447 - if (!strcmp(var, "convert.queue-size")) { 1448 - c->queue_size = perf_config_u64(var, value); 1449 - return 0; 1450 - } 1447 + if (!strcmp(var, "convert.queue-size")) 1448 + return perf_config_u64(&c->queue_size, var, value); 1451 1449 1452 1450 return 0; 1453 1451 }
+1 -1
tools/perf/util/help-unknown-cmd.c
··· 12 12 void *cb __maybe_unused) 13 13 { 14 14 if (!strcmp(var, "help.autocorrect")) 15 - autocorrect = perf_config_int(var,value); 15 + return perf_config_int(&autocorrect, var,value); 16 16 17 17 return 0; 18 18 }