staging: mt7621-pinctrl: use pinconf-generic for 'dt_node_to_map' and 'dt_free_map'
authorSergio Paracuellos <sergio.paracuellos@gmail.com>
Fri, 4 Jan 2019 11:34:08 +0000 (12:34 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 7 Jan 2019 10:28:13 +0000 (11:28 +0100)
Instead of reimplement afunction to do 'dt_node_to_map' task like
'rt2880_pinctrl_dt_node_to_map' make use of 'pinconf_generic_dt_node_to_map_all'
generic function for this task. Also use its equivalent function for free which
is 'pinconf_generic_dt_free_map'. Remove 'rt2880_pinctrl_dt_node_to_map' function
which is not needed anymore. This decrease a bit driver LOC and make it more
generic. To properly compile this changes 'GENERIC_PINCONF' option is selected
with the driver in its Kconfig file.

This also fix a problem with function 'rt2880_pinctrl_dt_node_to_map' which was
calling internally 'pinctrl_utils_reserve_map' which expects 'num_maps' to be initialized.
It does a memory allocation based on the value, and triggers the following
warning if is not properly set:

if (unlikely(order >= MAX_ORDER)) {
        WARN_ON_ONCE(!(gfp_mask & __GFP_NOWARN));
        return NULL;
}

Generic function 'pinconf_generic_dt_node_to_map_all' initializes properly
'num_maps' to zero fixing the problem.

Fixes: e12a1a6e087b ("staging: mt7621-pinctrl: refactor rt2880_pinctrl_dt_node_to_map function")
Reported-by: NeilBrown <neil@brown.name>
Tested-by: NeilBrown <neil@brown.name>
Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/mt7621-pinctrl/Kconfig
drivers/staging/mt7621-pinctrl/pinctrl-rt2880.c

index 37cf9c3273bebca6b157ff301563709badde200d..fc361271130729cf8c21548fee9ab048c2e47aec 100644 (file)
@@ -2,3 +2,4 @@ config PINCTRL_RT2880
        bool "RT2800 pinctrl driver for RALINK/Mediatek SOCs"
        depends on RALINK
        select PINMUX
+       select GENERIC_PINCONF
index aa98fbb170139ef7ba443d80ae2c8da72e9a4357..80e7067cfb797a3361148137b53f513a02fc3e0b 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/of.h>
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinconf.h>
+#include <linux/pinctrl/pinconf-generic.h>
 #include <linux/pinctrl/pinmux.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/pinctrl/machine.h>
@@ -73,48 +74,12 @@ static int rt2880_get_group_pins(struct pinctrl_dev *pctrldev,
        return 0;
 }
 
-static int rt2880_pinctrl_dt_node_to_map(struct pinctrl_dev *pctrldev,
-                                        struct device_node *np_config,
-                                        struct pinctrl_map **map,
-                                        unsigned int *num_maps)
-{
-       struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev);
-       struct property *prop;
-       const char *function_name, *group_name;
-       int ret;
-       int ngroups = 0;
-       unsigned int reserved_maps = 0;
-
-       for_each_node_with_property(np_config, "group")
-               ngroups++;
-
-       *map = NULL;
-       ret = pinctrl_utils_reserve_map(pctrldev, map, &reserved_maps,
-                                       num_maps, ngroups);
-       if (ret) {
-               dev_err(p->dev, "can't reserve map: %d\n", ret);
-               return ret;
-       }
-
-       of_property_for_each_string(np_config, "group", prop, group_name) {
-               ret = pinctrl_utils_add_map_mux(pctrldev, map, &reserved_maps,
-                                               num_maps, group_name,
-                                               function_name);
-               if (ret) {
-                       dev_err(p->dev, "can't add map: %d\n", ret);
-                       return ret;
-               }
-       }
-
-       return 0;
-}
-
 static const struct pinctrl_ops rt2880_pctrl_ops = {
        .get_groups_count       = rt2880_get_group_count,
        .get_group_name         = rt2880_get_group_name,
        .get_group_pins         = rt2880_get_group_pins,
-       .dt_node_to_map         = rt2880_pinctrl_dt_node_to_map,
-       .dt_free_map            = pinctrl_utils_free_map,
+       .dt_node_to_map         = pinconf_generic_dt_node_to_map_all,
+       .dt_free_map            = pinconf_generic_dt_free_map,
 };
 
 static int rt2880_pmx_func_count(struct pinctrl_dev *pctrldev)