]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
firmware: arm_scmi: Validate Powercap domains before state access
authorSudeep Holla <sudeep.holla@kernel.org>
Sun, 17 May 2026 19:02:43 +0000 (20:02 +0100)
committerSudeep Holla <sudeep.holla@kernel.org>
Wed, 20 May 2026 09:00:10 +0000 (10:00 +0100)
Powercap protocol v2 keeps local enable and last-cap state per domain.
The v2 enable helpers and disabled-domain cap_set path indexed that state
before checking that the supplied domain id was valid.

Validate the domain before touching the per-domain state.

Link: https://patch.msgid.link/20260517-scmi_fixes-v1-4-d86daec4defd@kernel.org
Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
drivers/firmware/arm_scmi/powercap.c

index ab9733f4458b81205b7e275456d918ae6037db55..27e3c805e92720af4d173d44480a03ee1964780e 100644 (file)
@@ -453,10 +453,14 @@ static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
                return -EINVAL;
 
        /* Just log the last set request if acting on a disabled domain */
-       if (PROTOCOL_REV_MAJOR(ph->version) >= 0x2 &&
-           !pi->states[domain_id].enabled) {
-               pi->states[domain_id].last_pcap = power_cap;
-               return 0;
+       if (PROTOCOL_REV_MAJOR(ph->version) >= 0x2) {
+               if (!scmi_powercap_dom_info_get(ph, domain_id))
+                       return -EINVAL;
+
+               if (!pi->states[domain_id].enabled) {
+                       pi->states[domain_id].last_pcap = power_cap;
+                       return 0;
+               }
        }
 
        return __scmi_powercap_cap_set(ph, pi, domain_id,
@@ -637,6 +641,9 @@ static int scmi_powercap_cap_enable_set(const struct scmi_protocol_handle *ph,
        if (PROTOCOL_REV_MAJOR(ph->version) < 0x2)
                return -EINVAL;
 
+       if (!scmi_powercap_dom_info_get(ph, domain_id))
+               return -EINVAL;
+
        if (enable == pi->states[domain_id].enabled)
                return 0;
 
@@ -678,6 +685,9 @@ static int scmi_powercap_cap_enable_get(const struct scmi_protocol_handle *ph,
        if (PROTOCOL_REV_MAJOR(ph->version) < 0x2)
                return 0;
 
+       if (!scmi_powercap_dom_info_get(ph, domain_id))
+               return -EINVAL;
+
        /*
         * Report always real platform state; platform could have ignored
         * a previous disable request. Default true on any error.