* [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action()
@ 2023-09-08 7:03 Dan Carpenter
2023-09-08 7:16 ` Geert Uytterhoeven
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Dan Carpenter @ 2023-09-08 7:03 UTC (permalink / raw)
To: Rob Herring
Cc: Rob Herring, Frank Rowand, Geert Uytterhoeven, devicetree,
linux-kernel, kernel-janitors
Smatch complains that the error path where "action" is invalid leaks
the "ce" allocation:
drivers/of/dynamic.c:935 of_changeset_action()
warn: possible memory leak of 'ce'
Fix this by doing the validation before the allocation.
Fixes: 914d9d831e61 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/of/dynamic.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index 0a3483e247a8..f63250c650ca 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -890,13 +890,13 @@ int of_changeset_action(struct of_changeset *ocs, unsigned long action,
{
struct of_changeset_entry *ce;
+ if (WARN_ON(action >= ARRAY_SIZE(action_names)))
+ return -EINVAL;
+
ce = kzalloc(sizeof(*ce), GFP_KERNEL);
if (!ce)
return -ENOMEM;
- if (WARN_ON(action >= ARRAY_SIZE(action_names)))
- return -EINVAL;
-
/* get a reference to the node */
ce->action = action;
ce->np = of_node_get(np);
--
2.39.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() 2023-09-08 7:03 [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() Dan Carpenter @ 2023-09-08 7:16 ` Geert Uytterhoeven 2023-09-08 15:18 ` Rob Herring 2023-09-11 14:58 ` Rob Herring 2 siblings, 0 replies; 10+ messages in thread From: Geert Uytterhoeven @ 2023-09-08 7:16 UTC (permalink / raw) To: Dan Carpenter Cc: Rob Herring, Rob Herring, Frank Rowand, devicetree, linux-kernel, kernel-janitors On Fri, Sep 8, 2023 at 9:03 AM Dan Carpenter <dan.carpenter@linaro.org> wrote: > Smatch complains that the error path where "action" is invalid leaks > the "ce" allocation: > drivers/of/dynamic.c:935 of_changeset_action() > warn: possible memory leak of 'ce' > > Fix this by doing the validation before the allocation. > > Fixes: 914d9d831e61 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock") > Reported-by: kernel test robot <lkp@intel.com> > Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/ > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() 2023-09-08 7:03 [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() Dan Carpenter 2023-09-08 7:16 ` Geert Uytterhoeven @ 2023-09-08 15:18 ` Rob Herring 2023-09-08 15:34 ` Geert Uytterhoeven 2023-09-11 14:58 ` Rob Herring 2 siblings, 1 reply; 10+ messages in thread From: Rob Herring @ 2023-09-08 15:18 UTC (permalink / raw) To: Dan Carpenter, kbuild test robot Cc: Frank Rowand, Geert Uytterhoeven, devicetree, linux-kernel, kernel-janitors On Fri, Sep 8, 2023 at 2:03 AM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > Smatch complains that the error path where "action" is invalid leaks > the "ce" allocation: > drivers/of/dynamic.c:935 of_changeset_action() > warn: possible memory leak of 'ce' > > Fix this by doing the validation before the allocation. I'm going to add a note when applying that "action" can't ever actually be invalid because all the callers are static inlines with hardcoded action values. I suppose there could be an out of tree module calling of_changeset_action() directly, but that's wrong given the wrappers. > Fixes: 914d9d831e61 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock") > Reported-by: kernel test robot <lkp@intel.com> > Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/ Despite what that says, it was never reported to me. IOW, the added TO and CC lines don't seem to have any effect. > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > --- > drivers/of/dynamic.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c > index 0a3483e247a8..f63250c650ca 100644 > --- a/drivers/of/dynamic.c > +++ b/drivers/of/dynamic.c > @@ -890,13 +890,13 @@ int of_changeset_action(struct of_changeset *ocs, unsigned long action, > { > struct of_changeset_entry *ce; > > + if (WARN_ON(action >= ARRAY_SIZE(action_names))) > + return -EINVAL; > + > ce = kzalloc(sizeof(*ce), GFP_KERNEL); > if (!ce) > return -ENOMEM; > > - if (WARN_ON(action >= ARRAY_SIZE(action_names))) > - return -EINVAL; > - > /* get a reference to the node */ > ce->action = action; > ce->np = of_node_get(np); > -- > 2.39.2 > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() 2023-09-08 15:18 ` Rob Herring @ 2023-09-08 15:34 ` Geert Uytterhoeven 2023-09-08 16:14 ` Dan Carpenter 0 siblings, 1 reply; 10+ messages in thread From: Geert Uytterhoeven @ 2023-09-08 15:34 UTC (permalink / raw) To: Rob Herring Cc: Dan Carpenter, kbuild test robot, Frank Rowand, devicetree, linux-kernel, kernel-janitors Hi Rob, On Fri, Sep 8, 2023 at 5:18 PM Rob Herring <robh@kernel.org> wrote: > On Fri, Sep 8, 2023 at 2:03 AM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > Smatch complains that the error path where "action" is invalid leaks > > the "ce" allocation: > > drivers/of/dynamic.c:935 of_changeset_action() > > warn: possible memory leak of 'ce' > > > > Fix this by doing the validation before the allocation. > > I'm going to add a note when applying that "action" can't ever > actually be invalid because all the callers are static inlines with > hardcoded action values. I suppose there could be an out of tree > module calling of_changeset_action() directly, but that's wrong given > the wrappers. FTR, the out-of-tree overlay configfs patches do not call of_changeset_action() (or any of the wrappers). > > Fixes: 914d9d831e61 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock") > > Reported-by: kernel test robot <lkp@intel.com> > > Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/ > > Despite what that says, it was never reported to me. IOW, the added TO > and CC lines don't seem to have any effect. The copy I received did list you in the "To"-header, though. Fall-out of the issues seen with Gmail lately? I do miss lots of email, too :-( Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() 2023-09-08 15:34 ` Geert Uytterhoeven @ 2023-09-08 16:14 ` Dan Carpenter 2023-09-12 15:32 ` Rob Herring 0 siblings, 1 reply; 10+ messages in thread From: Dan Carpenter @ 2023-09-08 16:14 UTC (permalink / raw) To: Geert Uytterhoeven Cc: Rob Herring, kbuild test robot, Frank Rowand, devicetree, linux-kernel, kernel-janitors On Fri, Sep 08, 2023 at 05:34:53PM +0200, Geert Uytterhoeven wrote: > > > Fixes: 914d9d831e61 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock") > > > Reported-by: kernel test robot <lkp@intel.com> > > > Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/ > > > > Despite what that says, it was never reported to me. IOW, the added TO > > and CC lines don't seem to have any effect. > > The copy I received did list you in the "To"-header, though. > Fall-out of the issues seen with Gmail lately? > I do miss lots of email, too :-( My gmail account dropped a whole lot of mail too in the last week of August. I was out of office that week so I didn't investigate. I was assuming it was an issue with vger... regards, dan carpenter ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() 2023-09-08 16:14 ` Dan Carpenter @ 2023-09-12 15:32 ` Rob Herring 2023-09-12 15:55 ` Geert Uytterhoeven 2023-09-13 6:28 ` Dan Carpenter 0 siblings, 2 replies; 10+ messages in thread From: Rob Herring @ 2023-09-12 15:32 UTC (permalink / raw) To: Dan Carpenter, Geert Uytterhoeven Cc: kbuild test robot, Frank Rowand, devicetree, linux-kernel, kernel-janitors On Fri, Sep 8, 2023 at 11:14 AM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > On Fri, Sep 08, 2023 at 05:34:53PM +0200, Geert Uytterhoeven wrote: > > > > Fixes: 914d9d831e61 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock") > > > > Reported-by: kernel test robot <lkp@intel.com> > > > > Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/ > > > > > > Despite what that says, it was never reported to me. IOW, the added TO > > > and CC lines don't seem to have any effect. > > > > The copy I received did list you in the "To"-header, though. Are you sure that's the header and not in the body? > > Fall-out of the issues seen with Gmail lately? > > I do miss lots of email, too :-( > > My gmail account dropped a whole lot of mail too in the last week of > August. I was out of office that week so I didn't investigate. I was > assuming it was an issue with vger... I don't think it's related to those issues. If I search lore including my email[1], then it doesn't find it either. Lore only has it in oe-kbuild. Not LKML or oe-kbuild-all. It really just looks like the git-send-email style of extracting emails from tags in the body is not happening. Rob [1] https://lore.kernel.org/all/?q=f%3Alkp%40intel.com+a%3Arobh%40kernel.org+of_changeset_action ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() 2023-09-12 15:32 ` Rob Herring @ 2023-09-12 15:55 ` Geert Uytterhoeven 2023-09-13 6:28 ` Dan Carpenter 1 sibling, 0 replies; 10+ messages in thread From: Geert Uytterhoeven @ 2023-09-12 15:55 UTC (permalink / raw) To: Rob Herring Cc: Dan Carpenter, kbuild test robot, Frank Rowand, devicetree, linux-kernel, kernel-janitors Hi Rob, On Tue, Sep 12, 2023 at 5:32 PM Rob Herring <robh@kernel.org> wrote: > On Fri, Sep 8, 2023 at 11:14 AM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > On Fri, Sep 08, 2023 at 05:34:53PM +0200, Geert Uytterhoeven wrote: > > > > > Fixes: 914d9d831e61 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock") > > > > > Reported-by: kernel test robot <lkp@intel.com> > > > > > Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/ > > > > > > > > Despite what that says, it was never reported to me. IOW, the added TO > > > > and CC lines don't seem to have any effect. > > > > > > The copy I received did list you in the "To"-header, though. > > Are you sure that's the header and not in the body? Yes: Date: Thu, 7 Sep 2023 13:52:48 +0300 From: Dan Carpenter <dan.carpenter@linaro.org> To: oe-kbuild@lists.linux.dev, Rob Herring <robh@kernel.org> Cc: lkp@intel.com, oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org, Geert Uytterhoeven <geert+renesas@glider.be> Subject: drivers/of/dynamic.c:935 of_changeset_action() warn: possible memory leak of 'ce' Message-ID: <eaa86211-436d-445b-80bd-84cea5745b5a@kadam.mountain> > > > Fall-out of the issues seen with Gmail lately? > > > I do miss lots of email, too :-( > > > > My gmail account dropped a whole lot of mail too in the last week of > > August. I was out of office that week so I didn't investigate. I was > > assuming it was an issue with vger... > > I don't think it's related to those issues. If I search lore including > my email[1], then it doesn't find it either. Lore only has it in > oe-kbuild. Not LKML or oe-kbuild-all. It really just looks like the > git-send-email style of extracting emails from tags in the body is not > happening. Oh, looks like there were two emails, one from lkp, and one from Dan: https://lore.kernel.org/all/eaa86211-436d-445b-80bd-84cea5745b5a@kadam.mountain I was referring to the one from Dan, which is not the one in Closes:. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() 2023-09-12 15:32 ` Rob Herring 2023-09-12 15:55 ` Geert Uytterhoeven @ 2023-09-13 6:28 ` Dan Carpenter 2023-09-13 12:44 ` Rob Herring 1 sibling, 1 reply; 10+ messages in thread From: Dan Carpenter @ 2023-09-13 6:28 UTC (permalink / raw) To: Rob Herring Cc: Geert Uytterhoeven, kbuild test robot, Frank Rowand, devicetree, linux-kernel, kernel-janitors On Tue, Sep 12, 2023 at 10:32:08AM -0500, Rob Herring wrote: > On Fri, Sep 8, 2023 at 11:14 AM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > > On Fri, Sep 08, 2023 at 05:34:53PM +0200, Geert Uytterhoeven wrote: > > > > > Fixes: 914d9d831e61 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock") > > > > > Reported-by: kernel test robot <lkp@intel.com> > > > > > Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/ > > > > > > > > Despite what that says, it was never reported to me. IOW, the added TO > > > > and CC lines don't seem to have any effect. > > > > > > The copy I received did list you in the "To"-header, though. > > Are you sure that's the header and not in the body? > How these warnings work is that the kbuild bot sends the email to me and the oe-kbuild@lists.linux.dev list. I look it over and send it out publicly if the warning seems right. You're seeing the first email that I hadn't forwarded yet but the second forwarded email went out and it reached lkml. https://lore.kernel.org/lkml/eaa86211-436d-445b-80bd-84cea5745b5a@kadam.mountain/raw You're on the To: header so it should have reached you as well... regards, dan carpenter ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() 2023-09-13 6:28 ` Dan Carpenter @ 2023-09-13 12:44 ` Rob Herring 0 siblings, 0 replies; 10+ messages in thread From: Rob Herring @ 2023-09-13 12:44 UTC (permalink / raw) To: Dan Carpenter Cc: Geert Uytterhoeven, kbuild test robot, Frank Rowand, devicetree, linux-kernel, kernel-janitors On Wed, Sep 13, 2023 at 1:29 AM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > On Tue, Sep 12, 2023 at 10:32:08AM -0500, Rob Herring wrote: > > On Fri, Sep 8, 2023 at 11:14 AM Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > > > > On Fri, Sep 08, 2023 at 05:34:53PM +0200, Geert Uytterhoeven wrote: > > > > > > Fixes: 914d9d831e61 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock") > > > > > > Reported-by: kernel test robot <lkp@intel.com> > > > > > > Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/ > > > > > > > > > > Despite what that says, it was never reported to me. IOW, the added TO > > > > > and CC lines don't seem to have any effect. > > > > > > > > The copy I received did list you in the "To"-header, though. > > > > Are you sure that's the header and not in the body? > > > > How these warnings work is that the kbuild bot sends the email to me and > the oe-kbuild@lists.linux.dev list. I look it over and send it out > publicly if the warning seems right. > > You're seeing the first email that I hadn't forwarded yet but the second > forwarded email went out and it reached lkml. > > https://lore.kernel.org/lkml/eaa86211-436d-445b-80bd-84cea5745b5a@kadam.mountain/raw > > You're on the To: header so it should have reached you as well... Ah, okay. I have that one. It just got dumped off to my lkml folder rather than one I have for 0-day which I actually look at. Thanks for the explanation. Looks like I need to adjust my filters for these. Rob ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() 2023-09-08 7:03 [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() Dan Carpenter 2023-09-08 7:16 ` Geert Uytterhoeven 2023-09-08 15:18 ` Rob Herring @ 2023-09-11 14:58 ` Rob Herring 2 siblings, 0 replies; 10+ messages in thread From: Rob Herring @ 2023-09-11 14:58 UTC (permalink / raw) To: Dan Carpenter Cc: Rob Herring, devicetree, Frank Rowand, kernel-janitors, linux-kernel, Geert Uytterhoeven On Fri, 08 Sep 2023 10:03:50 +0300, Dan Carpenter wrote: > Smatch complains that the error path where "action" is invalid leaks > the "ce" allocation: > drivers/of/dynamic.c:935 of_changeset_action() > warn: possible memory leak of 'ce' > > Fix this by doing the validation before the allocation. > > Fixes: 914d9d831e61 ("of: dynamic: Refactor action prints to not use "%pOF" inside devtree_lock") > Reported-by: kernel test robot <lkp@intel.com> > Closes: https://lore.kernel.org/r/202309011059.EOdr4im9-lkp@intel.com/ > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> > --- > drivers/of/dynamic.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > Applied, thanks! ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-09-13 12:44 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-09-08 7:03 [PATCH] of: dynamic: Fix potential memory leak in of_changeset_action() Dan Carpenter 2023-09-08 7:16 ` Geert Uytterhoeven 2023-09-08 15:18 ` Rob Herring 2023-09-08 15:34 ` Geert Uytterhoeven 2023-09-08 16:14 ` Dan Carpenter 2023-09-12 15:32 ` Rob Herring 2023-09-12 15:55 ` Geert Uytterhoeven 2023-09-13 6:28 ` Dan Carpenter 2023-09-13 12:44 ` Rob Herring 2023-09-11 14:58 ` Rob Herring
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).