From: Dan Carpenter <dan.carpenter@linaro.org>
To: Sudeep Holla <sudeep.holla@arm.com>,
AKASHI Takahiro <takahiro.akashi@linaro.org>,
Michal Simek <michal.simek@amd.com>
Cc: Cristian Marussi <cristian.marussi@arm.com>,
arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH RFC v2 1/7] firmware: arm_scmi: move boiler plate code into the get info functions
Date: Sun, 20 Jul 2025 14:38:35 -0500 [thread overview]
Message-ID: <7a47cf3d-05e1-4702-87ef-cb7f36f03149@sabinyo.mountain> (raw)
In-Reply-To: <cover.1753039612.git.dan.carpenter@linaro.org>
This code to check whether the selector is valid and if the item has
already been recorded in the array can be moved to the
scmi_pinctrl_get_function_info() type functions. That way it's in
one place instead of duplicated in each of the callers.
I removed the check for if "pi->nr_groups == 0" because if that were the
case then "selector >= pi->nr_groups" would already be true. It already
was not checked for pins so this makes things a bit more uniform.
I also removed the check for if (!pin) since pin is an offset into the
middle of an array and can't be NULL.
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/firmware/arm_scmi/pinctrl.c | 108 +++++++++++++---------------
1 file changed, 48 insertions(+), 60 deletions(-)
diff --git a/drivers/firmware/arm_scmi/pinctrl.c b/drivers/firmware/arm_scmi/pinctrl.c
index 3855c98caf06..d18c2d248f04 100644
--- a/drivers/firmware/arm_scmi/pinctrl.c
+++ b/drivers/firmware/arm_scmi/pinctrl.c
@@ -596,11 +596,19 @@ static int scmi_pinctrl_pin_free(const struct scmi_protocol_handle *ph, u32 pin)
}
static int scmi_pinctrl_get_group_info(const struct scmi_protocol_handle *ph,
- u32 selector,
- struct scmi_group_info *group)
+ u32 selector)
{
+ struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+ struct scmi_group_info *group;
int ret;
+ if (selector >= pi->nr_groups)
+ return -EINVAL;
+
+ group = &pi->groups[selector];
+ if (group->present)
+ return 0;
+
ret = scmi_pinctrl_attributes(ph, GROUP_TYPE, selector, group->name,
&group->nr_pins);
if (ret)
@@ -632,21 +640,14 @@ static int scmi_pinctrl_get_group_name(const struct scmi_protocol_handle *ph,
u32 selector, const char **name)
{
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+ int ret;
if (!name)
return -EINVAL;
- if (selector >= pi->nr_groups || pi->nr_groups == 0)
- return -EINVAL;
-
- if (!pi->groups[selector].present) {
- int ret;
-
- ret = scmi_pinctrl_get_group_info(ph, selector,
- &pi->groups[selector]);
- if (ret)
- return ret;
- }
+ ret = scmi_pinctrl_get_group_info(ph, selector);
+ if (ret)
+ return ret;
*name = pi->groups[selector].name;
@@ -658,21 +659,14 @@ static int scmi_pinctrl_group_pins_get(const struct scmi_protocol_handle *ph,
u32 *nr_pins)
{
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+ int ret;
if (!pins || !nr_pins)
return -EINVAL;
- if (selector >= pi->nr_groups || pi->nr_groups == 0)
- return -EINVAL;
-
- if (!pi->groups[selector].present) {
- int ret;
-
- ret = scmi_pinctrl_get_group_info(ph, selector,
- &pi->groups[selector]);
- if (ret)
- return ret;
- }
+ ret = scmi_pinctrl_get_group_info(ph, selector);
+ if (ret)
+ return ret;
*pins = pi->groups[selector].group_pins;
*nr_pins = pi->groups[selector].nr_pins;
@@ -681,11 +675,19 @@ static int scmi_pinctrl_group_pins_get(const struct scmi_protocol_handle *ph,
}
static int scmi_pinctrl_get_function_info(const struct scmi_protocol_handle *ph,
- u32 selector,
- struct scmi_function_info *func)
+ u32 selector)
{
+ struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+ struct scmi_function_info *func;
int ret;
+ if (selector >= pi->nr_functions)
+ return -EINVAL;
+
+ func = &pi->functions[selector];
+ if (func->present)
+ return 0;
+
ret = scmi_pinctrl_attributes(ph, FUNCTION_TYPE, selector, func->name,
&func->nr_groups);
if (ret)
@@ -716,21 +718,14 @@ static int scmi_pinctrl_get_function_name(const struct scmi_protocol_handle *ph,
u32 selector, const char **name)
{
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+ int ret;
if (!name)
return -EINVAL;
- if (selector >= pi->nr_functions || pi->nr_functions == 0)
- return -EINVAL;
-
- if (!pi->functions[selector].present) {
- int ret;
-
- ret = scmi_pinctrl_get_function_info(ph, selector,
- &pi->functions[selector]);
- if (ret)
- return ret;
- }
+ ret = scmi_pinctrl_get_function_info(ph, selector);
+ if (ret)
+ return ret;
*name = pi->functions[selector].name;
return 0;
@@ -742,21 +737,14 @@ scmi_pinctrl_function_groups_get(const struct scmi_protocol_handle *ph,
const u32 **groups)
{
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+ int ret;
if (!groups || !nr_groups)
return -EINVAL;
- if (selector >= pi->nr_functions || pi->nr_functions == 0)
- return -EINVAL;
-
- if (!pi->functions[selector].present) {
- int ret;
-
- ret = scmi_pinctrl_get_function_info(ph, selector,
- &pi->functions[selector]);
- if (ret)
- return ret;
- }
+ ret = scmi_pinctrl_get_function_info(ph, selector);
+ if (ret)
+ return ret;
*groups = pi->functions[selector].groups;
*nr_groups = pi->functions[selector].nr_groups;
@@ -771,13 +759,19 @@ static int scmi_pinctrl_mux_set(const struct scmi_protocol_handle *ph,
}
static int scmi_pinctrl_get_pin_info(const struct scmi_protocol_handle *ph,
- u32 selector, struct scmi_pin_info *pin)
+ u32 selector)
{
+ struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+ struct scmi_pin_info *pin;
int ret;
- if (!pin)
+ if (selector >= pi->nr_pins)
return -EINVAL;
+ pin = &pi->pins[selector];
+ if (pin->present)
+ return 0;
+
ret = scmi_pinctrl_attributes(ph, PIN_TYPE, selector, pin->name, NULL);
if (ret)
return ret;
@@ -790,20 +784,14 @@ static int scmi_pinctrl_get_pin_name(const struct scmi_protocol_handle *ph,
u32 selector, const char **name)
{
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
+ int ret;
if (!name)
return -EINVAL;
- if (selector >= pi->nr_pins)
- return -EINVAL;
-
- if (!pi->pins[selector].present) {
- int ret;
-
- ret = scmi_pinctrl_get_pin_info(ph, selector, &pi->pins[selector]);
- if (ret)
- return ret;
- }
+ ret = scmi_pinctrl_get_pin_info(ph, selector);
+ if (ret)
+ return ret;
*name = pi->pins[selector].name;
--
2.47.2
next prev parent reply other threads:[~2025-07-20 19:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-20 19:38 [PATCH RFC v2 0/7] pinctrl-scmi: Add GPIO support Dan Carpenter
2025-07-20 19:38 ` Dan Carpenter [this message]
2025-08-21 8:09 ` [PATCH RFC v2 1/7] firmware: arm_scmi: move boiler plate code into the get info functions Cristian Marussi
2025-07-20 19:38 ` [PATCH RFC v2 2/7] firmware: arm_scmi: add is_gpio() function Dan Carpenter
2025-08-21 8:19 ` Cristian Marussi
2025-07-20 19:38 ` [PATCH RFC v2 4/7] pinctrl-scmi: add PIN_CONFIG_INPUT_VALUE Dan Carpenter
2025-08-21 8:38 ` Cristian Marussi
2025-09-05 8:27 ` Linus Walleij
2025-09-05 8:31 ` Linus Walleij
2025-09-05 9:24 ` Linus Walleij
2025-07-20 19:39 ` [PATCH RFC v2 6/7] pinctrl-scmi: Add GPIO support Dan Carpenter
2025-08-14 8:39 ` Linus Walleij
2025-07-20 19:39 ` [PATCH RFC v2 5/7] pinctrl: Delete PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS support Dan Carpenter
2025-08-21 8:48 ` Cristian Marussi
2025-07-20 19:39 ` [PATCH RFC v2 7/7] pinctrl-scmi: remove unused struct member Dan Carpenter
2025-08-21 8:50 ` Cristian Marussi
2025-08-18 9:03 ` [PATCH RFC v2 0/7] pinctrl-scmi: Add GPIO support Linus Walleij
2025-09-04 8:49 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7a47cf3d-05e1-4702-87ef-cb7f36f03149@sabinyo.mountain \
--to=dan.carpenter@linaro.org \
--cc=arm-scmi@vger.kernel.org \
--cc=cristian.marussi@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@amd.com \
--cc=sudeep.holla@arm.com \
--cc=takahiro.akashi@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox