From nobody Mon May 25 01:15:08 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 D1F2A34250D for ; Wed, 20 May 2026 07:02:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779260544; cv=none; b=olmliX1puPr4Wc+APVOIKpnMk7kifaOSC2g5n3952xrVm8ph98O5Uzy3V3imkp3J0QKNu6KeFR5RhUzsXDSs+As1FYntI9e96ZnXrqdEzmmipdvyf7qEkw0YWpE1ZhbT5vkMQJrraVly1FSqfaQdEA/JvxmI4jIVoAIAVaOuEgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779260544; c=relaxed/simple; bh=+mGoF9JwgI6c+QZpu+TCNir986u8wYfMWu5E5ArQeng=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=juC9rQhKrZxUVs1tSaoP2oTQG4SiZJFeLANB+EHEluKMJT8IankQylvGXW55KUjb0HAeV+SeMsubfgICvaDSm2gzrGVx2MRVaEF18tfILXq9YBmTlu3oMImczsyGkEnqO9ylz8M4o74MOf8FL7c0yCoIqRIFN8bjzo6NLYhRHzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NqDO34Ip; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NqDO34Ip" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2bab2548e8bso19382835ad.0 for ; Wed, 20 May 2026 00:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779260542; x=1779865342; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ywhZO2eqzRTajRbw+DBdw5fKWMJj8Wquqh8z21Ew4Lg=; b=NqDO34IpVb7Uzq9aITosOpIrVCeqQBQ72BpK4A8MJsVq1tyzc5GrS3kBlRvf759/F9 xlj3uFlenvkm4aPcw+BxAguN5iCoo9tNcbgbN3t6/AF8LXfDBBppR2kryHqAr8zGctG/ NCmQpU1elHlGQwhkrCo7ZOTSJzKlTJb624BhKs5Zj6xxJPZvOINAarcmWPhM4xjwN2G5 TOjEyiZaJkG9sO7xxPwD+JLBLBlp++aoufjlQdfFeIM30foc3ruhEHkDRUIyy2dPxw/V cHDJ0dR+YBnp3ZLKTXpn0nKCjXBgsU1J6asn1r+Hc70EmEL+Z+2a76N+x0OAbEhwXWAL bOBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779260542; x=1779865342; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ywhZO2eqzRTajRbw+DBdw5fKWMJj8Wquqh8z21Ew4Lg=; b=fXri/vHX0MzCLIYBHl+P888IWAaN+FofgQAL1tTuaxaZVxU6qGMz5E28LDbXssq2j5 dYE+3Ytfd8aGwK9nLyLVvev9IE7TtvcW6k7HDn7SQIUT9L1kZvkYOq6zj9z0j9n0lCYa zKgkiX6PoMYTslTafPGDZ1uEOrvD09b81jRkNRAetvE0M4JL8G+iNrFrLNdAoz+EkcDB eFxtu0nO4MIbiWB8KTk4h+8TGXFUyH1OQmGu3dviPEL3rDYN+uUJNYc8fYXteOr0pWMH i9k+1efdIksl/eoB9w+eN8OPHrBU1nO0KxAtXNFoMsXqxj8Fd86ShBdBVRtElQe7wJGU 6Bnw== X-Forwarded-Encrypted: i=1; AFNElJ/PjlVGDimL7yzcWAeOj1H+KvRBmdNdJhNEbALPgA6XzcXpaSJgNOKHcRjomKbTVWT3uEJ6kit63kNLTzo=@vger.kernel.org X-Gm-Message-State: AOJu0YzE2zbTmH+al8UAdmLG1W6NxcoEVOsQELX2jgAR7VCJYsdUNaVz V2qw5g4QdA+TvUvhGFPPcSsXOw+6tgiZXIjMJawQ6bsRTJx5YuGEraCw X-Gm-Gg: Acq92OE9ui8D0LAFquJ+sFpzlZUnGpOPydmMnuP4m81ED5hSE2NXOS+7z5I79H1TzKP Tmd6eGqk4SEcZWf8V4HUPVaXUccFG6Rt1+Sv0vOg65zCgPinlaJf2/oa7X/jckuIMcGTeHK2ECP D7qaWsIk8T151LOJ5bJMDOfheO8mw8XixBDO31CYxavOLO0iascmBkmj1Uywlx8iLOBtEx7aJT8 oOSuEWni6P6gCfLaGFvClA88/+wPxQxTf7is/q9ZsAYlRzNJgdSqKw6JZtPWN11S4jy++4pOr8A UQSnzcaONDW91QXLCR9A25V8zwmBGQ83M6kofq662HY8jVeIL98L3MsKn4vHb/2TnXNe5iUf3HV Z/4q/xtmeutxUQG/sCtnq47kebOrsQQdaQCqG3Oh2mjZLB3+QTFyxasQxy3FnFA7AXjxQvSKjvp J5pZR8yEjyF73wOAu6AUnMcTluGlAu9/vzbOUneDK/0wl69hngPKDFqHGVgpcWNYdvzvyOSVs= X-Received: by 2002:a17:903:1ae7:b0:2b2:49a7:a5bc with SMTP id d9443c01a7336-2bd7e9e5458mr233213185ad.39.1779260542004; Wed, 20 May 2026 00:02:22 -0700 (PDT) Received: from EDAMAMEPC.tail763c14.ts.net (p1188143-ipoe.ipoe.ocn.ne.jp. [122.26.33.142]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2bd5b568cefsm209708455ad.0.2026.05.20.00.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 00:02:21 -0700 (PDT) From: EDAMAMEX To: mario.limonciello@amd.com, ray.huang@amd.com Cc: perry.yuan@amd.com, kprateek.nayak@amd.com, rafael@kernel.org, viresh.kumar@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, EDAMAMEX Subject: [PATCH] cpufreq/amd-pstate: handle missing policy in dynamic EPP callbacks Date: Wed, 20 May 2026 16:02:11 +0900 Message-ID: <20260520070211.2753183-1-edame8080@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" cpufreq_cpu_get() returns NULL when no cpufreq policy is associated with the requested CPU, for example because the CPU is offline or the policy has already been torn down. Both amd_pstate_power_supply_notifier() and amd_pstate_profile_set() acquire a policy via cpufreq_cpu_get() and then pass that pointer to amd_pstate_get_balanced_epp() and amd_pstate_set_epp(), which dereference it unconditionally. A racing CPU hotplug or driver teardown can therefore lead to a NULL pointer dereference on either of these dynamic EPP paths. The third cpufreq_cpu_get() caller in this file, amd_pstate_verify(), already handles the NULL case. Bring the two new callers in line with that pattern: return NOTIFY_OK from the power-supply notifier (matching the other "nothing to do" exits) and -ENODEV from amd_pstate_profile_set() (the usual cpufreq error for a missing CPU policy). Found by code inspection; not tested on hardware. Fixes: e30ca6dd5345 ("cpufreq/amd-pstate: Add dynamic energy performance pr= eference") Fixes: 798c47593cca ("cpufreq/amd-pstate: Add support for platform profile = class") Signed-off-by: EDAMAMEX --- drivers/cpufreq/amd-pstate.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 453084c67..f659a54c7 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1183,6 +1183,9 @@ static int amd_pstate_power_supply_notifier(struct no= tifier_block *nb, if (cpudata->current_profile !=3D PLATFORM_PROFILE_BALANCED) return 0; =20 + if (!policy) + return NOTIFY_OK; + epp =3D amd_pstate_get_balanced_epp(policy); =20 ret =3D amd_pstate_set_epp(policy, epp); @@ -1218,6 +1221,9 @@ static int amd_pstate_profile_set(struct device *dev, struct cpufreq_policy *policy __free(put_cpufreq_policy) =3D cpufreq_cpu_= get(cpudata->cpu); int ret; =20 + if (!policy) + return -ENODEV; + switch (profile) { case PLATFORM_PROFILE_LOW_POWER: ret =3D amd_pstate_set_epp(policy, AMD_CPPC_EPP_POWERSAVE); --=20 2.43.0