Linux Power Management development
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: longlong yan <yanlonglong@kylinos.cn>, shuah@kernel.org
Cc: jkacur@redhat.com, jwyatt@redhat.com,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	sageofredondo@gmail.com, trenn@suse.com,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH v2] cpupower/debug/i386: check mmap return value in main
Date: Fri, 17 Jul 2026 14:01:37 -0600	[thread overview]
Message-ID: <7f6a28eb-ea4d-4c9e-9aed-ed184b5d22e4@linuxfoundation.org> (raw)
In-Reply-To: <20260717013125.974-1-yanlonglong@kylinos.cn>

On 7/16/26 19:31, longlong yan wrote:
> The return value of mmap() is not checked. On failure mmap() returns
> MAP_FAILED, not NULL. If mmap() fails, the subsequent for-loop
> dereferences the invalid pointer (MAP_FAILED), causing a segfault.
> 
> Add a check for MAP_FAILED after mmap(), consistent with the existing
> error handling style for open() in the same function.
> 

-----
> Changes in v2:
> - Remove trailing whitespace and blank row
-----

The above changes in v2 information should be placed under
the --- after the Signed-off-by
> 
> Fixes: 7fe2f6399a84 ("cpupowerutils - cpufrequtils extended with quite some features")
> Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
> ---

Here - otherwise it becomes part of the commit log and we
don't want that.

Please send v3.

>   tools/power/cpupower/debug/i386/dump_psb.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/tools/power/cpupower/debug/i386/dump_psb.c b/tools/power/cpupower/debug/i386/dump_psb.c
> index 6fb81b42ea61..fcbb73b48acb 100644
> --- a/tools/power/cpupower/debug/i386/dump_psb.c
> +++ b/tools/power/cpupower/debug/i386/dump_psb.c
> @@ -182,6 +182,11 @@ main(int argc, char *argv[])
>   	mem = mmap(mem, 0x100000 - 0xc0000, PROT_READ, MAP_SHARED, fd, 0xc0000);
>   	close(fd);
>   
> +	if (mem == MAP_FAILED) {
> +		printf("Couldn't mmap /dev/mem\n");
> +		exit(1);
> +	}
> +
>   	for (p = mem; p - mem < LEN; p+=16) {
>   		if (memcmp(p, "AMDK7PNOW!", 10) == 0) {
>   			decode_psb(p, numpst);

thanks,
-- Shuah

      reply	other threads:[~2026-07-17 20:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29  3:11 [PATCH] cpupower/debug/i386: check mmap return value in main longlong yan
2026-07-16 23:26 ` Shuah
2026-07-17  1:31   ` [PATCH v2] " longlong yan
2026-07-17 20:01     ` Shuah Khan [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=7f6a28eb-ea4d-4c9e-9aed-ed184b5d22e4@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=jkacur@redhat.com \
    --cc=jwyatt@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sageofredondo@gmail.com \
    --cc=shuah@kernel.org \
    --cc=trenn@suse.com \
    --cc=yanlonglong@kylinos.cn \
    /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