Skip to content

Commit a3c46c8

Browse files
Dan Carpentersudeep-holla
authored andcommitted
firmware: arm_scmi: Move boiler plate code into the get info functions
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. Also remove 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> Reviewed-by: Cristian Marussi <cristian.marussi@arm.com> Message-Id: <287b5302f583e3535d50617ec3b0856e38253171.1761576798.git.dan.carpenter@linaro.org> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
1 parent f675386 commit a3c46c8

1 file changed

Lines changed: 48 additions & 60 deletions

File tree

drivers/firmware/arm_scmi/pinctrl.c

Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,19 @@ static int scmi_pinctrl_pin_free(const struct scmi_protocol_handle *ph, u32 pin)
596596
}
597597

598598
static int scmi_pinctrl_get_group_info(const struct scmi_protocol_handle *ph,
599-
u32 selector,
600-
struct scmi_group_info *group)
599+
u32 selector)
601600
{
601+
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
602+
struct scmi_group_info *group;
602603
int ret;
603604

605+
if (selector >= pi->nr_groups)
606+
return -EINVAL;
607+
608+
group = &pi->groups[selector];
609+
if (group->present)
610+
return 0;
611+
604612
ret = scmi_pinctrl_attributes(ph, GROUP_TYPE, selector, group->name,
605613
&group->nr_pins);
606614
if (ret)
@@ -632,21 +640,14 @@ static int scmi_pinctrl_get_group_name(const struct scmi_protocol_handle *ph,
632640
u32 selector, const char **name)
633641
{
634642
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
643+
int ret;
635644

636645
if (!name)
637646
return -EINVAL;
638647

639-
if (selector >= pi->nr_groups || pi->nr_groups == 0)
640-
return -EINVAL;
641-
642-
if (!pi->groups[selector].present) {
643-
int ret;
644-
645-
ret = scmi_pinctrl_get_group_info(ph, selector,
646-
&pi->groups[selector]);
647-
if (ret)
648-
return ret;
649-
}
648+
ret = scmi_pinctrl_get_group_info(ph, selector);
649+
if (ret)
650+
return ret;
650651

651652
*name = pi->groups[selector].name;
652653

@@ -658,21 +659,14 @@ static int scmi_pinctrl_group_pins_get(const struct scmi_protocol_handle *ph,
658659
u32 *nr_pins)
659660
{
660661
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
662+
int ret;
661663

662664
if (!pins || !nr_pins)
663665
return -EINVAL;
664666

665-
if (selector >= pi->nr_groups || pi->nr_groups == 0)
666-
return -EINVAL;
667-
668-
if (!pi->groups[selector].present) {
669-
int ret;
670-
671-
ret = scmi_pinctrl_get_group_info(ph, selector,
672-
&pi->groups[selector]);
673-
if (ret)
674-
return ret;
675-
}
667+
ret = scmi_pinctrl_get_group_info(ph, selector);
668+
if (ret)
669+
return ret;
676670

677671
*pins = pi->groups[selector].group_pins;
678672
*nr_pins = pi->groups[selector].nr_pins;
@@ -681,11 +675,19 @@ static int scmi_pinctrl_group_pins_get(const struct scmi_protocol_handle *ph,
681675
}
682676

683677
static int scmi_pinctrl_get_function_info(const struct scmi_protocol_handle *ph,
684-
u32 selector,
685-
struct scmi_function_info *func)
678+
u32 selector)
686679
{
680+
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
681+
struct scmi_function_info *func;
687682
int ret;
688683

684+
if (selector >= pi->nr_functions)
685+
return -EINVAL;
686+
687+
func = &pi->functions[selector];
688+
if (func->present)
689+
return 0;
690+
689691
ret = scmi_pinctrl_attributes(ph, FUNCTION_TYPE, selector, func->name,
690692
&func->nr_groups);
691693
if (ret)
@@ -716,21 +718,14 @@ static int scmi_pinctrl_get_function_name(const struct scmi_protocol_handle *ph,
716718
u32 selector, const char **name)
717719
{
718720
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
721+
int ret;
719722

720723
if (!name)
721724
return -EINVAL;
722725

723-
if (selector >= pi->nr_functions || pi->nr_functions == 0)
724-
return -EINVAL;
725-
726-
if (!pi->functions[selector].present) {
727-
int ret;
728-
729-
ret = scmi_pinctrl_get_function_info(ph, selector,
730-
&pi->functions[selector]);
731-
if (ret)
732-
return ret;
733-
}
726+
ret = scmi_pinctrl_get_function_info(ph, selector);
727+
if (ret)
728+
return ret;
734729

735730
*name = pi->functions[selector].name;
736731
return 0;
@@ -742,21 +737,14 @@ scmi_pinctrl_function_groups_get(const struct scmi_protocol_handle *ph,
742737
const u32 **groups)
743738
{
744739
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
740+
int ret;
745741

746742
if (!groups || !nr_groups)
747743
return -EINVAL;
748744

749-
if (selector >= pi->nr_functions || pi->nr_functions == 0)
750-
return -EINVAL;
751-
752-
if (!pi->functions[selector].present) {
753-
int ret;
754-
755-
ret = scmi_pinctrl_get_function_info(ph, selector,
756-
&pi->functions[selector]);
757-
if (ret)
758-
return ret;
759-
}
745+
ret = scmi_pinctrl_get_function_info(ph, selector);
746+
if (ret)
747+
return ret;
760748

761749
*groups = pi->functions[selector].groups;
762750
*nr_groups = pi->functions[selector].nr_groups;
@@ -771,13 +759,19 @@ static int scmi_pinctrl_mux_set(const struct scmi_protocol_handle *ph,
771759
}
772760

773761
static int scmi_pinctrl_get_pin_info(const struct scmi_protocol_handle *ph,
774-
u32 selector, struct scmi_pin_info *pin)
762+
u32 selector)
775763
{
764+
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
765+
struct scmi_pin_info *pin;
776766
int ret;
777767

778-
if (!pin)
768+
if (selector >= pi->nr_pins)
779769
return -EINVAL;
780770

771+
pin = &pi->pins[selector];
772+
if (pin->present)
773+
return 0;
774+
781775
ret = scmi_pinctrl_attributes(ph, PIN_TYPE, selector, pin->name, NULL);
782776
if (ret)
783777
return ret;
@@ -790,20 +784,14 @@ static int scmi_pinctrl_get_pin_name(const struct scmi_protocol_handle *ph,
790784
u32 selector, const char **name)
791785
{
792786
struct scmi_pinctrl_info *pi = ph->get_priv(ph);
787+
int ret;
793788

794789
if (!name)
795790
return -EINVAL;
796791

797-
if (selector >= pi->nr_pins)
798-
return -EINVAL;
799-
800-
if (!pi->pins[selector].present) {
801-
int ret;
802-
803-
ret = scmi_pinctrl_get_pin_info(ph, selector, &pi->pins[selector]);
804-
if (ret)
805-
return ret;
806-
}
792+
ret = scmi_pinctrl_get_pin_info(ph, selector);
793+
if (ret)
794+
return ret;
807795

808796
*name = pi->pins[selector].name;
809797

0 commit comments

Comments
 (0)