Message ID | 20250516191536.1353824-1-u.kleine-koenig@baylibre.com |
---|---|
State | Accepted |
Headers | show |
Series | [libpwm] sysfs: Complete cleanup in close callback | expand |
Hello, On Fri, May 16, 2025 at 09:15:36PM +0200, Uwe Kleine-König wrote: > Unexport used PWMs and close all open file descriptors. > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> I don't expect review feedback, so I went ahead and pushed it out to https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/libpwm.git main . Best regards Uwe
diff --git a/sysfs.c b/sysfs.c index 3188c1bd2ecf..fe4edea1e102 100644 --- a/sysfs.c +++ b/sysfs.c @@ -41,10 +41,18 @@ static void pwm_chip_sysfs_close(struct pwm_chip *chip) for (i = 0; i < chip->npwm; ++i) { if (chip_sysfs->pwms[i]) { + int fd = openat(chip_sysfs->dirfd, "unexport", O_WRONLY | O_CLOEXEC); + + if (fd >= 0) { + dprintf(fd, "%u\n", i); + close(fd); + } + close(chip_sysfs->pwms[i]->dirfd); free(chip_sysfs->pwms[i]); } } + close(chip_sysfs->dirfd); free(chip_sysfs); }
Unexport used PWMs and close all open file descriptors. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> --- sysfs.c | 8 ++++++++ 1 file changed, 8 insertions(+) base-commit: 00aff52a76199f13ea9e0ad628ffcac93fdce538