]> git.baikalelectronics.ru Git - kernel.git/commit
hwmon: (sht15) Fix wrong assumptions in device remove callback
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Mon, 25 Jul 2022 19:43:44 +0000 (21:43 +0200)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 26 Jul 2022 14:00:27 +0000 (07:00 -0700)
commit141cc9316bee7155dc9a623fa63667b493506972
tree0f232ac09a94f76410b3f09b98c8cf5606f577c4
parent36951543b6d6fe3d5afa5d33853e5df3384d5d42
hwmon: (sht15) Fix wrong assumptions in device remove callback

Taking a lock at the beginning of .remove() doesn't prevent new readers.
With the existing approach it can happen, that a read occurs just when
the lock was taken blocking the reader until the lock is released at the
end of the remove callback which then accessed *data that is already
freed then.

To actually fix this problem the hwmon core needs some adaption. Until
this is implemented take the optimistic approach of assuming that all
readers are gone after hwmon_device_unregister() and
sysfs_remove_group() as most other drivers do. (And once the core
implements that, taking the lock would deadlock.)

So drop the lock, move the reset to after device unregistration to keep
the device in a workable state until it's deregistered. Also add a error
message in case the reset fails and return 0 anyhow. (Returning an error
code, doesn't stop the platform device unregistration and only results
in a little helpful error message before the devm cleanup handlers are
called.)

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20220725194344.150098-1-u.kleine-koenig@pengutronix.de
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/sht15.c