linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: sunxi: Free configs in pinctrl_map only if it is a config map
@ 2016-11-11  2:35 Chen-Yu Tsai
  2016-11-11  8:29 ` Maxime Ripard
  2016-11-15  9:15 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Chen-Yu Tsai @ 2016-11-11  2:35 UTC (permalink / raw)
  To: Linus Walleij, Maxime Ripard
  Cc: Chen-Yu Tsai, linux-gpio, linux-arm-kernel, linux-kernel, linux-sunxi

In the recently refactored sunxi pinctrl library, we are only allocating
one set of pin configs for each pinmux setting node. When the pinctrl_map
structure is freed, the pin configs should also be freed. However the
code assumed the first map would contain the configs, which actually
never happens, as the mux function map gets added first.

The proper way to do this is to look through all the maps and free the
first one whose type is actually PIN_MAP_TYPE_CONFIGS_GROUP.

Also slightly expand the comment explaining this.

Fixes: f233dbca6227 ("pinctrl: sunxi: Rework the pin config building code")
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/pinctrl/sunxi/pinctrl-sunxi.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index ebe2c73d211e..e199d95af8c0 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -408,8 +408,21 @@ static void sunxi_pctrl_dt_free_map(struct pinctrl_dev *pctldev,
 				    struct pinctrl_map *map,
 				    unsigned num_maps)
 {
-	/* All the maps have the same pin config, free only the first one */
-	kfree(map[0].data.configs.configs);
+	int i;
+
+	/* pin config is never in the first map */
+	for (i = 1; i < num_maps; i++) {
+		if (map[i].type != PIN_MAP_TYPE_CONFIGS_GROUP)
+			continue;
+
+		/*
+		 * All the maps share the same pin config,
+		 * free only the first one we find.
+		 */
+		kfree(map[i].data.configs.configs);
+		break;
+	}
+
 	kfree(map);
 }
 
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: sunxi: Free configs in pinctrl_map only if it is a config map
  2016-11-11  2:35 [PATCH] pinctrl: sunxi: Free configs in pinctrl_map only if it is a config map Chen-Yu Tsai
@ 2016-11-11  8:29 ` Maxime Ripard
  2016-11-15  9:15 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Maxime Ripard @ 2016-11-11  8:29 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Linus Walleij, linux-gpio, linux-arm-kernel, linux-kernel, linux-sunxi

[-- Attachment #1: Type: text/plain, Size: 935 bytes --]

On Fri, Nov 11, 2016 at 10:35:10AM +0800, Chen-Yu Tsai wrote:
> In the recently refactored sunxi pinctrl library, we are only allocating
> one set of pin configs for each pinmux setting node. When the pinctrl_map
> structure is freed, the pin configs should also be freed. However the
> code assumed the first map would contain the configs, which actually
> never happens, as the mux function map gets added first.
> 
> The proper way to do this is to look through all the maps and free the
> first one whose type is actually PIN_MAP_TYPE_CONFIGS_GROUP.
> 
> Also slightly expand the comment explaining this.
> 
> Fixes: f233dbca6227 ("pinctrl: sunxi: Rework the pin config building code")
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: sunxi: Free configs in pinctrl_map only if it is a config map
  2016-11-11  2:35 [PATCH] pinctrl: sunxi: Free configs in pinctrl_map only if it is a config map Chen-Yu Tsai
  2016-11-11  8:29 ` Maxime Ripard
@ 2016-11-15  9:15 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2016-11-15  9:15 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Maxime Ripard, linux-gpio, linux-arm-kernel, linux-kernel, linux-sunxi

On Fri, Nov 11, 2016 at 3:35 AM, Chen-Yu Tsai <wens@csie.org> wrote:

> In the recently refactored sunxi pinctrl library, we are only allocating
> one set of pin configs for each pinmux setting node. When the pinctrl_map
> structure is freed, the pin configs should also be freed. However the
> code assumed the first map would contain the configs, which actually
> never happens, as the mux function map gets added first.
>
> The proper way to do this is to look through all the maps and free the
> first one whose type is actually PIN_MAP_TYPE_CONFIGS_GROUP.
>
> Also slightly expand the comment explaining this.
>
> Fixes: f233dbca6227 ("pinctrl: sunxi: Rework the pin config building code")
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Patch applied with Maxime's ACK.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-11-15  9:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-11  2:35 [PATCH] pinctrl: sunxi: Free configs in pinctrl_map only if it is a config map Chen-Yu Tsai
2016-11-11  8:29 ` Maxime Ripard
2016-11-15  9:15 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).