linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@xilinx.com>
To: Johan Hovold <johan@kernel.org>,
	Navid Emamdoost <navid.emamdoost@gmail.com>
Cc: "Daniel Lezcano" <daniel.lezcano@linaro.org>,
	"Michal Simek" <michal.simek@xilinx.com>,
	linux-kernel@vger.kernel.org, emamd001@umn.edu,
	"Sören Brinkmann" <soren.brinkmann@xilinx.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] clocksource/drivers: Fix memory leaks in ttc_setup_clockevent and ttc_setup_clocksource
Date: Fri, 20 Dec 2019 09:37:44 +0100	[thread overview]
Message-ID: <3d72fe70-25fb-cdee-ac7d-bc1aa2ae5137@xilinx.com> (raw)
In-Reply-To: <20191220051013.GT22665@localhost>

On 20. 12. 19 6:10, Johan Hovold wrote:
> On Thu, Dec 19, 2019 at 06:09:21PM -0600, Navid Emamdoost wrote:
>> In the implementation of ttc_setup_clockevent() and
>> ttc_setup_clocksource(), the allocated memory for ttccs is leaked when
>> clk_notifier_register() fails. Use goto to direct the execution into error
>> handling path.
> 
> No, that memory was never leaked since that function did not return on
> registration errors before your patch.
> 
>> Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error")
> 
> Perhaps you meant to fix the actual leak that was added by this commit
> in a different function, ttc_setup_clockevent(), when returning on
> notifier-registration errors?
> 
> Also should the clock be left enabled on errors?
> 
>> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
>> ---
>>  drivers/clocksource/timer-cadence-ttc.c | 22 +++++++++++++---------
>>  1 file changed, 13 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c
>> index c6d11a1cb238..46d69982ad33 100644
>> --- a/drivers/clocksource/timer-cadence-ttc.c
>> +++ b/drivers/clocksource/timer-cadence-ttc.c
>> @@ -328,10 +328,8 @@ static int __init ttc_setup_clocksource(struct clk *clk, void __iomem *base,
>>  	ttccs->ttc.clk = clk;
>>  
>>  	err = clk_prepare_enable(ttccs->ttc.clk);
>> -	if (err) {
>> -		kfree(ttccs);
>> -		return err;
>> -	}
>> +	if (err)
>> +		goto release_ttcce;
>>  
>>  	ttccs->ttc.freq = clk_get_rate(ttccs->ttc.clk);
>>  
>> @@ -341,8 +339,10 @@ static int __init ttc_setup_clocksource(struct clk *clk, void __iomem *base,
>>  
>>  	err = clk_notifier_register(ttccs->ttc.clk,
>>  				    &ttccs->ttc.clk_rate_change_nb);
>> -	if (err)
>> +	if (err) {
>>  		pr_warn("Unable to register clock notifier.\n");
>> +		goto release_ttcce;
>> +	}
> 

+ this is IMHO v3 version. It means just label it properly and also keep
changes log.

Thanks,
Michal


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-12-20  8:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-20  0:09 [PATCH] clocksource/drivers: Fix memory leaks in ttc_setup_clockevent and ttc_setup_clocksource Navid Emamdoost
2019-12-20  5:10 ` Johan Hovold
2019-12-20  8:37   ` Michal Simek [this message]
2019-12-23 12:43 ` [PATCH] clocksource/drivers: Fix something " Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3d72fe70-25fb-cdee-ac7d-bc1aa2ae5137@xilinx.com \
    --to=michal.simek@xilinx.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=emamd001@umn.edu \
    --cc=johan@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=navid.emamdoost@gmail.com \
    --cc=soren.brinkmann@xilinx.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).