Skip to content

Commit 0733424

Browse files
David Hsuthierryreding
David Hsu
authored andcommitted
pwm: Unexport children before chip removal
Exported pwm channels aren't removed before the pwmchip and are leaked. This results in invalid sysfs files. This fix removes all exported pwm channels before chip removal. Signed-off-by: David Hsu <davidhsu@google.com> Fixes: 76abbdd ("pwm: Add sysfs interface") Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
1 parent 29b4817 commit 0733424

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

drivers/pwm/core.c

+2
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ int pwmchip_remove(struct pwm_chip *chip)
339339
unsigned int i;
340340
int ret = 0;
341341

342+
pwmchip_sysfs_unexport_children(chip);
343+
342344
mutex_lock(&pwm_lock);
343345

344346
for (i = 0; i < chip->npwm; i++) {

drivers/pwm/sysfs.c

+18
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,24 @@ void pwmchip_sysfs_unexport(struct pwm_chip *chip)
409409
}
410410
}
411411

412+
void pwmchip_sysfs_unexport_children(struct pwm_chip *chip)
413+
{
414+
struct device *parent;
415+
unsigned int i;
416+
417+
parent = class_find_device(&pwm_class, NULL, chip,
418+
pwmchip_sysfs_match);
419+
if (!parent)
420+
return;
421+
422+
for (i = 0; i < chip->npwm; i++) {
423+
struct pwm_device *pwm = &chip->pwms[i];
424+
425+
if (test_bit(PWMF_EXPORTED, &pwm->flags))
426+
pwm_unexport_child(parent, pwm);
427+
}
428+
}
429+
412430
static int __init pwm_sysfs_init(void)
413431
{
414432
return class_register(&pwm_class);

include/linux/pwm.h

+5
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ static inline void pwm_remove_table(struct pwm_lookup *table, size_t num)
641641
#ifdef CONFIG_PWM_SYSFS
642642
void pwmchip_sysfs_export(struct pwm_chip *chip);
643643
void pwmchip_sysfs_unexport(struct pwm_chip *chip);
644+
void pwmchip_sysfs_unexport_children(struct pwm_chip *chip);
644645
#else
645646
static inline void pwmchip_sysfs_export(struct pwm_chip *chip)
646647
{
@@ -649,6 +650,10 @@ static inline void pwmchip_sysfs_export(struct pwm_chip *chip)
649650
static inline void pwmchip_sysfs_unexport(struct pwm_chip *chip)
650651
{
651652
}
653+
654+
static inline void pwmchip_sysfs_unexport_children(struct pwm_chip *chip)
655+
{
656+
}
652657
#endif /* CONFIG_PWM_SYSFS */
653658

654659
#endif /* __LINUX_PWM_H */

0 commit comments

Comments
 (0)