From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 B254E4D2ECC for ; Thu, 11 Jun 2026 20:47:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781210827; cv=none; b=adEeB8QMXNLTR8y6uIQq+dxnEwR8sOfiwEkq/K6QzUdwMIGvbekRZl8OASBM3BlqsTbWt4iPRzSATQd7UYH3qW0Adjjed3YC2vVdlA7qGYDjVleGBfOoaVAGClgPPiLnDSG58cIECB+oZtoDiR6/OmxcN3hhqdv/yKhMfoXswYI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781210827; c=relaxed/simple; bh=7Mwo+iIqdQx8E6U6qCCbr1Gq9IaDaII2ThvLIrQQF9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CABunNpqAeEgl2ehnqmMKlxdn9f7l2nHz1vs7EI0rVVL2HZB2TJ97HSipWrfqom9sCOvjKgNL+L6qstiTfVv0EeI1j+UZgQULbKE/G0Je6aD4k1reiRZTYgHTrmNCADihfYtVMYf5QKf5625/2Agqircm5MYfjuVdviowM6/nIs= 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=s5XZ+kR7; arc=none smtp.client-ip=209.85.221.46 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="s5XZ+kR7" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-46013161068so115774f8f.2 for ; Thu, 11 Jun 2026 13:47:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781210824; x=1781815624; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mdCZ9G/0ajheplZaMy2X4Fl2JukUf3RvZhBEz4Soe+w=; b=s5XZ+kR7J/dOzoB7pMEJOl8NTAb0c8qpKcgZrGo80Av7/DONx8gW+sp47lTaXNnTFs G8zr6HYUE3IaI+h5PXR5PpAzmxqoJ4JRsZBmlMtfdRkNET9ewXTvvdKFlLNlmccCYjg8 Ojt4/fheTpLCIrVsdBx20AQHXLtH8b3M78OVgsArOdvQVLzaR8mVR8MyhJ5Y4h9O9Akj uD9X8JOb10P1SDEpaMr9RCpoNnXRE3fMm1OvYygakMw2tM4uf9r+pgsHh1VHXAQXYYSa j3yWpc8PqwRsSBIklAJNAe/+uCIeJVRsNVlRo5QNPpawkGYWbOlkTuIBYRVzWNYcIjWe qBFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781210824; x=1781815624; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=mdCZ9G/0ajheplZaMy2X4Fl2JukUf3RvZhBEz4Soe+w=; b=Has7FyDIyx3UneKsLhaq2FgPvN/W4WNDOYriIBVu1+nGss0yb1j+AFNewOtpzjjlCc IT+I4NQLg/FEMphMjlLpvlSW8EqxVqWQ5rdoCt4CHZFjQMT/IHwKJNSawY0amz50wy6p Fs5O6KkXGk4rNPyqnUf/m9+SPJnVqEDou9i4jyTSyga4g6xclefKRnrpayHtQxuvMlsK eeu/4RiiTvJhv0u9W8+4LzIHwSQS9S2IpuFqjT0IH8zEYM2LkqnPWsyXgZU3Ewkcnl8Q iNT75Zu2H3yPmmT1atAgxf7P53Wg0Ct5mgIg6Q0CQ2wG0h9boA6E4x5+I4UysqxXOsut fUsQ== X-Forwarded-Encrypted: i=1; AFNElJ+pRPjUUiuj6lKWAm+1dO/aqC9R3QzylO43wNIjnqcNO6vgKGVJkPfW1Cxecqv4RMLZamXEl6WkEp7bmgw=@vger.kernel.org X-Gm-Message-State: AOJu0YyStLmN8p3EK0tjf0CRrPri9uUJ1EBLKvNo7QNLh073zpIUZ47r /DD0I69aGbLu6MPDvjEXdPcTb4MLaZ8AjsQGIRZzwBPBCcj4jsiOjPmLN6GviXrQ X-Gm-Gg: Acq92OEC6C0/hHxLhEaUJ8ZVMKr9tpOE+0lu0yWDMoO7ts7nlZtkyi1t49gHjsY7etS ftJWGsaO+KY3xW63etLjbFbmEoahxZ3zOLnnmzt4T8jCSVxEfS/iqUcJPLRilWqfJ21aB+aYZ+M qy8l4E2IWOt2JhNz5NWwz148UnsTJfCa3L19awb960189vRFjA9TyPzuEptZ9v5526UxCYUhkWY nD8gYSC483c2HAnd+wUVigy3htNcjEJO0mqFUmGVPQfmkGM3sLV7KdmFQljf5x49UjFJwLE++ju X84tvFKRZQkidHSDASPO+ocfYftMsu9TDw9wwRloUj6i5rPD8Dij4cBSdnwUPxBOLemKgztEuSW t7KeluEMsQQjyW6s9zL9M/tLYLrkjcAroRGmoK3sb7VrSYnH2QibbNeNaxFjTMFYTaJ5u54JLY8 x9a4Fl+kNQFXBfBR2SRqClbdqe8SXvhG3iY5IBb9ViwlIk2+roL+vCZd0mMNon9CRR3nYvY34tN XIVpUv3lfohXnXq4AOqCT5ILQ8KgWNQPu6FWq4crw== X-Received: by 2002:a05:6000:228a:b0:43c:ffee:ee94 with SMTP id ffacd0b85a97d-4606db8c6c6mr34423f8f.11.1781210824158; Thu, 11 Jun 2026 13:47:04 -0700 (PDT) Received: from MBP-Elazar-Leibovich.civet-hops.ts.net (bzq-85-130-200-168.static.bezeqint.net. [85.130.200.168]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4606c0d0947sm1727493f8f.16.2026.06.11.13.47.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 11 Jun 2026 13:47:03 -0700 (PDT) From: Elazar Leibovich To: linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , linux-kernel@vger.kernel.org, Sivan Zohar-Kotzer , Elazar Leibovich Subject: [PATCH 2/2] powercap: dtpm_devfreq: Guard em_pd_get() against NULL return in callbacks Date: Thu, 11 Jun 2026 23:46:58 +0300 Message-ID: <20260611204658.47987-3-elazarl@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260611204658.47987-1-elazarl@gmail.com> References: <20260611204658.47987-1-elazarl@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Sivan Zohar-Kotzer em_pd_get() returns NULL when the device has no energy model registered. All three dtpm callbacks dereference the perf domain without checking it: 1. set_pd_power_limit() — reachable from sysfs via the powercap constraint power_limit_uw store path. If NULL, return the current power limit unchanged (no-op) instead of crashing. 2. get_pd_power_uw() — reachable from sysfs via the power_uw read path. Return 0 if the EM is absent. 3. update_pd_power_uw() — called via dtpm_update_power(). Return -EINVAL if the EM is absent. This mirrors the equivalent NULL checks in dtpm_cpu.c. Note this only handles the case where the EM is already gone (or was never registered) when the callback starts. A callback racing with em_dev_unregister_perf_domain() can still observe a non-NULL perf domain that is freed underneath it; closing that race requires lifetime guarantees from the EM core and is addressed separately. Fixes: e44655617317 ("powercap/drivers/dtpm: Add dtpm devfreq with energy model support") Signed-off-by: Sivan Zohar-Kotzer Co-developed-by: Elazar Leibovich Signed-off-by: Elazar Leibovich --- drivers/powercap/dtpm_devfreq.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/powercap/dtpm_devfreq.c b/drivers/powercap/dtpm_devfreq.c index d1dff6ccab12..cf16e2756481 100644 --- a/drivers/powercap/dtpm_devfreq.c +++ b/drivers/powercap/dtpm_devfreq.c @@ -39,6 +39,9 @@ static int update_pd_power_uw(struct dtpm *dtpm) struct em_perf_domain *pd = em_pd_get(dev); struct em_perf_state *table; + if (!pd) + return -EINVAL; + rcu_read_lock(); table = em_perf_state_from_pd(pd); @@ -60,6 +63,9 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit) unsigned long freq; int i; + if (!pd) + return dtpm->power_limit; + rcu_read_lock(); table = em_perf_state_from_pd(pd); for (i = 0; i < pd->nr_perf_states; i++) { @@ -102,6 +108,9 @@ static u64 get_pd_power_uw(struct dtpm *dtpm) u64 power = 0; int i; + if (!pd) + return 0; + mutex_lock(&devfreq->lock); status = devfreq->last_status; mutex_unlock(&devfreq->lock); -- 2.50.1 (Apple Git-155)