Skip to contentSkip to conversation

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

PATCH Applied Andy Shevchenko 2 participants 2 messages Oct 25, 2024 PWM

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 pwm: core: use device_match_name() instead of strcmp(dev_name(...

Use the dedicated helper for comparing device names against strings.

Note, the current code has a check for the dev_name() against NULL. With the current implementations of the device_add() and dev_set_name() it most likely a theoretical assumption that that might happen, while I don't see how. Hence, that check has simply been removed.

---
v2: elaborated a dead code elimination in the commit message (Uwe)

 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,

Quoted 8 lines · Andy Shevchenko

Use the dedicated helper for comparing device names against strings.

Note, the current code has a check for the dev_name() against NULL. With the current implementations of the device_add() and dev_set_name() it most likely a theoretical assumption that that might happen, while I don't see how. Hence, that check has simply been removed.

thanks, applied to

https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next

Best regards
Uwe