kernel: bump 4.9 to 4.9.77
[openwrt/openwrt.git] / target / linux / sunxi / patches-4.9 / 0036-pinctrl-sunxi-Free-configs-in-pinctrl_map-only-if-it.patch
1 From 88f01a1bd0e0dbd01b65907023dbe53cf524ea2a Mon Sep 17 00:00:00 2001
2 From: Chen-Yu Tsai <wens@csie.org>
3 Date: Fri, 11 Nov 2016 10:35:10 +0800
4 Subject: pinctrl: sunxi: Free configs in pinctrl_map only if it is a config
5 map
6
7 In the recently refactored sunxi pinctrl library, we are only allocating
8 one set of pin configs for each pinmux setting node. When the pinctrl_map
9 structure is freed, the pin configs should also be freed. However the
10 code assumed the first map would contain the configs, which actually
11 never happens, as the mux function map gets added first.
12
13 The proper way to do this is to look through all the maps and free the
14 first one whose type is actually PIN_MAP_TYPE_CONFIGS_GROUP.
15
16 Also slightly expand the comment explaining this.
17
18 Fixes: f233dbca6227 ("pinctrl: sunxi: Rework the pin config building code")
19 Signed-off-by: Chen-Yu Tsai <wens@csie.org>
20 Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
21 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
22 ---
23 drivers/pinctrl/sunxi/pinctrl-sunxi.c | 17 +++++++++++++++--
24 1 file changed, 15 insertions(+), 2 deletions(-)
25
26 --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
27 +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
28 @@ -408,8 +408,21 @@ static void sunxi_pctrl_dt_free_map(stru
29 struct pinctrl_map *map,
30 unsigned num_maps)
31 {
32 - /* All the maps have the same pin config, free only the first one */
33 - kfree(map[0].data.configs.configs);
34 + int i;
35 +
36 + /* pin config is never in the first map */
37 + for (i = 1; i < num_maps; i++) {
38 + if (map[i].type != PIN_MAP_TYPE_CONFIGS_GROUP)
39 + continue;
40 +
41 + /*
42 + * All the maps share the same pin config,
43 + * free only the first one we find.
44 + */
45 + kfree(map[i].data.configs.configs);
46 + break;
47 + }
48 +
49 kfree(map);
50 }
51