Message ID | 20241006-th1520-pinctrl-fixes-v2-3-b1822ae3a6d7@tenstorrent.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | pinctrl: th1520: Improve code quality | expand |
Context | Check | Description |
---|---|---|
conchuod/vmtest-fixes-PR | fail | merge-conflict |
Hi Drew,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 2694868880705e8f6bb61b24b1b25adc42a4a217]
url: https://github.com/intel-lab-lkp/linux/commits/Drew-Fustini/pinctrl-th1520-Fix-return-value-for-unknown-pin-error/20241007-014953
base: 2694868880705e8f6bb61b24b1b25adc42a4a217
patch link: https://lore.kernel.org/r/20241006-th1520-pinctrl-fixes-v2-3-b1822ae3a6d7%40tenstorrent.com
patch subject: [PATCH v2 3/3] pinctrl: th1520: Convert dt child node loop to scoped iterator
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20241007/202410072033.XpRqZ8nz-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241007/202410072033.XpRqZ8nz-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410072033.XpRqZ8nz-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/pinctrl/pinctrl-th1520.c: In function 'th1520_pinctrl_dt_node_to_map':
>> drivers/pinctrl/pinctrl-th1520.c:420:29: warning: unused variable 'child' [-Wunused-variable]
420 | struct device_node *child;
| ^~~~~
vim +/child +420 drivers/pinctrl/pinctrl-th1520.c
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 413
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 414 static int th1520_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 415 struct device_node *np,
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 416 struct pinctrl_map **maps,
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 417 unsigned int *num_maps)
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 418 {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 419 struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev);
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 @420 struct device_node *child;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 421 struct pinctrl_map *map;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 422 unsigned long *configs;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 423 unsigned int nconfigs;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 424 unsigned int nmaps;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 425 int ret;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 426
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 427 nmaps = 0;
1a1dcc4caac257 Drew Fustini 2024-10-06 428 for_each_available_child_of_node_scoped(np, child) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 429 int npins = of_property_count_strings(child, "pins");
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 430
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 431 if (npins <= 0) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 432 dev_err(thp->pctl->dev, "no pins selected for %pOFn.%pOFn\n",
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 433 np, child);
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 434 return -EINVAL;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 435 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 436 nmaps += npins;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 437 if (of_property_present(child, "function"))
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 438 nmaps += npins;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 439 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 440
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 441 map = kcalloc(nmaps, sizeof(*map), GFP_KERNEL);
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 442 if (!map)
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 443 return -ENOMEM;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 444
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 445 nmaps = 0;
9aae170bf6c30e Drew Fustini 2024-10-06 446 guard(mutex)(&thp->mutex);
1a1dcc4caac257 Drew Fustini 2024-10-06 447 for_each_available_child_of_node_scoped(np, child) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 448 unsigned int rollback = nmaps;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 449 enum th1520_muxtype muxtype;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 450 struct property *prop;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 451 const char *funcname;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 452 const char **pgnames;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 453 const char *pinname;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 454 int npins;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 455
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 456 ret = pinconf_generic_parse_dt_config(child, pctldev, &configs, &nconfigs);
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 457 if (ret) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 458 dev_err(thp->pctl->dev, "%pOFn.%pOFn: error parsing pin config\n",
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 459 np, child);
1a1dcc4caac257 Drew Fustini 2024-10-06 460 goto free_map;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 461 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 462
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 463 if (!of_property_read_string(child, "function", &funcname)) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 464 muxtype = th1520_muxtype_get(funcname);
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 465 if (!muxtype) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 466 dev_err(thp->pctl->dev, "%pOFn.%pOFn: unknown function '%s'\n",
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 467 np, child, funcname);
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 468 ret = -EINVAL;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 469 goto free_configs;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 470 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 471
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 472 funcname = devm_kasprintf(thp->pctl->dev, GFP_KERNEL, "%pOFn.%pOFn",
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 473 np, child);
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 474 if (!funcname) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 475 ret = -ENOMEM;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 476 goto free_configs;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 477 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 478
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 479 npins = of_property_count_strings(child, "pins");
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 480 pgnames = devm_kcalloc(thp->pctl->dev, npins, sizeof(*pgnames), GFP_KERNEL);
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 481 if (!pgnames) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 482 ret = -ENOMEM;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 483 goto free_configs;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 484 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 485 } else {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 486 funcname = NULL;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 487 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 488
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 489 npins = 0;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 490 of_property_for_each_string(child, "pins", prop, pinname) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 491 unsigned int i;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 492
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 493 for (i = 0; i < thp->desc.npins; i++) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 494 if (!strcmp(pinname, thp->desc.pins[i].name))
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 495 break;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 496 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 497 if (i == thp->desc.npins) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 498 nmaps = rollback;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 499 dev_err(thp->pctl->dev, "%pOFn.%pOFn: unknown pin '%s'\n",
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 500 np, child, pinname);
08f5dfea548d37 Drew Fustini 2024-10-06 501 ret = -EINVAL;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 502 goto free_configs;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 503 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 504
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 505 if (nconfigs) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 506 map[nmaps].type = PIN_MAP_TYPE_CONFIGS_PIN;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 507 map[nmaps].data.configs.group_or_pin = thp->desc.pins[i].name;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 508 map[nmaps].data.configs.configs = configs;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 509 map[nmaps].data.configs.num_configs = nconfigs;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 510 nmaps += 1;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 511 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 512 if (funcname) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 513 pgnames[npins++] = thp->desc.pins[i].name;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 514 map[nmaps].type = PIN_MAP_TYPE_MUX_GROUP;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 515 map[nmaps].data.mux.function = funcname;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 516 map[nmaps].data.mux.group = thp->desc.pins[i].name;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 517 nmaps += 1;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 518 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 519 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 520
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 521 if (funcname) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 522 ret = pinmux_generic_add_function(pctldev, funcname, pgnames,
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 523 npins, (void *)muxtype);
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 524 if (ret < 0) {
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 525 dev_err(thp->pctl->dev, "error adding function %s\n", funcname);
1a1dcc4caac257 Drew Fustini 2024-10-06 526 goto free_map;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 527 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 528 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 529 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 530
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 531 *maps = map;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 532 *num_maps = nmaps;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 533 return 0;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 534
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 535 free_configs:
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 536 kfree(configs);
1a1dcc4caac257 Drew Fustini 2024-10-06 537 free_map:
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 538 th1520_pinctrl_dt_free_map(pctldev, map, nmaps);
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 539 return ret;
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 540 }
bed5cd6f8a9883 Emil Renner Berthing 2024-09-30 541
On Mon, Oct 07, 2024 at 08:26:28PM +0800, kernel test robot wrote: > Hi Drew, > > kernel test robot noticed the following build warnings: > > [auto build test WARNING on 2694868880705e8f6bb61b24b1b25adc42a4a217] > > url: https://github.com/intel-lab-lkp/linux/commits/Drew-Fustini/pinctrl-th1520-Fix-return-value-for-unknown-pin-error/20241007-014953 > base: 2694868880705e8f6bb61b24b1b25adc42a4a217 > patch link: https://lore.kernel.org/r/20241006-th1520-pinctrl-fixes-v2-3-b1822ae3a6d7%40tenstorrent.com > patch subject: [PATCH v2 3/3] pinctrl: th1520: Convert dt child node loop to scoped iterator > config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20241007/202410072033.XpRqZ8nz-lkp@intel.com/config) > compiler: alpha-linux-gcc (GCC) 13.3.0 > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241007/202410072033.XpRqZ8nz-lkp@intel.com/reproduce) > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > the same patch/commit), kindly add following tags > | Reported-by: kernel test robot <lkp@intel.com> > | Closes: https://lore.kernel.org/oe-kbuild-all/202410072033.XpRqZ8nz-lkp@intel.com/ > > All warnings (new ones prefixed by >>): > > drivers/pinctrl/pinctrl-th1520.c: In function 'th1520_pinctrl_dt_node_to_map': > >> drivers/pinctrl/pinctrl-th1520.c:420:29: warning: unused variable 'child' [-Wunused-variable] > 420 | struct device_node *child; > | ^~~~~ It seems this is because the scoped iterator declares *child in the macro and thus no separate declaration is needed: #define for_each_available_child_of_node_scoped(parent, child) \ for (struct device_node *child __free(device_node) = \ of_get_next_available_child(parent, NULL); \ child != NULL; \ child = of_get_next_available_child(parent, child)) I'll fix in next revision. Thanks, Drew
diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c index 7ed3f82b9339..286c6b2b0b13 100644 --- a/drivers/pinctrl/pinctrl-th1520.c +++ b/drivers/pinctrl/pinctrl-th1520.c @@ -425,11 +425,10 @@ static int th1520_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev, int ret; nmaps = 0; - for_each_available_child_of_node(np, child) { + for_each_available_child_of_node_scoped(np, child) { int npins = of_property_count_strings(child, "pins"); if (npins <= 0) { - of_node_put(child); dev_err(thp->pctl->dev, "no pins selected for %pOFn.%pOFn\n", np, child); return -EINVAL; @@ -445,7 +444,7 @@ static int th1520_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev, nmaps = 0; guard(mutex)(&thp->mutex); - for_each_available_child_of_node(np, child) { + for_each_available_child_of_node_scoped(np, child) { unsigned int rollback = nmaps; enum th1520_muxtype muxtype; struct property *prop; @@ -458,7 +457,7 @@ static int th1520_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev, if (ret) { dev_err(thp->pctl->dev, "%pOFn.%pOFn: error parsing pin config\n", np, child); - goto put_child; + goto free_map; } if (!of_property_read_string(child, "function", &funcname)) { @@ -524,7 +523,7 @@ static int th1520_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev, npins, (void *)muxtype); if (ret < 0) { dev_err(thp->pctl->dev, "error adding function %s\n", funcname); - goto put_child; + goto free_map; } } } @@ -535,8 +534,7 @@ static int th1520_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev, free_configs: kfree(configs); -put_child: - of_node_put(child); +free_map: th1520_pinctrl_dt_free_map(pctldev, map, nmaps); return ret; }
Convert th1520_pinctrl_dt_node_to_map() to use a scoped iterator with for_each_available_child_of_node_scoped(). As a result, there is no need to call of_node_put() anymore. The put_child label has been renamed to free_map which is now a more accurate description. Suggested-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Drew Fustini <dfustini@tenstorrent.com> --- drivers/pinctrl/pinctrl-th1520.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)