From nobody Mon Feb 9 05:53:21 2026 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (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 14CF23A5C07 for ; Thu, 22 Jan 2026 16:17:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769098661; cv=none; b=dLknrA3gJlSLr7vbFMQJTxuagWOS56ZeNFKzoYhSWVRK13DxpFQ5liFxwCCrRx6WrkRKugX9Zp3J+jGtTz4q/elTntA7wdKmKEoZvW25vD6yGSEa7CRTvcUujwEuCJ4bCU4tzdyTb2xr0zj1cx9c6IQyBP6vjPi7oJpwnEGFOI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769098661; c=relaxed/simple; bh=HjeLQ8qD73Sk2YMD1wucS1WtV6wsk+vAzVdelCP67H0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=MxB/OWQ5eavoOWSHHfLh//te/7QIbd4kqbbTre6s2ri4PJm/3B/nbX4eTlNPOfGDa+pYsRRXPn5QaNjhXZUNBaCuijYlcFrYS5ycUOyb4S/oRsF3C6tV2ocMkmoWWsg+oTIlzvPoawOovzCK68lBDoAHlP4lPuGQU1IpEvjhXr8= 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=XM6LKQRj; arc=none smtp.client-ip=209.85.208.176 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="XM6LKQRj" Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-382f0732612so7078751fa.1 for ; Thu, 22 Jan 2026 08:17:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769098651; x=1769703451; 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=RXPPA+2hVnuz9+lpDAGfbv/AXvnSUFySkKsxMNbKNAk=; b=XM6LKQRjYZMYVc/GQ0nTnay3wHCO36WhhN4lymFsIQGrajDYollRWX+IrezfXUElyX ptMYJXbc72lgRD6perHXAU6d5SiGo0npo4JKFpvQtdv3lOgMUvNJfx/G2mIOMh1whs5b NsJecxk4KFThOPf6F4ssozZPDcw23Li/dJOAI6LkjqpxEs0T79YauxHf3wWBYDHPJGyP 9q/vyztoy/0eMmMH1iG7jfbp2/THk83bDozGztjhIjhIh3PJeNlCFoU8p7ZyqI5Xsj/v 9S/heUxBOnQmJMV5PTsgkpmgn40FQrYyexIl2nIZlA9X8HdXUOiFLX1wooxeTv8mswZr v/jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769098651; x=1769703451; 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=RXPPA+2hVnuz9+lpDAGfbv/AXvnSUFySkKsxMNbKNAk=; b=spl7TxgQU8HbmsN1Ii0rbjv7GN+mVt8o0OzSxvay3zC00B+bvAp26kapo96gXqwx0p wI1kF2J3w/IYMn7nT3vjtIsvk+krfeYOaPqDFcnTIhMVPX4LKoYgnB/oZEcVcwg8xHcK SEYcL6wzWodS/nDvZg6O0YZKqhAMloseAM+gzPxgPISPQqAn+LIufbTo0ihNjLZ+vJOC Md6tbm2LiPuI90vtrCpBxXv9pexuxQOnEwyOCW8JyP4fO7ruqMTKXIunxhaa/kmwgNkQ yDD7N4F6vUAmxMmh+L0bjW2c6ZfuMe1r149P6SAk3FjCVa3iywCIDsg7EGoeVQct8o5t ie8Q== X-Forwarded-Encrypted: i=1; AJvYcCXBaMsgKHVntvkNvL2wTJsnsSJJoR8vXikIiVTyOALv8wjpV/UcDJzA/+RS82F4jXj6ZkiUbexWPEbM+IM=@vger.kernel.org X-Gm-Message-State: AOJu0YyNAd0R4piCsWP6QsBbaSTSzDDFobW843iCL3wsKe0ZFMlStPTy jp5KQFF1QXD1heleG1cMSyGHMGnJ4YtgoV8V+9POMV11oXP0Btpfx/lpZlKLjbFQk4Y= X-Gm-Gg: AZuq6aIZXgq5+rhSsPPK+MEpTWYlfThrGqlNVQnQQGyFvRrvH6+A9IoK4ebDcpkP7xT 58uJCkg0AEFqUPoOrUOzL+CgJ/y0ZqD6ik5+JaRoqBp0JoexHxDd71H6WCzDF8Tslt9Omaa+ICA acGqeRE60ATnFNojDVTvLYCzr4M3S+WyR5P6WLIH5SARvdVDn2NCS67BGbMHP2E3Rdk3wYJZxpb VY9WJwjt4slsr3A4Zqa6MHFh+UT9WkGsx5OWxtKHKx66J6L2hqDVjmOvRj5RY/BVpbK2Z4eTDRV BhJQe+QunAEAmDFEx4VRV9fwu9gtsW9wnQEgf+SH1K8DjXyBga2aL9UU5NjZ7FDgFZMk7oLRubt VOXv9l96ZtwOfg4Vmh3gxl2Luia2nMLIFfhN6+HakqqT71bpdl9NpzSXkLH7fsKSW4yravR62UX CbXdGYErI5UImIRs4sxGpTH5izaIGQDQ== X-Received: by 2002:a05:651c:31c6:b0:37a:84e5:a1cc with SMTP id 38308e7fff4ca-38386a37928mr72388961fa.22.1769098650866; Thu, 22 Jan 2026 08:17:30 -0800 (PST) Received: from NB-6746.corp.yadro.com ([188.243.183.148]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-38384fb94f6sm56092161fa.49.2026.01.22.08.17.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jan 2026 08:17:30 -0800 (PST) From: Artem Shimko To: Sudeep Holla , Cristian Marussi Cc: Artem Shimko , arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] firmware: arm_scmi: extract domain ID validation helpers Date: Thu, 22 Jan 2026 19:17:27 +0300 Message-ID: <20260122161728.1225583-1-a.shimko.dev@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" Refactor the voltage protocol implementation by moving repeated domain ID boundary checks into dedicated inline functions. This reduces code duplication and improves maintainability. The new helpers are scmi_voltage_domain_validate_id() which validates a domain ID and returns an error code, and scmi_voltage_domain_lookup() which returns a pointer to the domain structure or an error pointer. These are used consistently across the voltage operations. No functional changes are introduced - the validation logic remains identical to the original inline checks. Signed-off-by: Artem Shimko --- Hello maintainers and reviewers, Continuing the refactoring work from the previous one [1], this patch extracts repeated domain ID boundary checks in the voltage protocol into dedicated helper functions. This improves code maintainability by reducing duplication and centralizing the validation logic. The patch introduces two inline helpers: * scmi_voltage_domain_validate_id(): validates domain ID and returns an error code * scmi_voltage_domain_lookup(): returns pointer to domain struct or error Thank you! [1] https://lore.kernel.org/all/20251103161044.2269377-1-a.shimko.dev@gmail= .com/T/#u -- Regards, artem drivers/firmware/arm_scmi/voltage.c | 59 ++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/drivers/firmware/arm_scmi/voltage.c b/drivers/firmware/arm_scm= i/voltage.c index 17127880e10a..62010df24053 100644 --- a/drivers/firmware/arm_scmi/voltage.c +++ b/drivers/firmware/arm_scmi/voltage.c @@ -262,15 +262,37 @@ static int scmi_voltage_descriptors_get(const struct = scmi_protocol_handle *ph, return ret; } =20 +static inline int +scmi_voltage_domain_validate_id(const struct scmi_protocol_handle *ph, u32= domain_id) +{ + struct voltage_info *vinfo =3D ph->get_priv(ph); + + if (domain_id >=3D vinfo->num_domains) + return -EINVAL; + + return 0; +} + +static inline struct scmi_voltage_info * +scmi_voltage_domain_lookup(const struct scmi_protocol_handle *ph, u32 doma= in_id) +{ + struct voltage_info *vinfo =3D ph->get_priv(ph); + + if (domain_id >=3D vinfo->num_domains) + return ERR_PTR(-EINVAL); + + return vinfo->domains + domain_id; +} + static int __scmi_voltage_get_u32(const struct scmi_protocol_handle *ph, u8 cmd_id, u32 domain_id, u32 *value) { int ret; struct scmi_xfer *t; - struct voltage_info *vinfo =3D ph->get_priv(ph); =20 - if (domain_id >=3D vinfo->num_domains) - return -EINVAL; + ret =3D scmi_voltage_domain_validate_id(ph, domain_id); + if (ret) + return ret; =20 ret =3D ph->xops->xfer_get_init(ph, cmd_id, sizeof(__le32), 0, &t); if (ret) @@ -290,11 +312,11 @@ static int scmi_voltage_config_set(const struct scmi_= protocol_handle *ph, { int ret; struct scmi_xfer *t; - struct voltage_info *vinfo =3D ph->get_priv(ph); struct scmi_msg_cmd_config_set *cmd; =20 - if (domain_id >=3D vinfo->num_domains) - return -EINVAL; + ret =3D scmi_voltage_domain_validate_id(ph, domain_id); + if (ret) + return ret; =20 ret =3D ph->xops->xfer_get_init(ph, VOLTAGE_CONFIG_SET, sizeof(*cmd), 0, &t); @@ -325,25 +347,23 @@ static int scmi_voltage_level_set(const struct scmi_p= rotocol_handle *ph, { int ret; struct scmi_xfer *t; - struct voltage_info *vinfo =3D ph->get_priv(ph); struct scmi_msg_cmd_level_set *cmd; - struct scmi_voltage_info *v; + struct scmi_voltage_info *vi; =20 - if (domain_id >=3D vinfo->num_domains) - return -EINVAL; + vi =3D scmi_voltage_domain_lookup(ph, domain_id); + if (IS_ERR(vi)) + return PTR_ERR(vi); =20 ret =3D ph->xops->xfer_get_init(ph, VOLTAGE_LEVEL_SET, sizeof(*cmd), 0, &t); if (ret) return ret; =20 - v =3D vinfo->domains + domain_id; - cmd =3D t->tx.buf; cmd->domain_id =3D cpu_to_le32(domain_id); cmd->voltage_level =3D cpu_to_le32(volt_uV); =20 - if (!v->async_level_set || mode !=3D SCMI_VOLTAGE_LEVEL_SET_AUTO) { + if (!vi->async_level_set || mode !=3D SCMI_VOLTAGE_LEVEL_SET_AUTO) { cmd->flags =3D cpu_to_le32(0x0); ret =3D ph->xops->do_xfer(ph, t); } else { @@ -356,7 +376,7 @@ static int scmi_voltage_level_set(const struct scmi_pro= tocol_handle *ph, if (le32_to_cpu(resp->domain_id) =3D=3D domain_id) dev_dbg(ph->dev, "Voltage domain %d set async to %d\n", - v->id, + vi->id, le32_to_cpu(resp->voltage_level)); else ret =3D -EPROTO; @@ -377,13 +397,16 @@ static int scmi_voltage_level_get(const struct scmi_p= rotocol_handle *ph, static const struct scmi_voltage_info * __must_check scmi_voltage_info_get(const struct scmi_protocol_handle *ph, u32 domain_id) { - struct voltage_info *vinfo =3D ph->get_priv(ph); + struct scmi_voltage_info *vi; =20 - if (domain_id >=3D vinfo->num_domains || - !vinfo->domains[domain_id].num_levels) + vi =3D scmi_voltage_domain_lookup(ph, domain_id); + if (IS_ERR(vi)) return NULL; =20 - return vinfo->domains + domain_id; + if (!vi->num_levels) + return NULL; + + return vi; } =20 static int scmi_voltage_domains_num_get(const struct scmi_protocol_handle = *ph) --=20 2.43.0