From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0CB523645D for ; Mon, 20 Jul 2026 23:16:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784589399; cv=none; b=DqAn6urmjn4vgj4AMWXjeJO/l7dELj4zbCER/rEjPHad/jAaJyjbsng/NNd25sVw2hm5A9NRUyreDM0NkMMQKb8RNzledoCt8KGc5NFTFsI/KqGzK/QLiXc0x5bhDJAA4LPQagOllvf3QQLxupLCtULPytjmQv+DEpr+o9NiS48= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784589399; c=relaxed/simple; bh=iJTvM7FzbQufcWwG5DlwV7gilgwCwXQxdewlBg0Uckk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Muxh04KxfqQROU+vD+ISfC9vfpy3MhIICY2uGYP30J8szq+JgvQ44bGCvbsPQIi//pmj+U8ft00vWJHGHKVeNr9QhQBGtYGuDcjsaNpIYkMyIgHAMQhAdrMijIbH2rGtsL2GarN1tlAEdCGjqktv/ln17reTj7zOeOxwHGckVcE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=V1LwWaCe; arc=none smtp.client-ip=209.85.160.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="V1LwWaCe" Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-448cf99c133so2838718fac.1 for ; Mon, 20 Jul 2026 16:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1784589395; x=1785194195; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=nruANn1J2b318QWYJd0dvVE8ypNBnKBF2jdRb6cl/xM=; b=V1LwWaCe3Hg73zAlf2TvIVl5gc215CTSTVZ3HR21qgvORVee8jwPdKYakN0nHywtjE kHYkSl/DXTGg/GU4DE13xVl+61yUleSG4ClBKVcNc0UypyVJ2GR/9z7WHCvgQV0TdmWS y0RD7rpZrwV38564P03SCDap+wtwGPtl2jAGo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784589395; x=1785194195; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nruANn1J2b318QWYJd0dvVE8ypNBnKBF2jdRb6cl/xM=; b=eSphGtjLOZHlX3yKy2SeCKuVpjUOdDG2zex4xw3orRL5Eb4Z8InS3Chp1HAB6TM6B/ HAeOGveUanuVYLfLSWVSEr1aqgjNYTkeWG28Pd0EJ7S4cpRxh5+dxwE4g2mqcS3oZSnS VMTGUmYBx4HV3/AWppg1g2f0kN1FY8xK6f8ynq82YmVWRPYQGICd67n9QlKoLkS2mS6Z PrpH7frOLrKphEXFiBxBAlnrC0W4UGXgerdoO5krt9ocQgi/SdoWQNg3dekwnQ+x6wZU W4jpSIlVEutXP9zoRZN6CfNODGxPLczS9vE3V7Uw/elIYQM7V/h8rD3KVj6gn53vZp1+ MFbg== X-Forwarded-Encrypted: i=1; AHgh+RpQESbxmTvDrS432wZ9IGGVbH2qYO6g3yTEVNGNR3y7sVn3JazXS4s+J1PzqUGa1HtSGgfyh63b98tKKwk=@vger.kernel.org X-Gm-Message-State: AOJu0YzDANB0SeybpSPla6Q/nerggMf4NfHF/SpanaBRBuBBxOf2KiiT PThLT6S1Sr0qnqYI31sfTi9B+dMoGq5u5zevZIoPbZOuVLBWAlYR1MZ/BsKOwJFIL8g= X-Gm-Gg: AfdE7cmIYdssY/66U33sXNKh0OdWxZRwzU2/TUC0VYtLe5yzMvQ7D9tSxYU8KSEbFBc VnJNkZ9MBTauvfcDpPIYHVTABRBaQZbGMscy8+tjEsLmszfupzSf6ei3PMP1haOZv2gwnpIprcO teh3iLnJqCvEPgC/TMYpIxzD9UjhKhYTAesGFEkU1Tz5euG31h0omAnB0QJV4lG4e9HLzIhshF5 4sd0A3JelYTQSNunEcCAuMKeaCAteVzSr/u45bttZmD2amIzcopN+cr/6tE52ZAKDBIYit972fI vhW5BMxUNMBzssql43kTyRX88fWb/DimiYaqn2EBN/eWNlEmECPm1HGECb7xsZxEAvplQs1Xb1A jUYIsiTUujQzKUhSoWgBvjK9Ippta6styIPk+BHWtelHcNuVg5pqrrWlm/cQ638Og9LMZfP4dQc 7kD5sd0VhLi14= X-Received: by 2002:a05:6820:16a4:b0:6a1:8132:cb27 with SMTP id 006d021491bc7-6a51d57315emr7717381eaf.9.1784589395464; Mon, 20 Jul 2026 16:16:35 -0700 (PDT) Received: from [192.168.1.128] ([38.15.57.99]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-6a51a253d56sm8324491eaf.12.2026.07.20.16.16.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Jul 2026 16:16:33 -0700 (PDT) Message-ID: <46d783d4-5887-4d01-8260-233e484123f1@linuxfoundation.org> Date: Mon, 20 Jul 2026 17:16:30 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] cpupower/debug/i386: check mmap return value in main To: longlong yan Cc: jkacur@redhat.com, jwyatt@redhat.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, sageofredondo@gmail.com, shuah@kernel.org, trenn@suse.com, Shuah Khan References: <7f6a28eb-ea4d-4c9e-9aed-ed184b5d22e4@linuxfoundation.org> <20260720013437.428-1-yanlonglong@kylinos.cn> Content-Language: en-US From: Shuah Khan In-Reply-To: <20260720013437.428-1-yanlonglong@kylinos.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/19/26 19:34, 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. > > Fixes: 7fe2f6399a84 ("cpupowerutils - cpufrequtils extended with quite some features") > Signed-off-by: longlong yan > > Changes in v2: > - Remove trailing whitespace and blank row > > Changes in v3: > - Format Adjustment > --- This is where the change information needs to be placed. It is still not correct. Please refer to submitting patches documentation. > 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