Commit 25d2e41c authored by Rafał Miłecki's avatar Rafał Miłecki Committed by Linus Walleij

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: c26c4bfc ("pinctrl: keembay: rework loops looking for groups names")
Reported-by: default avatarNathan Chancellor <nathan@kernel.org>
Signed-off-by: default avatarRafał Miłecki <rafal@milecki.pl>
Link: https://lore.kernel.org/r/20220111172919.6567-2-zajec5@gmail.comSigned-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 30cc5389
......@@ -773,63 +773,42 @@ static int thunderbay_build_groups(struct thunderbay_pinctrl *tpc)
static int thunderbay_add_functions(struct thunderbay_pinctrl *tpc, struct function_desc *funcs)
{
struct function_desc *function = funcs;
int i;
/* Assign the groups for each function */
for (i = 0; i < tpc->soc->npins; i++) {
const struct pinctrl_pin_desc *pin_info = thunderbay_pins + i;
struct thunderbay_mux_desc *pin_mux = pin_info->drv_data;
while (pin_mux->name) {
const char **grp;
int j, grp_num, match = 0;
size_t grp_size;
struct function_desc *func;
for (j = 0; j < tpc->nfuncs; j++) {
if (!strcmp(pin_mux->name, function[j].name)) {
match = 1;
break;
}
}
if (!match)
return -EINVAL;
func = function + j;
grp_num = func->num_group_names;
grp_size = sizeof(*func->group_names);
if (!func->group_names) {
func->group_names = devm_kcalloc(tpc->dev,
grp_num,
grp_size,
GFP_KERNEL);
if (!func->group_names) {
kfree(func);
return -ENOMEM;
}
for (i = 0; i < tpc->nfuncs; i++) {
struct function_desc *func = &funcs[i];
const char **group_names;
unsigned int grp_idx = 0;
int j;
group_names = devm_kcalloc(tpc->dev, func->num_group_names,
sizeof(*group_names), GFP_KERNEL);
if (!group_names)
return -ENOMEM;
for (j = 0; j < tpc->soc->npins; j++) {
const struct pinctrl_pin_desc *pin_info = &thunderbay_pins[j];
struct thunderbay_mux_desc *pin_mux;
for (pin_mux = pin_info->drv_data; pin_mux->name; pin_mux++) {
if (!strcmp(pin_mux->name, func->name))
group_names[grp_idx++] = pin_info->name;
}
grp = func->group_names;
while (*grp)
grp++;
*grp = pin_info->name;
pin_mux++;
}
func->group_names = group_names;
}
/* Add all functions */
for (i = 0; i < tpc->nfuncs; i++) {
pinmux_generic_add_function(tpc->pctrl,
function[i].name,
function[i].group_names,
function[i].num_group_names,
function[i].data);
funcs[i].name,
funcs[i].group_names,
funcs[i].num_group_names,
funcs[i].data);
}
kfree(function);
kfree(funcs);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment