Skip to content

Commit 30cc538

Browse files
Rafał MiłeckiLinus Walleij
authored andcommitted
pinctrl: thunderbay: comment process of building functions a bit
This should make code a bit easier to follow. While at it use some "for" loops to simplify array iteration loops. Ref: 5d06749 ("pinctrl: keembay: comment process of building functions a bit") Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Link: https://lore.kernel.org/r/20220111172919.6567-1-zajec5@gmail.com Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent e783362 commit 30cc538

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

drivers/pinctrl/pinctrl-thunderbay.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -839,27 +839,30 @@ static int thunderbay_build_functions(struct thunderbay_pinctrl *tpc)
839839
void *ptr;
840840
int pin;
841841

842-
/* Total number of functions is unknown at this point. Allocate first. */
842+
/*
843+
* Allocate maximum possible number of functions. Assume every pin
844+
* being part of 8 (hw maximum) globally unique muxes.
845+
*/
843846
tpc->nfuncs = 0;
844847
thunderbay_funcs = kcalloc(tpc->soc->npins * 8,
845848
sizeof(*thunderbay_funcs), GFP_KERNEL);
846849
if (!thunderbay_funcs)
847850
return -ENOMEM;
848851

849-
/* Find total number of functions and each's properties */
852+
/* Setup 1 function for each unique mux */
850853
for (pin = 0; pin < tpc->soc->npins; pin++) {
851854
const struct pinctrl_pin_desc *pin_info = thunderbay_pins + pin;
852-
struct thunderbay_mux_desc *pin_mux = pin_info->drv_data;
855+
struct thunderbay_mux_desc *pin_mux;
853856

854-
while (pin_mux->name) {
855-
struct function_desc *func = thunderbay_funcs;
857+
for (pin_mux = pin_info->drv_data; pin_mux->name; pin_mux++) {
858+
struct function_desc *func;
856859

857-
while (func->name) {
860+
/* Check if we already have function for this mux */
861+
for (func = thunderbay_funcs; func->name; func++) {
858862
if (!strcmp(pin_mux->name, func->name)) {
859863
func->num_group_names++;
860864
break;
861865
}
862-
func++;
863866
}
864867

865868
if (!func->name) {
@@ -868,8 +871,6 @@ static int thunderbay_build_functions(struct thunderbay_pinctrl *tpc)
868871
func->data = (int *)&pin_mux->mode;
869872
tpc->nfuncs++;
870873
}
871-
872-
pin_mux++;
873874
}
874875
}
875876

0 commit comments

Comments
 (0)