* [PATCH 2/2] pinctrl: make it possible to add multiple maps
@ 2011-11-30 12:33 Linus Walleij
2011-11-30 13:30 ` Arnd Bergmann
0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2011-11-30 12:33 UTC (permalink / raw)
To: linux-kernel
Cc: Stephen Warren, Grant Likely, Barry Song, Shawn Guo,
Thomas Abraham, Dong Aisheng, Rajendra Nayak, Haojian Zhuang,
Arnd Bergmann, Linus Walleij
From: Linus Walleij <linus.walleij@linaro.org>
Since we now anyway make a copy of the platform-supplied pinmux
map, we can just as well make it possible to call the function
adding maps several times, so as to simplify cases (as PXA) where
several sets of disparate mappings need to be added depending on
target platform.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
drivers/pinctrl/pinmux.c | 58 ++++++++++++++++++++++-----------------------
1 files changed, 28 insertions(+), 30 deletions(-)
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 680f690..54fc27b 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -351,48 +351,30 @@ EXPORT_SYMBOL_GPL(pinmux_gpio_direction_output);
int __init pinmux_register_mappings(struct pinmux_map const *maps,
unsigned num_maps)
{
- int ret = 0;
+ void *tmp_maps;
int i;
- if (pinmux_maps_num != 0) {
- pr_err("pinmux mappings already registered, you can only "
- "register one set of maps\n");
- return -EINVAL;
- }
-
pr_debug("add %d pinmux maps\n", num_maps);
- /*
- * Make a copy of the map array - string pointers will end up in the
- * kernel const section anyway so these do not need to be deep copied.
- */
- pinmux_maps = kmemdup(maps, sizeof(struct pinmux_map) * num_maps,
- GFP_KERNEL);
- if (!pinmux_maps)
- return -ENOMEM;
-
+ /* First sanity check the new mapping */
for (i = 0; i < num_maps; i++) {
- /* Sanity check the mapping while copying it */
if (!maps[i].name) {
pr_err("failed to register map %d: "
"no map name given\n", i);
- ret = -EINVAL;
- goto err_out_free;
+ return -EINVAL;
}
if (!maps[i].ctrl_dev && !maps[i].ctrl_dev_name) {
pr_err("failed to register map %s (%d): "
"no pin control device given\n",
maps[i].name, i);
- ret = -EINVAL;
- goto err_out_free;
+ return -EINVAL;
}
if (!maps[i].function) {
pr_err("failed to register map %s (%d): "
"no function ID given\n", maps[i].name, i);
- ret = -EINVAL;
- goto err_out_free;
+ return -EINVAL;
}
if (!maps[i].dev && !maps[i].dev_name)
@@ -403,17 +385,33 @@ int __init pinmux_register_mappings(struct pinmux_map const *maps,
pr_debug("register map %s, function %s\n",
maps[i].name,
maps[i].function);
+ }
- pinmux_maps_num++;
+ /*
+ * Make a copy of the map array - string pointers will end up in the
+ * kernel const section anyway so these do not need to be deep copied.
+ */
+ if (!pinmux_maps_num) {
+ /* On first call, just copy them */
+ tmp_maps = kmemdup(maps,
+ sizeof(struct pinmux_map) * num_maps,
+ GFP_KERNEL);
+ if (!tmp_maps)
+ return -ENOMEM;
+ } else {
+ /* Subsequent calls, reallocate array to new size */
+ size_t oldsize = sizeof(struct pinmux_map) * pinmux_maps_num;
+ size_t newsize = sizeof(struct pinmux_map) * num_maps;
+
+ tmp_maps = krealloc(pinmux_maps, oldsize + newsize, GFP_KERNEL);
+ if (!tmp_maps)
+ return -ENOMEM;
+ memcpy((tmp_maps + oldsize), maps, newsize);
}
+ pinmux_maps = tmp_maps;
+ pinmux_maps_num += num_maps;
return 0;
-
-err_out_free:
- kfree(pinmux_maps);
- pinmux_maps = NULL;
- pinmux_maps_num = 0;
- return ret;
}
/**
--
1.7.3.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 2/2] pinctrl: make it possible to add multiple maps
2011-11-30 12:33 [PATCH 2/2] pinctrl: make it possible to add multiple maps Linus Walleij
@ 2011-11-30 13:30 ` Arnd Bergmann
2011-11-30 15:48 ` Haojian Zhuang
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2011-11-30 13:30 UTC (permalink / raw)
To: Linus Walleij
Cc: linux-kernel, Stephen Warren, Grant Likely, Barry Song, Shawn Guo,
Thomas Abraham, Dong Aisheng, Rajendra Nayak, Haojian Zhuang,
Linus Walleij
On Wednesday 30 November 2011, Linus Walleij wrote:
> From: Linus Walleij <linus.walleij@linaro.org>
>
> Since we now anyway make a copy of the platform-supplied pinmux
> map, we can just as well make it possible to call the function
> adding maps several times, so as to simplify cases (as PXA) where
> several sets of disparate mappings need to be added depending on
> target platform.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Arnd Bergmann <arnd@linaro.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] pinctrl: make it possible to add multiple maps
2011-11-30 13:30 ` Arnd Bergmann
@ 2011-11-30 15:48 ` Haojian Zhuang
0 siblings, 0 replies; 3+ messages in thread
From: Haojian Zhuang @ 2011-11-30 15:48 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Linus Walleij, linux-kernel, Stephen Warren, Grant Likely,
Barry Song, Shawn Guo, Thomas Abraham, Dong Aisheng,
Rajendra Nayak, Haojian Zhuang, Linus Walleij
On Wed, Nov 30, 2011 at 9:30 PM, Arnd Bergmann <arnd.bergmann@linaro.org> wrote:
> On Wednesday 30 November 2011, Linus Walleij wrote:
>> From: Linus Walleij <linus.walleij@linaro.org>
>>
>> Since we now anyway make a copy of the platform-supplied pinmux
>> map, we can just as well make it possible to call the function
>> adding maps several times, so as to simplify cases (as PXA) where
>> several sets of disparate mappings need to be added depending on
>> target platform.
>>
>> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
>
> Acked-by: Arnd Bergmann <arnd@linaro.org>
> --
Acked-by: Haojian Zhuang <haojian.zhuang@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-11-30 15:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-30 12:33 [PATCH 2/2] pinctrl: make it possible to add multiple maps Linus Walleij
2011-11-30 13:30 ` Arnd Bergmann
2011-11-30 15:48 ` Haojian Zhuang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox