]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpiolib: swnode: Make use of for_each_gpio_property_name()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 19 Aug 2024 14:28:59 +0000 (17:28 +0300)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 20 Aug 2024 08:22:38 +0000 (10:22 +0200)
For the sake of unification and easier maintenance replace
swnode_format_propname() call with for_each_gpio_property_name()
for-loop.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240819142945.327808-5-andriy.shevchenko@linux.intel.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpiolib-swnode.c

index d5e58a9673b5aa5bd25dc5daf7337983d6ecc9f6..1a6f706718167f80ee4b2ba95581efa44bdedc83 100644 (file)
 
 #define GPIOLIB_SWNODE_UNDEFINED_NAME "swnode-gpio-undefined"
 
-static void swnode_format_propname(const char *con_id, char *propname,
-                                  size_t max_size)
-{
-       /*
-        * Note we do not need to try both -gpios and -gpio suffixes,
-        * as, unlike OF and ACPI, we can fix software nodes to conform
-        * to the proper binding.
-        */
-       if (con_id)
-               snprintf(propname, max_size, "%s-gpios", con_id);
-       else
-               strscpy(propname, "gpios", max_size);
-}
-
 static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode)
 {
        const struct software_node *gdev_node;
@@ -84,9 +70,11 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode,
        if (!swnode)
                return ERR_PTR(-EINVAL);
 
-       swnode_format_propname(con_id, propname, sizeof(propname));
-
-       ret = swnode_gpio_get_reference(fwnode, propname, idx, &args);
+       for_each_gpio_property_name(propname, con_id) {
+               ret = swnode_gpio_get_reference(fwnode, propname, idx, &args);
+               if (ret == 0)
+                       break;
+       }
        if (ret) {
                pr_debug("%s: can't parse '%s' property of node '%pfwP[%d]'\n",
                        __func__, propname, fwnode, idx);
@@ -128,19 +116,21 @@ int swnode_gpio_count(const struct fwnode_handle *fwnode, const char *con_id)
        char propname[32];
        int count;
 
-       swnode_format_propname(con_id, propname, sizeof(propname));
-
        /*
         * This is not very efficient, but GPIO lists usually have only
         * 1 or 2 entries.
         */
-       count = 0;
-       while (swnode_gpio_get_reference(fwnode, propname, count, &args) == 0) {
-               fwnode_handle_put(args.fwnode);
-               count++;
+       for_each_gpio_property_name(propname, con_id) {
+               count = 0;
+               while (swnode_gpio_get_reference(fwnode, propname, count, &args) == 0) {
+                       fwnode_handle_put(args.fwnode);
+                       count++;
+               }
+               if (count)
+                       return count;
        }
 
-       return count ?: -ENOENT;
+       return -ENOENT;
 }
 
 #if IS_ENABLED(CONFIG_GPIO_SWNODE_UNDEFINED)