public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Tom Rix <trix@redhat.com>
To: Chen Yu <yu.c.chen@intel.com>
Cc: lenb@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/power turbostat: close file after use
Date: Sat, 30 Apr 2022 07:49:19 -0700	[thread overview]
Message-ID: <d71b4f7d-70db-efb3-4eb8-93cf96ab7519@redhat.com> (raw)
In-Reply-To: <20220430141947.GA5101@chenyu5-mobl1>


On 4/30/22 7:19 AM, Chen Yu wrote:
> On Sat, Apr 30, 2022 at 10:15:57AM -0400, Tom Rix wrote:
>> The cppcheck reports this issue
>> turbostat.c:2039]: (error) Resource leak: fp
>>
>> When the fscanf fails an error is returned without closing fp.
>> Move the fclose so even if the fscanf fails, the file will be closed.
>>
>> Fixes: eae97e053fe3 ("tools/power turbostat: Support thermal throttle count print")
>> Signed-off-by: Tom Rix <trix@redhat.com>
>> ---
>>   tools/power/x86/turbostat/turbostat.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
>> index ede31a4287a0..2e9a751af260 100644
>> --- a/tools/power/x86/turbostat/turbostat.c
>> +++ b/tools/power/x86/turbostat/turbostat.c
>> @@ -2035,9 +2035,9 @@ int get_core_throt_cnt(int cpu, unsigned long long *cnt)
>>   	if (!fp)
>>   		return -1;
>>   	ret = fscanf(fp, "%lld", &tmp);
>> +	fclose(fp);
>>   	if (ret != 1)
>>   		return -1;
>> -	fclose(fp);
>>   	*cnt = tmp;
>>   
>>   	return 0;
>> --
> Thank you Tom, and Colin has proposed a fix here:
> https://lore.kernel.org/lkml/20220426131607.1520483-1-colin.i.king@gmail.com/

Obviously I approve of Colin's fix :)

If it is not too much trouble, please add

Reviewed-by: Tom Rix <trix@redhat.com>

If it is already on its way to linux-next, don't worry about it.

Thanks,

Tom

>
> thanks,
> Chenyu
>


      reply	other threads:[~2022-04-30 14:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-30 14:15 [PATCH] tools/power turbostat: close file after use Tom Rix
2022-04-30 14:19 ` Chen Yu
2022-04-30 14:49   ` Tom Rix [this message]

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=d71b4f7d-70db-efb3-4eb8-93cf96ab7519@redhat.com \
    --to=trix@redhat.com \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=yu.c.chen@intel.com \
    /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