pwm: core: use device_match_name() instead of strcmp(dev_name(...
PATCH 1/1 pwm: core: use device_match_name() instead of strcmp(dev_name(...
Use the dedicated helper for comparing device names against strings.
--- drivers/pwm/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/pwm/core.c +1 -3
@@ -852,9 +852,7 @@ static struct pwm_chip *pwmchip_find_by_name(const char *name)guard (mutex)(&pwm_lock);idr_for_each_entry_ul (&pwm_chips, chip, tmp, id) { -const char *chip_name =dev_name (pwmchip_parent (chip)); - -if (chip_name &&strcmp (chip_name, name) ==0 ) +if (device_match_name (pwmchip_parent (chip), name))return chip; }
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Hello Andy,
drivers/pwm/core.c static struct pwm_chip *pwmchip_find_by_name(const char *name) · line 855
Quoted 12 lines · Andy Shevchenko
drivers/pwm/core.c +1
-3@@ -852,9 +852,7 @@ static struct pwm_chip *pwmchip_find_by_name(const char *name)guard (mutex)(&pwm_lock);idr_for_each_entry_ul (&pwm_chips, chip, tmp, id) { -const char *chip_name =dev_name (pwmchip_parent (chip)); - -if (chip_name &&strcmp (chip_name, name) ==0 ) +if (device_match_name (pwmchip_parent (chip), name))
This theoretically changes behaviour in a few cases. For example if dev_name(pwmchip_parent(chip)) is NULL the new code would crash. Can this happen?
Best regards
Uwe
Quoted 2 lines
drivers/pwm/core.c +0
-0return chip; }
Quoted 1 line · Uwe Kleine-König
On Thu, Oct 24, 2024 at 06:19:05PM +0300, Andy Shevchenko wrote:
...
Quoted 9 lines
drivers/pwm/core.c static struct pwm_chip *pwmchip_find_by_name(const char *name) · line 855
Quoted 5 lines
drivers/pwm/core.c +1
-3idr_for_each_entry_ul (&pwm_chips, chip, tmp, id) { -const char *chip_name =dev_name (pwmchip_parent (chip)); - -if (chip_name &&strcmp (chip_name, name) ==0 ) +if (device_match_name (pwmchip_parent (chip), name))This theoretically changes behaviour in a few cases. For example if dev_name(pwmchip_parent(chip)) is NULL the new code would crash. Can this happen?
Please, tell me how
(looking at the of device_add() and kobject_set_name_vargs() implementations)?
Btw, have you ever seen this check somewhere else? (I don't, but I haven't covered full kernel sources, of course.)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hello Andy,
Quoted 15 lines · Andy Shevchenko
Quoted 1 line · Uwe Kleine-König
On Thu, Oct 24, 2024 at 06:19:05PM +0300, Andy Shevchenko wrote:
...
Quoted 9 lines
drivers/pwm/core.c static struct pwm_chip *pwmchip_find_by_name(const char *name) · line 855
Quoted 5 lines
drivers/pwm/core.c +1
-3idr_for_each_entry_ul (&pwm_chips, chip, tmp, id) { -const char *chip_name =dev_name (pwmchip_parent (chip)); - -if (chip_name &&strcmp (chip_name, name) ==0 ) +if (device_match_name (pwmchip_parent (chip), name))This theoretically changes behaviour in a few cases. For example if dev_name(pwmchip_parent(chip)) is NULL the new code would crash. Can this happen?
Quoted 2 lines
Please, tell me how
(looking at the ofdevice_add()andkobject_set_name_vargs()implementations)?
This is unfair, I intended to let you do the work and you just give it back to me :-)
... a bit later ...
ok, willing to merge if you update the commit log to mention that the theoretical changes (no check for NULL, more lax check (trailing \n)) don't matter.
Best regards
Uwe
Quoted 3 lines · Uwe Kleine-König
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Uwe Kleine-König
On Thu, Oct 24, 2024 at 06:19:05PM +0300, Andy Shevchenko wrote:
...
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
drivers/pwm/core.c static struct pwm_chip *pwmchip_find_by_name(const char *name) · line 855
Quoted 5 lines
drivers/pwm/core.c +1
-3idr_for_each_entry_ul (&pwm_chips, chip, tmp, id) { -const char *chip_name =dev_name (pwmchip_parent (chip)); - -if (chip_name &&strcmp (chip_name, name) ==0 ) +if (device_match_name (pwmchip_parent (chip), name))This theoretically changes behaviour in a few cases. For example if dev_name(pwmchip_parent(chip)) is NULL the new code would crash. Can this happen?
Quoted 5 lines
Quoted 2 lines
Please, tell me how
(looking at the ofdevice_add()andkobject_set_name_vargs()implementations)?This is unfair, I intended to let you do the work and you just give it back to me :-)
Unfair to ask me about this code as you should know better as the maintainer than me why this code is there, no? :-)
Quoted 5 lines
... a bit later ...
ok, willing to merge if you update the commit log to mention that the theoretical changes (no check for NULL, more lax check (trailing \n)) don't matter.
Okay.
Signature · 2 lines
With Best Regards, Andy Shevchenko