diff options
author | Armin Wolf <W_Armin@gmx.de> | 2021-05-08 16:14:54 +0300 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2021-06-17 14:21:44 +0300 |
commit | 2be5f0d7532566d41194fe99d35d022ad399460d (patch) | |
tree | 77167ec9eab66df8cc1b5dd1db4eef53cc4c791b | |
parent | ba9c5fc395de5bb642ed973dbf34c1d0c82d185d (diff) | |
download | linux-2be5f0d7532566d41194fe99d35d022ad399460d.tar.xz |
hwmon: (sch56xx) Use devres functions for watchdog
Use devm_kzalloc()/devm_watchdog_register() for
watchdog registration since it allows us to remove
the sch56xx_watchdog_data struct from the drivers
own data structs.
Remove sch56xx_watchdog_unregister since devres
takes care of that now.
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20210508131457.12780-2-W_Armin@gmx.de
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
[groeck: Dropped unnecessary return; at end of void function]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/sch5627.c | 18 | ||||
-rw-r--r-- | drivers/hwmon/sch5636.c | 9 | ||||
-rw-r--r-- | drivers/hwmon/sch56xx-common.c | 28 | ||||
-rw-r--r-- | drivers/hwmon/sch56xx-common.h | 4 |
4 files changed, 16 insertions, 43 deletions
diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c index 4324a5dbc968..8f1b569c69e7 100644 --- a/drivers/hwmon/sch5627.c +++ b/drivers/hwmon/sch5627.c @@ -64,7 +64,6 @@ static const char * const SCH5627_IN_LABELS[SCH5627_NO_IN] = { struct sch5627_data { unsigned short addr; - struct sch56xx_watchdog_data *watchdog; u8 control; u8 temp_max[SCH5627_NO_TEMPS]; u8 temp_crit[SCH5627_NO_TEMPS]; @@ -357,16 +356,6 @@ static const struct hwmon_chip_info sch5627_chip_info = { .info = sch5627_info, }; -static int sch5627_remove(struct platform_device *pdev) -{ - struct sch5627_data *data = platform_get_drvdata(pdev); - - if (data->watchdog) - sch56xx_watchdog_unregister(data->watchdog); - - return 0; -} - static int sch5627_probe(struct platform_device *pdev) { struct sch5627_data *data; @@ -460,9 +449,9 @@ static int sch5627_probe(struct platform_device *pdev) return PTR_ERR(hwmon_dev); /* Note failing to register the watchdog is not a fatal error */ - data->watchdog = sch56xx_watchdog_register(&pdev->dev, data->addr, - (build_code << 24) | (build_id << 8) | hwmon_rev, - &data->update_lock, 1); + sch56xx_watchdog_register(&pdev->dev, data->addr, + (build_code << 24) | (build_id << 8) | hwmon_rev, + &data->update_lock, 1); return 0; } @@ -472,7 +461,6 @@ static struct platform_driver sch5627_driver = { .name = DRVNAME, }, .probe = sch5627_probe, - .remove = sch5627_remove, }; module_platform_driver(sch5627_driver); diff --git a/drivers/hwmon/sch5636.c b/drivers/hwmon/sch5636.c index 5683a38740f6..a5cd4de36575 100644 --- a/drivers/hwmon/sch5636.c +++ b/drivers/hwmon/sch5636.c @@ -54,7 +54,6 @@ static const u16 SCH5636_REG_FAN_VAL[SCH5636_NO_FANS] = { struct sch5636_data { unsigned short addr; struct device *hwmon_dev; - struct sch56xx_watchdog_data *watchdog; struct mutex update_lock; char valid; /* !=0 if following fields are valid */ @@ -372,9 +371,6 @@ static int sch5636_remove(struct platform_device *pdev) struct sch5636_data *data = platform_get_drvdata(pdev); int i; - if (data->watchdog) - sch56xx_watchdog_unregister(data->watchdog); - if (data->hwmon_dev) hwmon_device_unregister(data->hwmon_dev); @@ -495,9 +491,8 @@ static int sch5636_probe(struct platform_device *pdev) } /* Note failing to register the watchdog is not a fatal error */ - data->watchdog = sch56xx_watchdog_register(&pdev->dev, data->addr, - (revision[0] << 8) | revision[1], - &data->update_lock, 0); + sch56xx_watchdog_register(&pdev->dev, data->addr, (revision[0] << 8) | revision[1], + &data->update_lock, 0); return 0; diff --git a/drivers/hwmon/sch56xx-common.c b/drivers/hwmon/sch56xx-common.c index 6c84780e358e..b469d16ec175 100644 --- a/drivers/hwmon/sch56xx-common.c +++ b/drivers/hwmon/sch56xx-common.c @@ -378,8 +378,8 @@ static const struct watchdog_ops watchdog_ops = { .set_timeout = watchdog_set_timeout, }; -struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent, - u16 addr, u32 revision, struct mutex *io_lock, int check_enabled) +void sch56xx_watchdog_register(struct device *parent, u16 addr, u32 revision, + struct mutex *io_lock, int check_enabled) { struct sch56xx_watchdog_data *data; int err, control, output_enable; @@ -393,17 +393,17 @@ struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent, mutex_unlock(io_lock); if (control < 0) - return NULL; + return; if (output_enable < 0) - return NULL; + return; if (check_enabled && !(output_enable & SCH56XX_WDOG_OUTPUT_ENABLE)) { pr_warn("Watchdog not enabled by BIOS, not registering\n"); - return NULL; + return; } - data = kzalloc(sizeof(struct sch56xx_watchdog_data), GFP_KERNEL); + data = devm_kzalloc(parent, sizeof(struct sch56xx_watchdog_data), GFP_KERNEL); if (!data) - return NULL; + return; data->addr = addr; data->io_lock = io_lock; @@ -438,24 +438,14 @@ struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent, data->watchdog_output_enable = output_enable; watchdog_set_drvdata(&data->wddev, data); - err = watchdog_register_device(&data->wddev); + err = devm_watchdog_register_device(parent, &data->wddev); if (err) { pr_err("Registering watchdog chardev: %d\n", err); - kfree(data); - return NULL; + devm_kfree(parent, data); } - - return data; } EXPORT_SYMBOL(sch56xx_watchdog_register); -void sch56xx_watchdog_unregister(struct sch56xx_watchdog_data *data) -{ - watchdog_unregister_device(&data->wddev); - kfree(data); -} -EXPORT_SYMBOL(sch56xx_watchdog_unregister); - /* * platform dev find, add and remove functions */ diff --git a/drivers/hwmon/sch56xx-common.h b/drivers/hwmon/sch56xx-common.h index 75eb73617cf2..e907d9da0dd5 100644 --- a/drivers/hwmon/sch56xx-common.h +++ b/drivers/hwmon/sch56xx-common.h @@ -14,6 +14,6 @@ int sch56xx_read_virtual_reg16(u16 addr, u16 reg); int sch56xx_read_virtual_reg12(u16 addr, u16 msb_reg, u16 lsn_reg, int high_nibble); -struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent, - u16 addr, u32 revision, struct mutex *io_lock, int check_enabled); +void sch56xx_watchdog_register(struct device *parent, u16 addr, u32 revision, + struct mutex *io_lock, int check_enabled); void sch56xx_watchdog_unregister(struct sch56xx_watchdog_data *data); |