From 5d9e2ab9fea4cdf0a2522f5cbed2e7fbb220d757 Mon Sep 17 00:00:00 2001 From: Johannes Thumshirn Date: Tue, 3 May 2016 12:42:03 +0200 Subject: [PATCH] mcb: Implement bus->dev.release callback The mcb_bus structure previously was released in mcb_release_bus. This lead to the following warning on module unload: ------------[ cut here ]------------ WARNING: CPU: 1 PID: 2032 at drivers/base/core.c:251 device_release+0x73/0x90 Device 'mcb:0' does not have a release() function, it is broken and must be fixed. Modules linked in: men_z135_uart mcb_pci(-) mcb CPU: 1 PID: 2032 Comm: rmmod Not tainted 4.6.0-rc4+ #3 Hardware name: N/A N/A/COMe-mBTi10, BIOS MVV1R921 X64 10/14/2015 00000286 00000286 c0117de4 c12d6f16 c0117e2c c18be0d3 c0117dfc c104f6e1 000000fb f5ccbe08 f5ccbe00 f5c64600 c0117e18 c104f728 00000009 00000000 c0117e10 c18db674 c0117e2c c0117e3c c13ce5c3 c18be0d3 000000fb c18db674 Call Trace: [] dump_stack+0x47/0x61 [] __warn+0xc1/0xe0 [] warn_slowpath_fmt+0x28/0x30 [] device_release+0x73/0x90 [] kobject_release+0x34/0x80 [] ? kobject_del+0x2d/0x40 [] kobject_put+0x25/0x50 [] put_device+0xf/0x20 [] klist_devices_put+0xb/0x10 [] klist_next+0x73/0xf0 [] ? unbind_store+0x100/0x100 [] ? mcb_bus_add_devices+0x30/0x30 [mcb] [] bus_for_each_dev+0x51/0x80 [] mcb_release_bus+0x19/0x40 [mcb] [] ? mcb_bus_add_devices+0x30/0x30 [mcb] [] mcb_pci_remove+0x13/0x20 [mcb_pci] [] pci_device_remove+0x28/0xb0 [] __device_release_driver+0x7b/0x110 [] driver_detach+0x87/0x90 [] bus_remove_driver+0x3b/0x80 [] driver_unregister+0x20/0x50 [] pci_unregister_driver+0x13/0x60 [] mcb_pci_driver_exit+0xd/0xf [mcb_pci] [] SyS_delete_module+0x138/0x200 [] ? ____fput+0x8/0x10 [] ? task_work_run+0x74/0x90 [] do_fast_syscall_32+0x69/0x120 [] sysenter_past_esp+0x40/0x6a ---[ end trace 1ed34c2aa3019875 ]--- Release a mcb_bus' memory on the device's release callback, to avoid above warning. Signed-off-by: Johannes Thumshirn Reported-by: Andreas Werner Tested-by: Andreas Werner Signed-off-by: Greg Kroah-Hartman --- drivers/mcb/mcb-core.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/mcb/mcb-core.c b/drivers/mcb/mcb-core.c index 9ae4d15fc229..b73c6e7d28e4 100644 --- a/drivers/mcb/mcb-core.c +++ b/drivers/mcb/mcb-core.c @@ -83,8 +83,8 @@ static int mcb_remove(struct device *dev) static void mcb_shutdown(struct device *dev) { + struct mcb_driver *mdrv = to_mcb_driver(dev->driver); struct mcb_device *mdev = to_mcb_device(dev); - struct mcb_driver *mdrv = mdev->driver; if (mdrv && mdrv->shutdown) mdrv->shutdown(mdev); @@ -214,6 +214,7 @@ int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev) int device_id; device_initialize(&dev->dev); + mcb_bus_get(bus); dev->dev.bus = &mcb_bus_type; dev->dev.parent = bus->dev.parent; dev->dev.release = mcb_release_dev; @@ -237,6 +238,15 @@ out: } EXPORT_SYMBOL_GPL(mcb_device_register); +static void mcb_free_bus(struct device *dev) +{ + struct mcb_bus *bus = to_mcb_bus(dev); + + put_device(bus->carrier); + ida_simple_remove(&mcb_ida, bus->bus_nr); + kfree(bus); +} + /** * mcb_alloc_bus() - Allocate a new @mcb_bus * @@ -259,12 +269,13 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier) } bus->bus_nr = bus_nr; - bus->carrier = carrier; + bus->carrier = get_device(carrier); device_initialize(&bus->dev); bus->dev.parent = carrier; bus->dev.bus = &mcb_bus_type; bus->dev.type = &mcb_carrier_device_type; + bus->dev.release = &mcb_free_bus; dev_set_name(&bus->dev, "mcb:%d", bus_nr); rc = device_add(&bus->dev); @@ -273,6 +284,7 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier) return bus; err_free: + put_device(carrier); kfree(bus); return ERR_PTR(rc); } @@ -297,10 +309,6 @@ static void mcb_devices_unregister(struct mcb_bus *bus) void mcb_release_bus(struct mcb_bus *bus) { mcb_devices_unregister(bus); - - ida_simple_remove(&mcb_ida, bus->bus_nr); - - kfree(bus); } EXPORT_SYMBOL_GPL(mcb_release_bus); -- 2.20.1