firmware: arm_scmi: move boiler plate code into the get info functions
Subsystems (3)
PATCH 1/1 firmware: arm_scmi: move boiler plate code into the get info functions
In reply to a message not in the archiveThis 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.
Remove 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 the pin case so this makes things a bit more uniform.
Also remove the check for if (!pin) since pin is an offset into the middle of an array and can't be NULL.
---
I had sent this as an RFC earlier. It can just go in by itself.
https://lore.kernel.org/all/aDmpD9qz-4RUXvFq@pluto/
drivers/firmware/arm_scmi/pinctrl.c | 108 +++++++++++++--------------- 1 file changed, 48 insertions(+), 60 deletions(-)
drivers/firmware/arm_scmi/pinctrl.c +48 -60
@@ -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;
Signature · 1 line
2.51.0
PATCH 1/1 pinctrl-scmi: remove unused struct members
In reply to a message not in the archiveThe ->pins and ->nr_pins members are not used so delete them.
---
I sent this as part of an RFC earlier. In this version I deleted ->pins as well.
This can just go in by itself. It goes through Linus's tree since it's int the drivers/pinctrl/ directory.
drivers/pinctrl/pinctrl-scmi.c | 2 -- 1 file changed, 2 deletions(-)
drivers/pinctrl/pinctrl-scmi.c +0 -2
@@ -40,8 +40,6 @@ struct scmi_pinctrl {struct pinctrl_desc pctl_desc;struct pinfunction *functions;unsigned int nr_functions; -struct pinctrl_pin_desc *pins; -unsigned int nr_pins; };static int pinctrl_scmi_get_groups_count (struct pinctrl_dev *pctldev)
Signature · 1 line
2.51.0
Re: [PATCH] pinctrl-scmi: remove unused struct members
Quoted 3 lines · Dan Carpenter
The ->pins and ->nr_pins members are not used so delete them.
Signed-off-by Dan Carpenter <[email protected]>
Patch applied!
Yours,
Linus Walleij
Sudeep Holla
AppliedQuoted 10 lines · Dan Carpenter
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.Remove 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 the pin case so this makes things a bit more uniform.[...]
Applied to sudeep.holla/linux (for-next/scmi/updates), thanks!
[1/1] firmware: arm_scmi: move boiler plate code into the get info functions
https://git.kernel.org/sudeep.holla/c/a3c46c82d8a2
--
Regards,
Sudeep