mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-04 01:24:12 +08:00
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: c26c4bfc10
("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>
This commit is contained in:
parent
30cc538974
commit
25d2e41cf5
@ -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;
|
||||
for (i = 0; i < tpc->nfuncs; i++) {
|
||||
struct function_desc *func = &funcs[i];
|
||||
const char **group_names;
|
||||
unsigned int grp_idx = 0;
|
||||
int j;
|
||||
|
||||
while (pin_mux->name) {
|
||||
const char **grp;
|
||||
int j, grp_num, match = 0;
|
||||
size_t grp_size;
|
||||
struct function_desc *func;
|
||||
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->nfuncs; j++) {
|
||||
if (!strcmp(pin_mux->name, function[j].name)) {
|
||||
match = 1;
|
||||
break;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user