Skip to content

Commit 25d2e41

Browse files
Rafał MiłeckiLinus Walleij
authored andcommitted
pinctrl: thunderbay: rework loops looking for groups names
Make the outer loop iterate over functions as that's the real subject. This simplifies code (and reduces amount of lines of code) as allocating memory for names doesn't require extra checks anymore. While at it use local "group_names" variable. It fixes: drivers/pinctrl/pinctrl-thunderbay.c: In function 'thunderbay_add_functions': drivers/pinctrl/pinctrl-thunderbay.c:815:8: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 815 | grp = func->group_names; | ^ Ref: c26c4bf ("pinctrl: keembay: rework loops looking for groups names") Reported-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Link: https://lore.kernel.org/r/20220111172919.6567-2-zajec5@gmail.com Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 30cc538 commit 25d2e41

1 file changed

Lines changed: 25 additions & 46 deletions

File tree

drivers/pinctrl/pinctrl-thunderbay.c

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -773,63 +773,42 @@ static int thunderbay_build_groups(struct thunderbay_pinctrl *tpc)
773773

774774
static int thunderbay_add_functions(struct thunderbay_pinctrl *tpc, struct function_desc *funcs)
775775
{
776-
struct function_desc *function = funcs;
777776
int i;
778777

779778
/* Assign the groups for each function */
780-
for (i = 0; i < tpc->soc->npins; i++) {
781-
const struct pinctrl_pin_desc *pin_info = thunderbay_pins + i;
782-
struct thunderbay_mux_desc *pin_mux = pin_info->drv_data;
783-
784-
while (pin_mux->name) {
785-
const char **grp;
786-
int j, grp_num, match = 0;
787-
size_t grp_size;
788-
struct function_desc *func;
789-
790-
for (j = 0; j < tpc->nfuncs; j++) {
791-
if (!strcmp(pin_mux->name, function[j].name)) {
792-
match = 1;
793-
break;
794-
}
795-
}
796-
797-
if (!match)
798-
return -EINVAL;
799-
800-
func = function + j;
801-
grp_num = func->num_group_names;
802-
grp_size = sizeof(*func->group_names);
803-
804-
if (!func->group_names) {
805-
func->group_names = devm_kcalloc(tpc->dev,
806-
grp_num,
807-
grp_size,
808-
GFP_KERNEL);
809-
if (!func->group_names) {
810-
kfree(func);
811-
return -ENOMEM;
812-
}
779+
for (i = 0; i < tpc->nfuncs; i++) {
780+
struct function_desc *func = &funcs[i];
781+
const char **group_names;
782+
unsigned int grp_idx = 0;
783+
int j;
784+
785+
group_names = devm_kcalloc(tpc->dev, func->num_group_names,
786+
sizeof(*group_names), GFP_KERNEL);
787+
if (!group_names)
788+
return -ENOMEM;
789+
790+
for (j = 0; j < tpc->soc->npins; j++) {
791+
const struct pinctrl_pin_desc *pin_info = &thunderbay_pins[j];
792+
struct thunderbay_mux_desc *pin_mux;
793+
794+
for (pin_mux = pin_info->drv_data; pin_mux->name; pin_mux++) {
795+
if (!strcmp(pin_mux->name, func->name))
796+
group_names[grp_idx++] = pin_info->name;
813797
}
814-
815-
grp = func->group_names;
816-
while (*grp)
817-
grp++;
818-
819-
*grp = pin_info->name;
820-
pin_mux++;
821798
}
799+
800+
func->group_names = group_names;
822801
}
823802

824803
/* Add all functions */
825804
for (i = 0; i < tpc->nfuncs; i++) {
826805
pinmux_generic_add_function(tpc->pctrl,
827-
function[i].name,
828-
function[i].group_names,
829-
function[i].num_group_names,
830-
function[i].data);
806+
funcs[i].name,
807+
funcs[i].group_names,
808+
funcs[i].num_group_names,
809+
funcs[i].data);
831810
}
832-
kfree(function);
811+
kfree(funcs);
833812
return 0;
834813
}
835814

0 commit comments

Comments
 (0)