[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20190607120717.GA3109@zhanggen-UX430UQ>
Date: Fri, 7 Jun 2019 20:07:17 +0800
From: Gen Zhang <blackgod016574@...il.com>
To: Jiri Slaby <jslaby@...e.cz>
Cc: Stephen Boyd <sboyd@...nel.org>, mturquette@...libre.com,
linux-clk@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] clk: fix a missing-free bug in clk_cpy_name()
On Fri, Jun 07, 2019 at 11:10:37AM +0200, Jiri Slaby wrote:
> On 07. 06. 19, 3:52, Gen Zhang wrote:
> >>>>> @@ -3491,6 +3492,8 @@ static int clk_core_populate_parent_map(struct clk_core *core)
> >>>>> kfree_const(parents[i].name);
> >>>>> kfree_const(parents[i].fw_name);
> >>>>> } while (--i >= 0);
> >>>>> + kfree_const(parent->name);
> >>>>> + kfree_const(parent->fw_name);
> >>>>
> >>>> Both of them were just freed in the loop above, no?
> >>> for (i = 0, parent = parents; i < num_parents; i++, parent++)
> >>> Is 'parent' the same as the one from the loop above?
> >>
> >> Yes. Did it change somehow?
> > parent++?
>
> parent++ is done after the loop body. Or what do you mean?
>
> >>> Moreover, should 'parents[i].name' and 'parents[i].fw_name' be freed by
> >>> kfree_const()?
> >>>
> >>
> >> Yes? They're allocated with kstrdup_const() in clk_cpy_name(), or
> >> they're NULL by virtue of the kcalloc and then kfree_const() does
> >> nothing.
> > I re-examined clk_cpy_name(). They are the second parameter of
> > clk_cpy_name(). The first parameter is allocated, not the second one.
> > So 'parent->name' and 'parent->fw_name' should be freed, not
> > 'parents[i].name' or 'parents[i].fw_name'. Am I totally misunderstanding
> > this clk_cpy_name()? :-(
>
> The second parameter (the source) is parent_data[i].*, not parents[i].*
> (the destination). parent->fw_name and parent->name are properly freed
> in the do {} while loop as parents[i].name and parents[i].fw_name, given
> i hasn't changed yet. I am not sure what you mean at all. Are you
> uncertain about the C code flow?
>
> thanks,
> --
> js
> suse labs
Thanks your patient explainaton. I think I need some time to figure out
this part of code.
Thanks
Gen
Powered by blists - more mailing lists