]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
firmware: arm_scmi: Move boiler plate code into the get info functions
authorDan Carpenter <dan.carpenter@linaro.org>
Mon, 27 Oct 2025 15:16:06 +0000 (18:16 +0300)
committerSudeep Holla <sudeep.holla@arm.com>
Tue, 16 Dec 2025 12:27:26 +0000 (12:27 +0000)
This code to check whether the selector is valid and if the item has
already been recorded in the array can be moved to the
scmi_pinctrl_get_function_info() type functions.  That way it's in
one place instead of duplicated in each of the callers.

Remove the check for if "pi->nr_groups == 0" because if that were the
case then "selector >= pi->nr_groups" would already be true.  It already
was not checked for the pin case so this makes things a bit more uniform.

Also remove the check for if (!pin) since pin is an offset into the
middle of an array and can't be NULL.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>
Message-Id: <287b5302f583e3535d50617ec3b0856e38253171.1761576798.git.dan.carpenter@linaro.org>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
drivers/firmware/arm_scmi/pinctrl.c

index 3855c98caf06bd9b32043a42e6678791b71424f4..d18c2d248f042f2a9783c7a04eadbcaf80df244d 100644 (file)
@@ -596,11 +596,19 @@ static int scmi_pinctrl_pin_free(const struct scmi_protocol_handle *ph, u32 pin)
 }
 
 static int scmi_pinctrl_get_group_info(const struct scmi_protocol_handle *ph,
-                                      u32 selector,
-                                      struct scmi_group_info *group)
+                                      u32 selector)
 {
+       struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+       struct scmi_group_info *group;
        int ret;
 
+       if (selector >= pi->nr_groups)
+               return -EINVAL;
+
+       group = &pi->groups[selector];
+       if (group->present)
+               return 0;
+
        ret = scmi_pinctrl_attributes(ph, GROUP_TYPE, selector, group->name,
                                      &group->nr_pins);
        if (ret)
@@ -632,21 +640,14 @@ static int scmi_pinctrl_get_group_name(const struct scmi_protocol_handle *ph,
                                       u32 selector, const char **name)
 {
        struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+       int ret;
 
        if (!name)
                return -EINVAL;
 
-       if (selector >= pi->nr_groups || pi->nr_groups == 0)
-               return -EINVAL;
-
-       if (!pi->groups[selector].present) {
-               int ret;
-
-               ret = scmi_pinctrl_get_group_info(ph, selector,
-                                                 &pi->groups[selector]);
-               if (ret)
-                       return ret;
-       }
+       ret = scmi_pinctrl_get_group_info(ph, selector);
+       if (ret)
+               return ret;
 
        *name = pi->groups[selector].name;
 
@@ -658,21 +659,14 @@ static int scmi_pinctrl_group_pins_get(const struct scmi_protocol_handle *ph,
                                       u32 *nr_pins)
 {
        struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+       int ret;
 
        if (!pins || !nr_pins)
                return -EINVAL;
 
-       if (selector >= pi->nr_groups || pi->nr_groups == 0)
-               return -EINVAL;
-
-       if (!pi->groups[selector].present) {
-               int ret;
-
-               ret = scmi_pinctrl_get_group_info(ph, selector,
-                                                 &pi->groups[selector]);
-               if (ret)
-                       return ret;
-       }
+       ret = scmi_pinctrl_get_group_info(ph, selector);
+       if (ret)
+               return ret;
 
        *pins = pi->groups[selector].group_pins;
        *nr_pins = pi->groups[selector].nr_pins;
@@ -681,11 +675,19 @@ static int scmi_pinctrl_group_pins_get(const struct scmi_protocol_handle *ph,
 }
 
 static int scmi_pinctrl_get_function_info(const struct scmi_protocol_handle *ph,
-                                         u32 selector,
-                                         struct scmi_function_info *func)
+                                         u32 selector)
 {
+       struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+       struct scmi_function_info *func;
        int ret;
 
+       if (selector >= pi->nr_functions)
+               return -EINVAL;
+
+       func = &pi->functions[selector];
+       if (func->present)
+               return 0;
+
        ret = scmi_pinctrl_attributes(ph, FUNCTION_TYPE, selector, func->name,
                                      &func->nr_groups);
        if (ret)
@@ -716,21 +718,14 @@ static int scmi_pinctrl_get_function_name(const struct scmi_protocol_handle *ph,
                                          u32 selector, const char **name)
 {
        struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+       int ret;
 
        if (!name)
                return -EINVAL;
 
-       if (selector >= pi->nr_functions || pi->nr_functions == 0)
-               return -EINVAL;
-
-       if (!pi->functions[selector].present) {
-               int ret;
-
-               ret = scmi_pinctrl_get_function_info(ph, selector,
-                                                    &pi->functions[selector]);
-               if (ret)
-                       return ret;
-       }
+       ret = scmi_pinctrl_get_function_info(ph, selector);
+       if (ret)
+               return ret;
 
        *name = pi->functions[selector].name;
        return 0;
@@ -742,21 +737,14 @@ scmi_pinctrl_function_groups_get(const struct scmi_protocol_handle *ph,
                                 const u32 **groups)
 {
        struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+       int ret;
 
        if (!groups || !nr_groups)
                return -EINVAL;
 
-       if (selector >= pi->nr_functions || pi->nr_functions == 0)
-               return -EINVAL;
-
-       if (!pi->functions[selector].present) {
-               int ret;
-
-               ret = scmi_pinctrl_get_function_info(ph, selector,
-                                                    &pi->functions[selector]);
-               if (ret)
-                       return ret;
-       }
+       ret = scmi_pinctrl_get_function_info(ph, selector);
+       if (ret)
+               return ret;
 
        *groups = pi->functions[selector].groups;
        *nr_groups = pi->functions[selector].nr_groups;
@@ -771,13 +759,19 @@ static int scmi_pinctrl_mux_set(const struct scmi_protocol_handle *ph,
 }
 
 static int scmi_pinctrl_get_pin_info(const struct scmi_protocol_handle *ph,
-                                    u32 selector, struct scmi_pin_info *pin)
+                                    u32 selector)
 {
+       struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+       struct scmi_pin_info *pin;
        int ret;
 
-       if (!pin)
+       if (selector >= pi->nr_pins)
                return -EINVAL;
 
+       pin = &pi->pins[selector];
+       if (pin->present)
+               return 0;
+
        ret = scmi_pinctrl_attributes(ph, PIN_TYPE, selector, pin->name, NULL);
        if (ret)
                return ret;
@@ -790,20 +784,14 @@ static int scmi_pinctrl_get_pin_name(const struct scmi_protocol_handle *ph,
                                     u32 selector, const char **name)
 {
        struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+       int ret;
 
        if (!name)
                return -EINVAL;
 
-       if (selector >= pi->nr_pins)
-               return -EINVAL;
-
-       if (!pi->pins[selector].present) {
-               int ret;
-
-               ret = scmi_pinctrl_get_pin_info(ph, selector, &pi->pins[selector]);
-               if (ret)
-                       return ret;
-       }
+       ret = scmi_pinctrl_get_pin_info(ph, selector);
+       if (ret)
+               return ret;
 
        *name = pi->pins[selector].name;