Skip to contentSkip to conversation

pwm: core: use device_match_name() instead of strcmp(dev_name(...

PATCH Superseded Andy Shevchenko 2 participants 5 messages Oct 24, 2024 – Oct 25, 2024 PWM

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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
index 634be56e204b..4399e793efaf 100644
@@ -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
#1 lore raw

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
index 634be56e204b..4399e793efaf 100644
@@ -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 -0
 			return chip;
 	}
#2 lore raw
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 -3
 	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?

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
#3 lore raw

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 -3
 	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?

Quoted 2 lines

Please, tell me how
(looking at the of device_add() and kobject_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

#4 lore raw
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 -3
 	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?

Quoted 5 lines
Quoted 2 lines

Please, tell me how
(looking at the of device_add() and kobject_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