* memory leak and other oddness in pinctrl-mvebu.c
[not found] ` <1362872371.3690.106.camel@shinybook.infradead.org>
@ 2013-03-10 0:06 ` Jason Cooper
2013-03-13 16:59 ` Linus Walleij
2013-03-13 17:35 ` [PATCH] pinctrl: mvebu: prevent walking off the end of group array Jason Cooper
2013-03-13 17:48 ` [PATCH V2] " Jason Cooper
2 siblings, 1 reply; 15+ messages in thread
From: Jason Cooper @ 2013-03-10 0:06 UTC (permalink / raw)
To: linux-arm-kernel
Added LinusW, Gregory and Ezequiel to the email. Guys, can you give
this a Tested-by before I apply (or Ack for LinusW)?
thx,
Jason.
On Sat, Mar 09, 2013 at 11:39:31PM +0000, David Woodhouse wrote:
> On Sat, 2013-03-09 at 17:53 -0500, Jason Cooper wrote:
> > > + if (!nr_funcs)
> >
> > shouldn't this be:
> >
> > if (nr_funcs <= 0)
>
> Hm, no. But the loop should terminate if nr_funcs ever reaches zero,
> otherwise funcs->num_groups will be off the end of the original array:
>
> diff --git a/drivers/pinctrl/mvebu/pinctrl-mvebu.c b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
> index c689c04..8bbc607 100644
> --- a/drivers/pinctrl/mvebu/pinctrl-mvebu.c
> +++ b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
> @@ -478,16 +478,21 @@ static struct pinctrl_ops mvebu_pinctrl_ops = {
> .dt_free_map = mvebu_pinctrl_dt_free_map,
> };
>
> -static int _add_function(struct mvebu_pinctrl_function *funcs, const char *name)
> +static int _add_function(struct mvebu_pinctrl_function *funcs, int nr_funcs,
> + const char *name)
> {
> - while (funcs->num_groups) {
> + while (nr_funcs && funcs->num_groups) {
> /* function already there */
> if (strcmp(funcs->name, name) == 0) {
> funcs->num_groups++;
> return -EEXIST;
> }
> funcs++;
> + nr_funcs--;
> }
> + if (!nr_funcs)
> + return -EOVERFLOW;
> +
> funcs->name = name;
> funcs->num_groups = 1;
> return 0;
> @@ -501,7 +506,7 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev,
> int n, s;
>
> /* we allocate functions for number of pins and hope
> - * there are less unique functions than pins available */
> + * there are fewer unique functions than pins available */
> funcs = devm_kzalloc(&pdev->dev, pctl->desc.npins *
> sizeof(struct mvebu_pinctrl_function), GFP_KERNEL);
> if (!funcs)
> @@ -510,26 +515,27 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev,
> for (n = 0; n < pctl->num_groups; n++) {
> struct mvebu_pinctrl_group *grp = &pctl->groups[n];
> for (s = 0; s < grp->num_settings; s++) {
> + int ret;
> +
> /* skip unsupported settings on this variant */
> if (pctl->variant &&
> !(pctl->variant & grp->settings[s].variant))
> continue;
>
> /* check for unique functions and count groups */
> - if (_add_function(funcs, grp->settings[s].name))
> + ret = _add_function(funcs, pctl->desc.npins,
> + grp->settings[s].name);
> + if (ret == -EOVERFLOW)
> + dev_err(&pdev->dev,
> + "More functions than pins(%d)\n",
> + pctl->desc.npins);
> + if (ret)
> continue;
>
> num++;
> }
> }
>
> - /* with the number of unique functions and it's groups known,
> - reallocate functions and assign group names */
> - funcs = krealloc(funcs, num * sizeof(struct mvebu_pinctrl_function),
> - GFP_KERNEL);
> - if (!funcs)
> - return -ENOMEM;
> -
> pctl->num_functions = num;
> pctl->functions = funcs;
>
>
> --
> dwmw2
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* memory leak and other oddness in pinctrl-mvebu.c
2013-03-10 0:06 ` memory leak and other oddness in pinctrl-mvebu.c Jason Cooper
@ 2013-03-13 16:59 ` Linus Walleij
0 siblings, 0 replies; 15+ messages in thread
From: Linus Walleij @ 2013-03-13 16:59 UTC (permalink / raw)
To: linux-arm-kernel
On Sun, Mar 10, 2013 at 1:06 AM, Jason Cooper <jason@lakedaemon.net> wrote:
> Added LinusW, Gregory and Ezequiel to the email. Guys, can you give
> this a Tested-by before I apply (or Ack for LinusW)?
If the Marvell people are happy I'm happy. But I would like to have
some Tested-by from Sebastian or so? Also I don't quite see the
final form of this patch?
And shouldn't I rather take the final patch into the pinctrl tree?
Then there is a larger issue lurking behind this, and that is that
all platforms run their own awkward DT parse code, and that comes
from the fact that we could not agree on a common mapping.
We must think real hard if we can't atleast share some of the
parsing code here.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] pinctrl: mvebu: prevent walking off the end of group array
[not found] ` <1362872371.3690.106.camel@shinybook.infradead.org>
2013-03-10 0:06 ` memory leak and other oddness in pinctrl-mvebu.c Jason Cooper
@ 2013-03-13 17:35 ` Jason Cooper
2013-03-13 17:47 ` Linus Walleij
2013-03-13 17:48 ` Sebastian Hesselbarth
2013-03-13 17:48 ` [PATCH V2] " Jason Cooper
2 siblings, 2 replies; 15+ messages in thread
From: Jason Cooper @ 2013-03-13 17:35 UTC (permalink / raw)
To: linux-arm-kernel
From: David Woodhouse <dwmw2@infradead.org>
While investigating (ab)use of krealloc, David found this bug. It's
unlikely to occur, but now we detect the condition and error out
appropriately.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
---
David, please double check that this is as you intended. I had to hand-jam it in due to some peculiarities on my side.
drivers/pinctrl/mvebu/pinctrl-mvebu.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/drivers/pinctrl/mvebu/pinctrl-mvebu.c b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
index c689c04..8d8f175 100644
--- a/drivers/pinctrl/mvebu/pinctrl-mvebu.c
+++ b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
@@ -478,16 +478,21 @@ static struct pinctrl_ops mvebu_pinctrl_ops = {
.dt_free_map = mvebu_pinctrl_dt_free_map,
};
-static int _add_function(struct mvebu_pinctrl_function *funcs, const char *name)
+static int _add_function(struct mvebu_pinctrl_function *funcs, nt nr_funcs,
+ const char *name)
{
- while (funcs->num_groups) {
+ while (nr_funcs && funcs->num_groups) {
/* function already there */
if (strcmp(funcs->name, name) == 0) {
funcs->num_groups++;
return -EEXIST;
}
funcs++;
+ nr_funcs--;
}
+ if (!nr_funcs)
+ return -EOVERFLOW;
+
funcs->name = name;
funcs->num_groups = 1;
return 0;
@@ -501,7 +506,7 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev,
int n, s;
/* we allocate functions for number of pins and hope
- * there are less unique functions than pins available */
+ * there are fewer unique functions than pins available */
funcs = devm_kzalloc(&pdev->dev, pctl->desc.npins *
sizeof(struct mvebu_pinctrl_function), GFP_KERNEL);
if (!funcs)
@@ -510,26 +515,26 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev,
for (n = 0; n < pctl->num_groups; n++) {
struct mvebu_pinctrl_group *grp = &pctl->groups[n];
for (s = 0; s < grp->num_settings; s++) {
+ int ret;
+
/* skip unsupported settings on this variant */
if (pctl->variant &&
!(pctl->variant & grp->settings[s].variant))
continue;
/* check for unique functions and count groups */
- if (_add_function(funcs, grp->settings[s].name))
+ ret = _add_function(funcs, pctl->desc.npins,
+ grp->settings[s].name);
+ if (ret == -EOVERFLOW)
+ dev_err(&pdev->dev,
+ "More functions than pins(%d)\n",
+ pctl->desc.npins);
continue;
num++;
}
}
- /* with the number of unique functions and it's groups known,
- reallocate functions and assign group names */
- funcs = krealloc(funcs, num * sizeof(struct mvebu_pinctrl_function),
- GFP_KERNEL);
- if (!funcs)
- return -ENOMEM;
-
pctl->num_functions = num;
pctl->functions = funcs;
--
1.8.1.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH] pinctrl: mvebu: prevent walking off the end of group array
2013-03-13 17:35 ` [PATCH] pinctrl: mvebu: prevent walking off the end of group array Jason Cooper
@ 2013-03-13 17:47 ` Linus Walleij
2013-03-13 17:50 ` Jason Cooper
2013-03-13 17:48 ` Sebastian Hesselbarth
1 sibling, 1 reply; 15+ messages in thread
From: Linus Walleij @ 2013-03-13 17:47 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Mar 13, 2013 at 6:35 PM, Jason Cooper <jason@lakedaemon.net> wrote:
> From: David Woodhouse <dwmw2@infradead.org>
>
> While investigating (ab)use of krealloc, David found this bug. It's
> unlikely to occur, but now we detect the condition and error out
> appropriately.
>
> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
> Signed-off-by: Jason Cooper <jason@lakedaemon.net>
> ---
> David, please double check that this is as you intended. I had to hand-jam it in due to some peculiarities on my side.
I have tentatively applied this to my fixes branch.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] pinctrl: mvebu: prevent walking off the end of group array
2013-03-13 17:47 ` Linus Walleij
@ 2013-03-13 17:50 ` Jason Cooper
2013-03-13 18:40 ` Linus Walleij
0 siblings, 1 reply; 15+ messages in thread
From: Jason Cooper @ 2013-03-13 17:50 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Mar 13, 2013 at 06:47:36PM +0100, Linus Walleij wrote:
> On Wed, Mar 13, 2013 at 6:35 PM, Jason Cooper <jason@lakedaemon.net> wrote:
>
> > From: David Woodhouse <dwmw2@infradead.org>
> >
> > While investigating (ab)use of krealloc, David found this bug. It's
> > unlikely to occur, but now we detect the condition and error out
> > appropriately.
> >
> > Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
> > Signed-off-by: Jason Cooper <jason@lakedaemon.net>
> > ---
> > David, please double check that this is as you intended. I had to hand-jam it in due to some peculiarities on my side.
>
> I have tentatively applied this to my fixes branch.
Dang, you're quick. Please see V2 <shuffles feet>
thx,
Jason.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] pinctrl: mvebu: prevent walking off the end of group array
2013-03-13 17:50 ` Jason Cooper
@ 2013-03-13 18:40 ` Linus Walleij
0 siblings, 0 replies; 15+ messages in thread
From: Linus Walleij @ 2013-03-13 18:40 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Mar 13, 2013 at 6:50 PM, Jason Cooper <jason@lakedaemon.net> wrote:
> On Wed, Mar 13, 2013 at 06:47:36PM +0100, Linus Walleij wrote:
>> On Wed, Mar 13, 2013 at 6:35 PM, Jason Cooper <jason@lakedaemon.net> wrote:
>>
>> > From: David Woodhouse <dwmw2@infradead.org>
>> >
>> > While investigating (ab)use of krealloc, David found this bug. It's
>> > unlikely to occur, but now we detect the condition and error out
>> > appropriately.
>> >
>> > Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
>> > Signed-off-by: Jason Cooper <jason@lakedaemon.net>
>> > ---
>> > David, please double check that this is as you intended. I had to hand-jam it in due to some peculiarities on my side.
>>
>> I have tentatively applied this to my fixes branch.
>
> Dang, you're quick. Please see V2 <shuffles feet>
Ah, I'm too trigger happy. I took it out again waiting for some ACK
and testing..
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] pinctrl: mvebu: prevent walking off the end of group array
2013-03-13 17:35 ` [PATCH] pinctrl: mvebu: prevent walking off the end of group array Jason Cooper
2013-03-13 17:47 ` Linus Walleij
@ 2013-03-13 17:48 ` Sebastian Hesselbarth
1 sibling, 0 replies; 15+ messages in thread
From: Sebastian Hesselbarth @ 2013-03-13 17:48 UTC (permalink / raw)
To: linux-arm-kernel
On 03/13/2013 06:35 PM, Jason Cooper wrote:
> From: David Woodhouse<dwmw2@infradead.org>
>
> While investigating (ab)use of krealloc, David found this bug. It's
> unlikely to occur, but now we detect the condition and error out
> appropriately.
>
> Signed-off-by: David Woodhouse<David.Woodhouse@intel.com>
> Signed-off-by: Jason Cooper<jason@lakedaemon.net>
> ---
> David, please double check that this is as you intended. I had to hand-jam it in due to some peculiarities on my side.
>
Jason,
thanks for preparing that patch. I ll test (and Ack) asap but that will not be
before this weekend. If Thomas and Andrew ack it before me, consider it good.
Sebastian
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH V2] pinctrl: mvebu: prevent walking off the end of group array
[not found] ` <1362872371.3690.106.camel@shinybook.infradead.org>
2013-03-10 0:06 ` memory leak and other oddness in pinctrl-mvebu.c Jason Cooper
2013-03-13 17:35 ` [PATCH] pinctrl: mvebu: prevent walking off the end of group array Jason Cooper
@ 2013-03-13 17:48 ` Jason Cooper
2013-03-14 10:29 ` David Woodhouse
2013-03-16 11:44 ` [PATCH v3] " Sebastian Hesselbarth
2 siblings, 2 replies; 15+ messages in thread
From: Jason Cooper @ 2013-03-13 17:48 UTC (permalink / raw)
To: linux-arm-kernel
From: David Woodhouse <dwmw2@infradead.org>
While investigating (ab)use of krealloc, David found this bug. It's
unlikely to occur, but now we detect the condition and error out
appropriately.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
---
Changes from v1:
- correct typo (s/ nt / int /) I should've caught before sending.
David, please double check that this is as you intended. I had to hand-jam it
in due to some peculiarities on my side.
drivers/pinctrl/mvebu/pinctrl-mvebu.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/drivers/pinctrl/mvebu/pinctrl-mvebu.c b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
index c689c04..5db5fad 100644
--- a/drivers/pinctrl/mvebu/pinctrl-mvebu.c
+++ b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
@@ -478,16 +478,21 @@ static struct pinctrl_ops mvebu_pinctrl_ops = {
.dt_free_map = mvebu_pinctrl_dt_free_map,
};
-static int _add_function(struct mvebu_pinctrl_function *funcs, const char *name)
+static int _add_function(struct mvebu_pinctrl_function *funcs, int nr_funcs,
+ const char *name)
{
- while (funcs->num_groups) {
+ while (nr_funcs && funcs->num_groups) {
/* function already there */
if (strcmp(funcs->name, name) == 0) {
funcs->num_groups++;
return -EEXIST;
}
funcs++;
+ nr_funcs--;
}
+ if (!nr_funcs)
+ return -EOVERFLOW;
+
funcs->name = name;
funcs->num_groups = 1;
return 0;
@@ -501,7 +506,7 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev,
int n, s;
/* we allocate functions for number of pins and hope
- * there are less unique functions than pins available */
+ * there are fewer unique functions than pins available */
funcs = devm_kzalloc(&pdev->dev, pctl->desc.npins *
sizeof(struct mvebu_pinctrl_function), GFP_KERNEL);
if (!funcs)
@@ -510,26 +515,26 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev,
for (n = 0; n < pctl->num_groups; n++) {
struct mvebu_pinctrl_group *grp = &pctl->groups[n];
for (s = 0; s < grp->num_settings; s++) {
+ int ret;
+
/* skip unsupported settings on this variant */
if (pctl->variant &&
!(pctl->variant & grp->settings[s].variant))
continue;
/* check for unique functions and count groups */
- if (_add_function(funcs, grp->settings[s].name))
+ ret = _add_function(funcs, pctl->desc.npins,
+ grp->settings[s].name);
+ if (ret == -EOVERFLOW)
+ dev_err(&pdev->dev,
+ "More functions than pins(%d)\n",
+ pctl->desc.npins);
continue;
num++;
}
}
- /* with the number of unique functions and it's groups known,
- reallocate functions and assign group names */
- funcs = krealloc(funcs, num * sizeof(struct mvebu_pinctrl_function),
- GFP_KERNEL);
- if (!funcs)
- return -ENOMEM;
-
pctl->num_functions = num;
pctl->functions = funcs;
--
1.8.1.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH V2] pinctrl: mvebu: prevent walking off the end of group array
2013-03-13 17:48 ` [PATCH V2] " Jason Cooper
@ 2013-03-14 10:29 ` David Woodhouse
2013-03-16 11:44 ` [PATCH v3] " Sebastian Hesselbarth
1 sibling, 0 replies; 15+ messages in thread
From: David Woodhouse @ 2013-03-14 10:29 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, 2013-03-13 at 17:48 +0000, Jason Cooper wrote:
> From: David Woodhouse <dwmw2@infradead.org>
>
> While investigating (ab)use of krealloc, David found this bug. It's
> unlikely to occur, but now we detect the condition and error out
> appropriately.
>
> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
> Signed-off-by: Jason Cooper <jason@lakedaemon.net>
> ---
> Changes from v1:
> - correct typo (s/ nt / int /) I should've caught before sending.
>
> David, please double check that this is as you intended. I had to hand-jam it
> in due to some peculiarities on my side.
Looks fine; thanks.
--
David Woodhouse Open Source Technology Centre
David.Woodhouse at intel.com Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 6171 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130314/80874e05/attachment-0001.bin>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3] pinctrl: mvebu: prevent walking off the end of group array
2013-03-13 17:48 ` [PATCH V2] " Jason Cooper
2013-03-14 10:29 ` David Woodhouse
@ 2013-03-16 11:44 ` Sebastian Hesselbarth
2013-03-22 16:39 ` Jason Cooper
2013-03-27 22:06 ` Linus Walleij
1 sibling, 2 replies; 15+ messages in thread
From: Sebastian Hesselbarth @ 2013-03-16 11:44 UTC (permalink / raw)
To: linux-arm-kernel
From: David Woodhouse <dwmw2@infradead.org>
While investigating (ab)use of krealloc, David found this bug. It's
unlikely to occur, but now we detect the condition and error out
appropriately.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Jason, David,
I tested the patch on Dove and fixed all remaining issues.
Thomas, Gregory, Andrew should test on their platforms, too.
Sebastian
Changes from v2:
- fix counting of available array space
- fix return code handling
Changes from v1:
- correct typo (s/ nt / int /) I should've caught before sending.
drivers/pinctrl/mvebu/pinctrl-mvebu.c | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
---
Cc: Jason Cooper <jason@lakedaemon.net>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Gregory Clement <gregory.clement@free-electrons.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Stephen Warren <swarren@wwwdotorg.org>
Cc: Linux ARM Kernel <linux-arm-kernel@lists.infradead.org>
Cc: linux-kernel at vger.kernel.org
---
diff --git a/drivers/pinctrl/mvebu/pinctrl-mvebu.c b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
index c689c04..aa77fb7a 100644
--- a/drivers/pinctrl/mvebu/pinctrl-mvebu.c
+++ b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
@@ -478,8 +478,12 @@ static struct pinctrl_ops mvebu_pinctrl_ops = {
.dt_free_map = mvebu_pinctrl_dt_free_map,
};
-static int _add_function(struct mvebu_pinctrl_function *funcs, const char *name)
+static int _add_function(struct mvebu_pinctrl_function *funcs, int *funcsize,
+ const char *name)
{
+ if (*funcsize <= 0)
+ return -EOVERFLOW;
+
while (funcs->num_groups) {
/* function already there */
if (strcmp(funcs->name, name) == 0) {
@@ -488,8 +492,12 @@ static int _add_function(struct mvebu_pinctrl_function *funcs, const char *name)
}
funcs++;
}
+
+ /* append new unique function */
funcs->name = name;
funcs->num_groups = 1;
+ (*funcsize)--;
+
return 0;
}
@@ -497,12 +505,12 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev,
struct mvebu_pinctrl *pctl)
{
struct mvebu_pinctrl_function *funcs;
- int num = 0;
+ int num = 0, funcsize = pctl->desc.npins;
int n, s;
/* we allocate functions for number of pins and hope
- * there are less unique functions than pins available */
- funcs = devm_kzalloc(&pdev->dev, pctl->desc.npins *
+ * there are fewer unique functions than pins available */
+ funcs = devm_kzalloc(&pdev->dev, funcsize *
sizeof(struct mvebu_pinctrl_function), GFP_KERNEL);
if (!funcs)
return -ENOMEM;
@@ -510,26 +518,27 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev,
for (n = 0; n < pctl->num_groups; n++) {
struct mvebu_pinctrl_group *grp = &pctl->groups[n];
for (s = 0; s < grp->num_settings; s++) {
+ int ret;
+
/* skip unsupported settings on this variant */
if (pctl->variant &&
!(pctl->variant & grp->settings[s].variant))
continue;
/* check for unique functions and count groups */
- if (_add_function(funcs, grp->settings[s].name))
+ ret = _add_function(funcs, &funcsize,
+ grp->settings[s].name);
+ if (ret == -EOVERFLOW)
+ dev_err(&pdev->dev,
+ "More functions than pins(%d)\n",
+ pctl->desc.npins);
+ if (ret < 0)
continue;
num++;
}
}
- /* with the number of unique functions and it's groups known,
- reallocate functions and assign group names */
- funcs = krealloc(funcs, num * sizeof(struct mvebu_pinctrl_function),
- GFP_KERNEL);
- if (!funcs)
- return -ENOMEM;
-
pctl->num_functions = num;
pctl->functions = funcs;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v3] pinctrl: mvebu: prevent walking off the end of group array
2013-03-16 11:44 ` [PATCH v3] " Sebastian Hesselbarth
@ 2013-03-22 16:39 ` Jason Cooper
2013-03-27 22:06 ` Linus Walleij
1 sibling, 0 replies; 15+ messages in thread
From: Jason Cooper @ 2013-03-22 16:39 UTC (permalink / raw)
To: linux-arm-kernel
Linus,
On Sat, Mar 16, 2013 at 12:44:32PM +0100, Sebastian Hesselbarth wrote:
> From: David Woodhouse <dwmw2@infradead.org>
>
> While investigating (ab)use of krealloc, David found this bug. It's
> unlikely to occur, but now we detect the condition and error out
> appropriately.
>
> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
> Signed-off-by: Jason Cooper <jason@lakedaemon.net>
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> ---
> Jason, David,
>
> I tested the patch on Dove and fixed all remaining issues.
>
> Thomas, Gregory, Andrew should test on their platforms, too.
>
> Sebastian
>
> Changes from v2:
> - fix counting of available array space
> - fix return code handling
>
> Changes from v1:
> - correct typo (s/ nt / int /) I should've caught before sending.
>
> drivers/pinctrl/mvebu/pinctrl-mvebu.c | 33 +++++++++++++++++++++------------
> 1 file changed, 21 insertions(+), 12 deletions(-)
Does this look good to you?
fwiw,
Acked-by: Jason Cooper <jason@lakedaemon.net>
thx,
Jason.
> ---
> Cc: Jason Cooper <jason@lakedaemon.net>
> Cc: David Woodhouse <dwmw2@infradead.org>
> Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> Cc: Gregory Clement <gregory.clement@free-electrons.com>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Stephen Warren <swarren@wwwdotorg.org>
> Cc: Linux ARM Kernel <linux-arm-kernel@lists.infradead.org>
> Cc: linux-kernel at vger.kernel.org
> ---
> diff --git a/drivers/pinctrl/mvebu/pinctrl-mvebu.c b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
> index c689c04..aa77fb7a 100644
> --- a/drivers/pinctrl/mvebu/pinctrl-mvebu.c
> +++ b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
> @@ -478,8 +478,12 @@ static struct pinctrl_ops mvebu_pinctrl_ops = {
> .dt_free_map = mvebu_pinctrl_dt_free_map,
> };
>
> -static int _add_function(struct mvebu_pinctrl_function *funcs, const char *name)
> +static int _add_function(struct mvebu_pinctrl_function *funcs, int *funcsize,
> + const char *name)
> {
> + if (*funcsize <= 0)
> + return -EOVERFLOW;
> +
> while (funcs->num_groups) {
> /* function already there */
> if (strcmp(funcs->name, name) == 0) {
> @@ -488,8 +492,12 @@ static int _add_function(struct mvebu_pinctrl_function *funcs, const char *name)
> }
> funcs++;
> }
> +
> + /* append new unique function */
> funcs->name = name;
> funcs->num_groups = 1;
> + (*funcsize)--;
> +
> return 0;
> }
>
> @@ -497,12 +505,12 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev,
> struct mvebu_pinctrl *pctl)
> {
> struct mvebu_pinctrl_function *funcs;
> - int num = 0;
> + int num = 0, funcsize = pctl->desc.npins;
> int n, s;
>
> /* we allocate functions for number of pins and hope
> - * there are less unique functions than pins available */
> - funcs = devm_kzalloc(&pdev->dev, pctl->desc.npins *
> + * there are fewer unique functions than pins available */
> + funcs = devm_kzalloc(&pdev->dev, funcsize *
> sizeof(struct mvebu_pinctrl_function), GFP_KERNEL);
> if (!funcs)
> return -ENOMEM;
> @@ -510,26 +518,27 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev,
> for (n = 0; n < pctl->num_groups; n++) {
> struct mvebu_pinctrl_group *grp = &pctl->groups[n];
> for (s = 0; s < grp->num_settings; s++) {
> + int ret;
> +
> /* skip unsupported settings on this variant */
> if (pctl->variant &&
> !(pctl->variant & grp->settings[s].variant))
> continue;
>
> /* check for unique functions and count groups */
> - if (_add_function(funcs, grp->settings[s].name))
> + ret = _add_function(funcs, &funcsize,
> + grp->settings[s].name);
> + if (ret == -EOVERFLOW)
> + dev_err(&pdev->dev,
> + "More functions than pins(%d)\n",
> + pctl->desc.npins);
> + if (ret < 0)
> continue;
>
> num++;
> }
> }
>
> - /* with the number of unique functions and it's groups known,
> - reallocate functions and assign group names */
> - funcs = krealloc(funcs, num * sizeof(struct mvebu_pinctrl_function),
> - GFP_KERNEL);
> - if (!funcs)
> - return -ENOMEM;
> -
> pctl->num_functions = num;
> pctl->functions = funcs;
>
> --
> 1.7.10.4
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3] pinctrl: mvebu: prevent walking off the end of group array
2013-03-16 11:44 ` [PATCH v3] " Sebastian Hesselbarth
2013-03-22 16:39 ` Jason Cooper
@ 2013-03-27 22:06 ` Linus Walleij
2013-03-27 22:11 ` Woodhouse, David
1 sibling, 1 reply; 15+ messages in thread
From: Linus Walleij @ 2013-03-27 22:06 UTC (permalink / raw)
To: linux-arm-kernel
On Sat, Mar 16, 2013 at 12:44 PM, Sebastian Hesselbarth
<sebastian.hesselbarth@gmail.com> wrote:
> From: David Woodhouse <dwmw2@infradead.org>
>
> While investigating (ab)use of krealloc, David found this bug. It's
> unlikely to occur, but now we detect the condition and error out
> appropriately.
>
> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
> Signed-off-by: Jason Cooper <jason@lakedaemon.net>
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
OK this v2 version applied for fixes...
Is it so critical that it needs to be tagged for stable as well
then tell me.
If it's non-critical enough to live on for -next then tell me.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3] pinctrl: mvebu: prevent walking off the end of group array
2013-03-27 22:06 ` Linus Walleij
@ 2013-03-27 22:11 ` Woodhouse, David
2013-03-27 22:34 ` Linus Walleij
0 siblings, 1 reply; 15+ messages in thread
From: Woodhouse, David @ 2013-03-27 22:11 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, 2013-03-27 at 23:06 +0100, Linus Walleij wrote:
> Is it so critical that it needs to be tagged for stable as well
> then tell me.
>
> If it's non-critical enough to live on for -next then tell me.
I don't think it's critical. It'll probably never trigger in practice.
--
Sent with MeeGo's ActiveSync support.
David Woodhouse Open Source Technology Centre
David.Woodhouse at intel.com Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 6242 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130327/30d1c6d2/attachment-0001.bin>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3] pinctrl: mvebu: prevent walking off the end of group array
2013-03-27 22:11 ` Woodhouse, David
@ 2013-03-27 22:34 ` Linus Walleij
2013-03-28 11:08 ` Jason Cooper
0 siblings, 1 reply; 15+ messages in thread
From: Linus Walleij @ 2013-03-27 22:34 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Mar 27, 2013 at 11:11 PM, Woodhouse, David
<david.woodhouse@intel.com> wrote:
> On Wed, 2013-03-27 at 23:06 +0100, Linus Walleij wrote:
>> Is it so critical that it needs to be tagged for stable as well
>> then tell me.
>>
>> If it's non-critical enough to live on for -next then tell me.
>
> I don't think it's critical. It'll probably never trigger in practice.
Thanks, moving it to for-next then...
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3] pinctrl: mvebu: prevent walking off the end of group array
2013-03-27 22:34 ` Linus Walleij
@ 2013-03-28 11:08 ` Jason Cooper
0 siblings, 0 replies; 15+ messages in thread
From: Jason Cooper @ 2013-03-28 11:08 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Mar 27, 2013 at 11:34:53PM +0100, Linus Walleij wrote:
> On Wed, Mar 27, 2013 at 11:11 PM, Woodhouse, David
> <david.woodhouse@intel.com> wrote:
> > On Wed, 2013-03-27 at 23:06 +0100, Linus Walleij wrote:
> >> Is it so critical that it needs to be tagged for stable as well
> >> then tell me.
> >>
> >> If it's non-critical enough to live on for -next then tell me.
> >
> > I don't think it's critical. It'll probably never trigger in practice.
>
> Thanks, moving it to for-next then...
Thanks, Linus.
thx,
Jason.
^ permalink raw reply [flat|nested] 15+ messages in thread