nvmem: core: Prevent memory leak when device is unregistered
PATCH 1/1 nvmem: core: Prevent memory leak when device is unregistered
The nvmem_unregister() calls device_del() for the device but forgets to call put_device() to actually release the device object which causes that memory to be leaked.
Fix this by calling device_unregister() for the device intead which also calls put_device() for the device releasing it eventually.
--- drivers/nvmem/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvmem/core.c +1 -1
@@ -528,7 +528,7 @@ int nvmem_unregister(struct nvmem_device *nvmem)device_remove_bin_file (nvmem->base_dev, &nvmem->eeprom);nvmem_device_remove_all_cells (nvmem); -device_del (&nvmem->dev); +device_unregister (&nvmem->dev);return 0 ; }
Signature · 1 line
2.11.0
Quoted 5 lines · Mika Westerberg
The
nvmem_unregister()callsdevice_del()for the device but forgets to callput_device()to actually release the device object which causes that memory to be leaked.Fix this by calling
device_unregister()for the device intead which also
instead
Quoted 2 lines
calls
put_device()for the device releasing it eventually.
Other than that, FWIW:
Quoted 21 lines
Signed-off-by Mika Westerberg <[email protected]>--- drivers/nvmem/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/nvmem/core.c +1
-2@@ -528,7 +528,7 @@ int nvmem_unregister(struct nvmem_device *nvmem)device_remove_bin_file (nvmem->base_dev, &nvmem->eeprom);nvmem_device_remove_all_cells (nvmem); -device_del (&nvmem->dev); +device_unregister (&nvmem->dev);return 0 ; } --2.11.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 6 lines · Mika Westerberg
The
nvmem_unregister()callsdevice_del()for the device but forgets to callput_device()to actually release the device object which causes that memory to be leaked.Fix this by calling
device_unregister()for the device intead which also callsput_device()for the device releasing it eventually.
I was gonna suggest that you fix up the related leaks in the registration error paths as well, but since they are really distinct I just submitted a patch to fix those up separately instead (kfree was being just instead of put_device and the device was never deregistered on late probe errors).
Quoted 10 lines
Signed-off-by Mika Westerberg <[email protected]>--- drivers/nvmem/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/nvmem/core.c +0
-0
drivers/nvmem/core.c int nvmem_unregister(struct nvmem_device *nvmem) · line 531
Quoted 5 lines
drivers/nvmem/core.c +1
-1@@ -528,7 +528,7 @@ int nvmem_unregister(struct nvmem_device *nvmem)device_remove_bin_file (nvmem->base_dev, &nvmem->eeprom);nvmem_device_remove_all_cells (nvmem); -device_del (&nvmem->dev); +device_unregister (&nvmem->dev);
Might be cleaner to use an explicit call to put_device() here since the driver currently does not use device_register().
drivers/nvmem/core.c int nvmem_unregister(struct nvmem_device *nvmem) · line 534
Quoted 3 lines
drivers/nvmem/core.c +0
-0return 0 ; }
Thanks,
Johan
Quoted 9 lines · Mika Westerberg
The
nvmem_unregister()callsdevice_del()for the device but forgets to callput_device()to actually release the device object which causes that memory to be leaked.Fix this by calling
device_unregister()for the device intead which also callsput_device()for the device releasing it eventually.Signed-off-by Mika Westerberg <[email protected]>---
FWIW, I submitted similar fix for this here:
lkml.kernel.org/r/[email protected]
Quoted 19 lines
drivers/nvmem/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/nvmem/core.c +1
-2@@ -528,7 +528,7 @@ int nvmem_unregister(struct nvmem_device *nvmem)device_remove_bin_file (nvmem->base_dev, &nvmem->eeprom);nvmem_device_remove_all_cells (nvmem); -device_del (&nvmem->dev); +device_unregister (&nvmem->dev);return 0 ; } --2.11.0
Quoted 9 lines · Andrey Smirnov
Quoted 7 lines · Mika Westerberg
The
nvmem_unregister()callsdevice_del()for the device but forgets to callput_device()to actually release the device object which causes that memory to be leaked.Fix this by calling
device_unregister()for the device intead which also callsput_device()for the device releasing it eventually.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Mika Westerberg <[email protected]>---
FWIW, I submitted similar fix for this here:
lkml.kernel.org/r/[email protected]
Cool, let's go with that one instead then :)