Move flag-char reading and validating code to a separate function.

This will allow later reuse to read 2 sets of flags:

  1- flags to set or clear (after the [=-+] Operator)
  2- flags to require or prohibit before changing a callsite's flagstate

Signed-off-by: Jim Cromie <jim.cro...@gmail.com>
---
 lib/dynamic_debug.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 22335f7dbac1..8400e4f90b67 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -430,6 +430,26 @@ static int ddebug_parse_query(char *words[], int nwords,
        return 0;
 }
 
+static int ddebug_read_flags(const char *str, struct flag_settings *modifiers)
+{
+       int i;
+
+       for (; *str ; ++str) {
+               for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
+                       if (*str == opt_array[i].opt_char) {
+                               modifiers->flags |= opt_array[i].flag;
+                               break;
+                       }
+               }
+               if (i < 0) {
+                       pr_err("unknown flag '%c'\n", *str);
+                       return -EINVAL;
+               }
+       }
+       vpr_info("flags=0x%x\n", modifiers->flags);
+       return 0;
+}
+
 /*
  * Parse `str' as a flags specification, format [-+=][p]+.
  * Sets up *maskp and *flagsp to be used when changing the
@@ -438,7 +458,7 @@ static int ddebug_parse_query(char *words[], int nwords,
  */
 static int ddebug_parse_flags(const char *str, struct flag_settings *modifiers)
 {
-       int op, i;
+       int op;
 
        switch (*str) {
        case '+':
@@ -452,19 +472,8 @@ static int ddebug_parse_flags(const char *str, struct 
flag_settings *modifiers)
        }
        vpr_info("op='%c'\n", op);
 
-       for (; *str ; ++str) {
-               for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
-                       if (*str == opt_array[i].opt_char) {
-                               modifiers->flags |= opt_array[i].flag;
-                               break;
-                       }
-               }
-               if (i < 0) {
-                       pr_err("unknown flag '%c'\n", *str);
-                       return -EINVAL;
-               }
-       }
-       vpr_info("flags=0x%x\n", modifiers->flags);
+       if (ddebug_read_flags(str, modifiers))
+               return -EINVAL;
 
        /* calculate final flags, mask based upon op */
        switch (op) {
-- 
2.26.2

Reply via email to