From bdb57b7bc16252599cbcb826dfdf7e394dd2af4b Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Thu, 21 Feb 2019 17:21:50 -0600 Subject: ipmi_si: Remove hotmod devices on removal and exit When a hotmod-added device is removed or when the module is removed, remove the platform devices that was created for it. Signed-off-by: Corey Minyard --- drivers/char/ipmi/ipmi_si_hotmod.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'drivers/char/ipmi/ipmi_si_hotmod.c') diff --git a/drivers/char/ipmi/ipmi_si_hotmod.c b/drivers/char/ipmi/ipmi_si_hotmod.c index f0728be00bd2..230b10e7d288 100644 --- a/drivers/char/ipmi/ipmi_si_hotmod.c +++ b/drivers/char/ipmi/ipmi_si_hotmod.c @@ -219,7 +219,18 @@ static int hotmod_handler(const char *val, const struct kernel_param *kp) atomic_inc_return(&hotmod_nr), &h); } else { - ipmi_si_remove_by_data(h.space, h.type, h.addr); + struct device *dev; + + dev = ipmi_si_remove_by_data(h.space, h.type, h.addr); + if (dev && dev_is_platform(dev)) { + struct platform_device *pdev; + + pdev = to_platform_device(dev); + if (strcmp(pdev->name, "hotmod-ipmi-si") == 0) + platform_device_unregister(pdev); + } + if (dev) + put_device(dev); } } rv = len; @@ -227,3 +238,22 @@ out: kfree(str); return rv; } + +static int pdev_match_name(struct device *dev, void *data) +{ + struct platform_device *pdev = to_platform_device(dev); + + return strcmp(pdev->name, "hotmod-ipmi-si") == 0; +} + +void ipmi_si_hotmod_exit(void) +{ + struct device *dev; + + while ((dev = bus_find_device(&platform_bus_type, NULL, NULL, + pdev_match_name))) { + struct platform_device *pdev = to_platform_device(dev); + + platform_device_unregister(pdev); + } +} -- cgit v1.2.3