Since array types are handled differently, errors referencing them also need to be handled differently. Add and use a new INVALID_ARRAY_SPEC error. Also add INVALID_CMD and INVALID_DYN_CMD to catch and display the correct form for badly-formed commands, which can also be used in place of CMD_INCOMPLETE, which is removed, and remove CMD_TOO_LONG, since it's no longer used. Link: https://lkml.kernel.org/r/b9dd434dc6458dcff11adc6ed616fe93a8794770.1612208610.git.zanussi@kernel.org
Showing the changes to kernel (1 of 1 file). Show all
Unified · Split
| @@ -23,13 +23,14 @@ · 22 unmodified lines | ||
| 23 | 23 | #undef ERRORS |
| 24 | 24 | #define ERRORS \ |
| 25 | 25 | C(BAD_NAME, "Illegal name"), \ |
| 26 | − C(CMD_INCOMPLETE, "Incomplete command"), \ | |
| 26 | + C(INVALID_CMD, "Command must be of the form: <name> field[;field] ..."),\ | |
| 27 | + C(INVALID_DYN_CMD, "Command must be of the form: s or -:[synthetic/]<name> field[;field] ..."),\ | |
| 27 | 28 | C(EVENT_EXISTS, "Event already exists"), \ |
| 28 | 29 | C(TOO_MANY_FIELDS, "Too many fields"), \ |
| 29 | 30 | C(INCOMPLETE_TYPE, "Incomplete type"), \ |
| 30 | 31 | C(INVALID_TYPE, "Invalid type"), \ |
| 31 | − C(INVALID_FIELD, "Invalid field"), \ | |
| 32 | − C(CMD_TOO_LONG, "Command too long"), | |
| 32 | + C(INVALID_FIELD, "Invalid field"), \ | |
| 33 | + C(INVALID_ARRAY_SPEC, "Invalid array specification"), | |
| 33 | 34 | |
| 34 | 35 | #undef C |
| 35 | 36 | #define C(a, b) SYNTH_ERR_##a |
| @@ -655,7 +656,10 @@ static struct synth_field *parse_synth_field(int argc, char **argv) · 619 unmodified lines | ||
| 655 | 656 | |
| 656 | 657 | size = synth_field_size(field->type); |
| 657 | 658 | if (size < 0) { |
| 658 | − synth_err(SYNTH_ERR_INVALID_TYPE, errpos(field_type)); | |
| 659 | + if (array) | |
| 660 | + synth_err(SYNTH_ERR_INVALID_ARRAY_SPEC, errpos(field_name)); | |
| 661 | + else | |
| 662 | + synth_err(SYNTH_ERR_INVALID_TYPE, errpos(field_type)); | |
| 659 | 663 | ret = -EINVAL; |
| 660 | 664 | goto free; |
| 661 | 665 | } else if (size == 0) { |
| @@ -1174,7 +1178,7 @@ static int __create_synth_event(const char *name, const char *raw_fields) · 512 unmodified lines | ||
| 1174 | 1178 | */ |
| 1175 | 1179 | |
| 1176 | 1180 | if (name[0] == '\0') { |
| 1177 | − synth_err(SYNTH_ERR_CMD_INCOMPLETE, 0); | |
| 1181 | + synth_err(SYNTH_ERR_INVALID_CMD, 0); | |
| 1178 | 1182 | return -EINVAL; |
| 1179 | 1183 | } |
| 1180 | 1184 | |
| @@ -1226,7 +1230,7 @@ static int __create_synth_event(const char *name, const char *raw_fields) · 45 unmodified lines | ||
| 1226 | 1230 | } |
| 1227 | 1231 | |
| 1228 | 1232 | if (n_fields == 0) { |
| 1229 | − synth_err(SYNTH_ERR_CMD_INCOMPLETE, 0); | |
| 1233 | + synth_err(SYNTH_ERR_INVALID_CMD, 0); | |
| 1230 | 1234 | ret = -EINVAL; |
| 1231 | 1235 | goto err; |
| 1232 | 1236 | } |
| @@ -1410,13 +1414,13 @@ static int create_or_delete_synth_event(const char *raw_command) · 177 unmodified lines | ||
| 1410 | 1414 | |
| 1411 | 1415 | ret = check_command(raw_command); |
| 1412 | 1416 | if (ret) { |
| 1413 | − synth_err(SYNTH_ERR_CMD_INCOMPLETE, 0); | |
| 1417 | + synth_err(SYNTH_ERR_INVALID_CMD, 0); | |
| 1414 | 1418 | return ret; |
| 1415 | 1419 | } |
| 1416 | 1420 | |
| 1417 | 1421 | p = strpbrk(raw_command, " \t"); |
| 1418 | 1422 | if (!p && raw_command[0] != '!') { |
| 1419 | − synth_err(SYNTH_ERR_CMD_INCOMPLETE, 0); | |
| 1423 | + synth_err(SYNTH_ERR_INVALID_CMD, 0); | |
| 1420 | 1424 | ret = -EINVAL; |
| 1421 | 1425 | goto free; |
| 1422 | 1426 | } |
| @@ -1993,8 +1997,10 @@ static int create_synth_event(const char *raw_command) · 570 unmodified lines | ||
| 1993 | 1997 | last_cmd_set(raw_command); |
| 1994 | 1998 | |
| 1995 | 1999 | p = strpbrk(raw_command, " \t"); |
| 1996 | − if (!p) | |
| 2000 | + if (!p) { | |
| 2001 | + synth_err(SYNTH_ERR_INVALID_CMD, 0); | |
| 1997 | 2002 | return -EINVAL; |
| 2003 | + } | |
| 1998 | 2004 | |
| 1999 | 2005 | fields = skip_spaces(p); |
| 2000 | 2006 | |
| @@ -2007,8 +2013,10 @@ static int create_synth_event(const char *raw_command) · 6 unmodified lines | ||
| 2007 | 2013 | /* This interface accepts group name prefix */ |
| 2008 | 2014 | if (strchr(name, '/')) { |
| 2009 | 2015 | len = str_has_prefix(name, SYNTH_SYSTEM "/"); |
| 2010 | − if (len == 0) | |
| 2016 | + if (len == 0) { | |
| 2017 | + synth_err(SYNTH_ERR_INVALID_DYN_CMD, 0); | |
| 2011 | 2018 | return -EINVAL; |
| 2019 | + } | |
| 2012 | 2020 | name += len; |
| 2013 | 2021 | } |
| 2014 | 2022 | |
| @@ -2016,7 +2024,7 @@ static int create_synth_event(const char *raw_command) · 1 unmodified line | ||
| 2016 | 2024 | |
| 2017 | 2025 | ret = check_command(raw_command + len); |
| 2018 | 2026 | if (ret) { |
| 2019 | − synth_err(SYNTH_ERR_CMD_INCOMPLETE, 0); | |
| 2027 | + synth_err(SYNTH_ERR_INVALID_CMD, 0); | |
| 2020 | 2028 | return ret; |
| 2021 | 2029 | } |
| 2022 | 2030 | |