kernel-fxtec-pro1x/drivers/pinctrl
Drew Fustini 8bf3b460bf pinctrl-single: fix pcs_parse_pinconf() return value
[ Upstream commit f46fe79ff1b65692a65266a5bec6dbe2bf7fc70f ]

This patch causes pcs_parse_pinconf() to return -ENOTSUPP when no
pinctrl_map is added.  The current behavior is to return 0 when
!PCS_HAS_PINCONF or !nconfs.  Thus pcs_parse_one_pinctrl_entry()
incorrectly assumes that a map was added and sets num_maps = 2.

Analysis:
=========
The function pcs_parse_one_pinctrl_entry() calls pcs_parse_pinconf()
if PCS_HAS_PINCONF is enabled.  The function pcs_parse_pinconf()
returns 0 to indicate there was no error and num_maps is then set to 2:

 980 static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
 981                                                 struct device_node *np,
 982                                                 struct pinctrl_map **map,
 983                                                 unsigned *num_maps,
 984                                                 const char **pgnames)
 985 {
<snip>
1053         (*map)->type = PIN_MAP_TYPE_MUX_GROUP;
1054         (*map)->data.mux.group = np->name;
1055         (*map)->data.mux.function = np->name;
1056
1057         if (PCS_HAS_PINCONF && function) {
1058                 res = pcs_parse_pinconf(pcs, np, function, map);
1059                 if (res)
1060                         goto free_pingroups;
1061                 *num_maps = 2;
1062         } else {
1063                 *num_maps = 1;
1064         }

However, pcs_parse_pinconf() will also return 0 if !PCS_HAS_PINCONF or
!nconfs.  I believe these conditions should indicate that no map was
added by returning -ENOTSUPP. Otherwise pcs_parse_one_pinctrl_entry()
will set num_maps = 2 even though no maps were successfully added, as
it does not reach "m++" on line 940:

 895 static int pcs_parse_pinconf(struct pcs_device *pcs, struct device_node *np,
 896                              struct pcs_function *func,
 897                              struct pinctrl_map **map)
 898
 899 {
 900         struct pinctrl_map *m = *map;
<snip>
 917         /* If pinconf isn't supported, don't parse properties in below. */
 918         if (!PCS_HAS_PINCONF)
 919                 return 0;
 920
 921         /* cacluate how much properties are supported in current node */
 922         for (i = 0; i < ARRAY_SIZE(prop2); i++) {
 923                 if (of_find_property(np, prop2[i].name, NULL))
 924                         nconfs++;
 925         }
 926         for (i = 0; i < ARRAY_SIZE(prop4); i++) {
 927                 if (of_find_property(np, prop4[i].name, NULL))
 928                         nconfs++;
 929         }
 930         if (!nconfs)
 919                 return 0;
 932
 933         func->conf = devm_kcalloc(pcs->dev,
 934                                   nconfs, sizeof(struct pcs_conf_vals),
 935                                   GFP_KERNEL);
 936         if (!func->conf)
 937                 return -ENOMEM;
 938         func->nconfs = nconfs;
 939         conf = &(func->conf[0]);
 940         m++;

This situtation will cause a boot failure [0] on the BeagleBone Black
(AM3358) when am33xx_pinmux node in arch/arm/boot/dts/am33xx-l4.dtsi
has compatible = "pinconf-single" instead of "pinctrl-single".

The patch fixes this issue by returning -ENOSUPP when !PCS_HAS_PINCONF
or !nconfs, so that pcs_parse_one_pinctrl_entry() will know that no
map was added.

Logic is also added to pcs_parse_one_pinctrl_entry() to distinguish
between -ENOSUPP and other errors.  In the case of -ENOSUPP, num_maps
is set to 1 as it is valid for pinconf to be enabled and a given pin
group to not any pinconf properties.

[0] https://lore.kernel.org/linux-omap/20200529175544.GA3766151@x1/

Fixes: 9dddb4df90 ("pinctrl: single: support generic pinconf")
Signed-off-by: Drew Fustini <drew@beagleboard.org>
Acked-by: Tony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/20200608125143.GA2789203@x1
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-08-19 08:15:02 +02:00
..
actions
aspeed
bcm pinctrl: iproc-gpio: Fix incorrect pinconf configurations 2020-01-27 14:51:12 +01:00
berlin
cirrus pinctrl: madera: Fix uninitialized variable bug in madera_mux_set_mux 2019-12-01 09:16:15 +01:00
freescale pinctrl: freescale: imx: Fix an error handling path in 'imx_pinctrl_probe()' 2020-06-25 15:33:01 +02:00
intel pinctrl: cherryview: Add missing spinlock usage in chv_gpio_irq_handler 2020-05-20 08:18:41 +02:00
mediatek pinctrl: mediatek: Update cur_mask in mask/mask ops 2019-07-21 09:03:11 +02:00
meson pinctrl: meson-gxl: fix GPIOX sdio pins 2020-03-18 07:14:22 +01:00
mvebu pinctrl: armada-37xx: Fix irq mask access in armada_37xx_irq_set_type() 2019-12-17 20:35:07 +01:00
nomadik
pxa
qcom pinctrl: qcom: ssbi-gpio: fix gpio-hog related boot issues 2019-12-13 08:51:26 +01:00
samsung pinctrl: samsung: Save/restore eint_mask over suspend for EINT_TYPE GPIOs 2020-06-22 09:05:27 +02:00
sh-pfc pinctrl: sh-pfc: sh7269: Fix CAN function GPIOs 2020-02-24 08:34:44 +01:00
sirf
spear
sprd pinctrl: sprd: Use define directive for sprd_pinconf_params values 2019-10-01 08:26:07 +02:00
stm32 pinctrl: stm32: fix memory leak issue 2019-12-05 09:21:35 +01:00
sunxi pinctrl: sunxi: Fix a memory leak in 'sunxi_pinctrl_build_state()' 2019-12-01 09:16:24 +01:00
tegra pinctrl: tegra: Fix write barrier placement in pmx_writel 2019-10-07 18:56:52 +02:00
ti pinctl: ti: iodelay: fix error checking on pinctrl_count_index_with_args call 2020-01-17 19:47:06 +01:00
uniphier
vt8500
zte pinctrl: zte: fix leaked of_node references 2019-05-31 06:46:09 -07:00
core.c pinctrl: core: Remove extra kref_get which blocks hogs being freed 2020-03-18 07:14:23 +01:00
core.h
devicetree.c pinctrl: devicetree: Avoid taking direct reference to device name string 2019-12-31 16:34:53 +01:00
devicetree.h
Kconfig
Makefile
pinconf-generic.c
pinconf.c
pinconf.h
pinctrl-amd.c pinctrl: amd: fix __iomem annotation in amd_gpio_irq_handler() 2019-12-31 16:35:35 +01:00
pinctrl-amd.h pinctrl: amd: fix npins for uart0 in kerncz_groups 2020-07-29 10:16:44 +02:00
pinctrl-artpec6.c
pinctrl-as3722.c
pinctrl-at91-pio4.c pinctrl: at91-pio4: fix has_config check in atmel_pctl_dt_subnode_to_map() 2019-11-20 18:46:35 +01:00
pinctrl-at91.c pinctrl: at91: don't use the same irqchip with multiple gpiochips 2019-11-20 18:46:41 +01:00
pinctrl-at91.h
pinctrl-axp209.c
pinctrl-coh901.c
pinctrl-coh901.h
pinctrl-da850-pupd.c
pinctrl-digicolor.c
pinctrl-falcon.c
pinctrl-gemini.c pinctrl: gemini: Fix up TVC clock group 2019-11-24 08:20:58 +01:00
pinctrl-ingenic.c pinctrl: ingenic: Probe driver at subsys_initcall 2019-11-20 18:45:34 +01:00
pinctrl-lantiq.c
pinctrl-lantiq.h
pinctrl-lpc18xx.c pinctrl: lpc18xx: Use define directive for PIN_CONFIG_GPIO_PIN_INT 2019-12-01 09:17:33 +01:00
pinctrl-max77620.c pinctrl: max77620: Use define directive for max77620_pinconf_param values 2019-02-27 10:09:03 +01:00
pinctrl-mcp23s08.c pinctrl: mcp23s08: Fix add_data and irqchip_add_nested call order 2019-07-21 09:03:08 +02:00
pinctrl-ocelot.c
pinctrl-oxnas.c
pinctrl-palmas.c
pinctrl-pic32.c
pinctrl-pic32.h
pinctrl-pistachio.c pinctrl: pistachio: fix leaked of_node references 2019-05-31 06:46:16 -07:00
pinctrl-rk805.c
pinctrl-rockchip.c pinctrl: rockchip: fix memleak in rockchip_dt_node_to_map 2020-06-25 15:32:56 +02:00
pinctrl-rza1.c pinctrl: rza1: Fix wrong array assignment of rza1l_swio_entries 2020-06-25 15:32:53 +02:00
pinctrl-single.c pinctrl-single: fix pcs_parse_pinconf() return value 2020-08-19 08:15:02 +02:00
pinctrl-st.c
pinctrl-sx150x.c
pinctrl-tb10x.c
pinctrl-u300.c
pinctrl-utils.c
pinctrl-utils.h
pinctrl-xway.c pinctrl: xway: fix gpio-hog related boot issues 2019-12-05 09:20:30 +01:00
pinctrl-zynq.c pinctrl: zynq: Use define directive for PIN_CONFIG_IO_STANDARD 2019-12-01 09:17:33 +01:00
pinmux.c
pinmux.h