cxl/pmu: Ensure put_device on pmu devices
PATCH 1/1 cxl/pmu: Ensure put_device on pmu devices
The following kmemleaks were detected when removing the cxl module stack:
unreferenced object 0xffff88822616b800 (size 1024):
...
backtrace:
[<00000000bedc6f83>] kmalloc_trace+0x26/0x90
[<00000000448d1afc>] devm_cxl_pmu_add+0x3a/0x110 [cxl_core]
[<00000000ca3bfe16>] 0xffffffffa105213b
[<00000000ba7f78dc>] local_pci_probe+0x41/0x90
[<000000005bb027ac>] pci_device_probe+0xb0/0x1c0...
unreferenced object 0xffff8882260abcc0 (size 16):
...
hex dump (first 16 bytes):
70 6d 75 5f 6d 65 6d 30 2e 30 00 26 82 88 ff ff pmu_mem0.0.&....
backtrace:
...
[<00000000152b5e98>] dev_set_name+0x43/0x50
[<00000000c228798b>] devm_cxl_pmu_add+0x102/0x110 [cxl_core]
[<00000000ca3bfe16>] 0xffffffffa105213b
[<00000000ba7f78dc>] local_pci_probe+0x41/0x90
[<000000005bb027ac>] pci_device_probe+0xb0/0x1c0...
unreferenced object 0xffff8882272af200 (size 256):
...
backtrace:
[<00000000bedc6f83>] kmalloc_trace+0x26/0x90
[<00000000a14d1813>] device_add+0x4ea/0x890
[<00000000a3f07b47>] devm_cxl_pmu_add+0xbe/0x110 [cxl_core]
[<00000000ca3bfe16>] 0xffffffffa105213b
[<00000000ba7f78dc>] local_pci_probe+0x41/0x90
[<000000005bb027ac>] pci_device_probe+0xb0/0x1c0...
devm_cxl_pmu_add() correctly registers a device remove function but it only calls device_del() which is only part of device unregistration.
Properly call device_unregister() to free up the memory associated with the device.
--- drivers/cxl/core/pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/pmu.c +1 -1
@@ -23,7 +23,7 @@ const struct device_type cxl_pmu_type = {static void remove_dev (void *dev) { -device_del (dev); +device_unregister (dev); } int devm_cxl_pmu_add(struct device *parent, struct cxl_pmu_regs *regs,
---
base-commit: 58720809f52779dc0f08e53e54b014209d13eebb
change-id: 20231016-pmu-unregister-fix-345480926a58
Best regards,
Signature · 1 line
Ira Weiny <[email protected]>
Quoted 38 lines · Ira Weiny
The following kmemleaks were detected when removing the cxl module stack:
unreferenced object
0xffff88822616b800(size 1024):
...
backtrace:[<00000000bedc6f83>] kmalloc_trace+0x26/0x90 [<00000000448d1afc>] devm_cxl_pmu_add+0x3a/0x110 [cxl_core] [<00000000ca3bfe16>] 0xffffffffa105213b [<00000000ba7f78dc>] local_pci_probe+0x41/0x90 [<000000005bb027ac>] pci_device_probe+0xb0/0x1c0...
unreferenced object0xffff8882260abcc0(size 16):
...
hex dump (first 16 bytes):70 6d 75 5f 6d 65 6d 30 2e 30 00 26 82 88 ff ff pmu_mem0.0.&.... backtrace: ... [<00000000152b5e98>] dev_set_name+0x43/0x50 [<00000000c228798b>] devm_cxl_pmu_add+0x102/0x110 [cxl_core] [<00000000ca3bfe16>] 0xffffffffa105213b [<00000000ba7f78dc>] local_pci_probe+0x41/0x90 [<000000005bb027ac>] pci_device_probe+0xb0/0x1c0...
unreferenced object0xffff8882272af200(size 256):
...
backtrace:[<00000000bedc6f83>] kmalloc_trace+0x26/0x90 [<00000000a14d1813>] device_add+0x4ea/0x890 [<00000000a3f07b47>] devm_cxl_pmu_add+0xbe/0x110 [cxl_core] [<00000000ca3bfe16>] 0xffffffffa105213b [<00000000ba7f78dc>] local_pci_probe+0x41/0x90 [<000000005bb027ac>] pci_device_probe+0xb0/0x1c0...
devm_cxl_pmu_add()correctly registers a device remove function but it only callsdevice_del()which is only part of device unregistration.
Quoted 6 lines
Properly call
device_unregister()to free up the memory associated with the device.Fixes 1ad3f701c399 ("cxl/pci: Find and register CXL PMU devices")Cc Jonathan Cameron <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Although I wonder if we can just give device_unregister() to devm_add_action_or_reset() directly.
Quoted 23 lines
--- drivers/cxl/core/pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cxl/core/pmu.c +1
-2@@ -23,7 +23,7 @@ const struct device_type cxl_pmu_type = {static void remove_dev (void *dev) { -device_del (dev); +device_unregister (dev); } int devm_cxl_pmu_add(struct device *parent, struct cxl_pmu_regs *regs, ---base-commit:
58720809f52779dc0f08e53e54b014209d13eebb
change-id: 20231016-pmu-unregister-fix-345480926a58Best regards,
Quoted 2 lines · Dave Jiang
[snip]
Quoted 4 lines
Quoted 4 lines
Properly call
device_unregister()to free up the memory associated with the device.
Quoted 8 lines
Quoted 3 lines
Fixes 1ad3f701c399 ("cxl/pci: Find and register CXL PMU devices")Cc Jonathan Cameron <[email protected]>Signed-off-by Ira Weiny <[email protected]>Reviewed-by Dave Jiang <[email protected]>Although I wonder if we can just give
device_unregister()todevm_add_action_or_reset()directly.
No because the action callback takes void * and device_unregister() takes a struct device *.
Ira
[snip]
Dave Jiang
maintainerQuoted 14 lines · Ira Weiny
Quoted 2 lines · Dave Jiang
[snip]
Quoted 8 lines
Quoted 7 lines
Properly call
device_unregister()to free up the memory associated with the device.Fixes 1ad3f701c399 ("cxl/pci: Find and register CXL PMU devices")Cc Jonathan Cameron <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Quoted 7 lines
Quoted 4 lines
Reviewed-by Dave Jiang <[email protected]>Although I wonder if we can just give
device_unregister()todevm_add_action_or_reset()directly.No because the action callback takes void * and
device_unregister()takes a struct device *.
Ah right! I knew there was a reason for the wrapper....
Quoted 4 lines
Ira
[snip]
Quoted 38 lines · On Mon, 16 Oct 2023 16:25:05 -0700 Ira Weiny <[email protected]> wrote:
The following kmemleaks were detected when removing the cxl module stack:
unreferenced object
0xffff88822616b800(size 1024):
...
backtrace:[<00000000bedc6f83>] kmalloc_trace+0x26/0x90 [<00000000448d1afc>] devm_cxl_pmu_add+0x3a/0x110 [cxl_core] [<00000000ca3bfe16>] 0xffffffffa105213b [<00000000ba7f78dc>] local_pci_probe+0x41/0x90 [<000000005bb027ac>] pci_device_probe+0xb0/0x1c0...
unreferenced object0xffff8882260abcc0(size 16):
...
hex dump (first 16 bytes):70 6d 75 5f 6d 65 6d 30 2e 30 00 26 82 88 ff ff pmu_mem0.0.&.... backtrace: ... [<00000000152b5e98>] dev_set_name+0x43/0x50 [<00000000c228798b>] devm_cxl_pmu_add+0x102/0x110 [cxl_core] [<00000000ca3bfe16>] 0xffffffffa105213b [<00000000ba7f78dc>] local_pci_probe+0x41/0x90 [<000000005bb027ac>] pci_device_probe+0xb0/0x1c0...
unreferenced object0xffff8882272af200(size 256):
...
backtrace:[<00000000bedc6f83>] kmalloc_trace+0x26/0x90 [<00000000a14d1813>] device_add+0x4ea/0x890 [<00000000a3f07b47>] devm_cxl_pmu_add+0xbe/0x110 [cxl_core] [<00000000ca3bfe16>] 0xffffffffa105213b [<00000000ba7f78dc>] local_pci_probe+0x41/0x90 [<000000005bb027ac>] pci_device_probe+0xb0/0x1c0...
devm_cxl_pmu_add()correctly registers a device remove function but it only callsdevice_del()which is only part of device unregistration.
Quoted 6 lines
Properly call
device_unregister()to free up the memory associated with the device.Fixes 1ad3f701c399 ("cxl/pci: Find and register CXL PMU devices")Cc Jonathan Cameron <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Oops.
Quoted 23 lines
--- drivers/cxl/core/pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cxl/core/pmu.c +1
-2@@ -23,7 +23,7 @@ const struct device_type cxl_pmu_type = {static void remove_dev (void *dev) { -device_del (dev); +device_unregister (dev); } int devm_cxl_pmu_add(struct device *parent, struct cxl_pmu_regs *regs, ---base-commit:
58720809f52779dc0f08e53e54b014209d13eebb
change-id: 20231016-pmu-unregister-fix-345480926a58Best regards,