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>
This commit is contained in:
Родитель
ba9c5fc395
Коммит
2be5f0d753
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче