1
0
Fork 0

hwmon: (core) Add comment describing how hwdev is freed in error path

The hwmon core registers the hwmon device before adding sensors to the
thermal core. If that fails, the hwmon device is released and an error
is returned to the caller. From the code flow, it appears to be necessary
to free struct hwmon_device *, allocated with kzalloc(), in that
situation. This is incorrect, since the data structure will be freed
automatically in hwmon_dev_release() when device_unregister() is called.
This used to result in a double free, which was found and fixed with
commit 74e3512731 ("hwmon: (core) Fix double-free in
__hwmon_device_register()"). This is, however, not obvious; any reader
may erroneously conclude that the data structure is not freed.

Add comment explaining why kfree() is not necessary in this situation.

Reported-by: Eduardo Valentin <eduval@amazon.com>
Cc: Eduardo Valentin <eduval@amazon.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
alistair/sunxi64-5.4-dsi
Guenter Roeck 2019-06-06 09:43:14 -07:00
parent 5fe625c136
commit 792eac1843
1 changed files with 6 additions and 0 deletions

View File

@ -651,6 +651,12 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
hwdev, j);
if (err) {
device_unregister(hdev);
/*
* Don't worry about hwdev;
* hwmon_dev_release(), called
* from device_unregister(),
* will free it.
*/
goto ida_remove;
}
}