Skip to content

Commit 2be5f0d

Browse files
Wer-Wolfgroeck
authored andcommitted
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>
1 parent ba9c5fc commit 2be5f0d

File tree

4 files changed

+16
-43
lines changed

4 files changed

+16
-43
lines changed

drivers/hwmon/sch5627.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ static const char * const SCH5627_IN_LABELS[SCH5627_NO_IN] = {
6464

6565
struct sch5627_data {
6666
unsigned short addr;
67-
struct sch56xx_watchdog_data *watchdog;
6867
u8 control;
6968
u8 temp_max[SCH5627_NO_TEMPS];
7069
u8 temp_crit[SCH5627_NO_TEMPS];
@@ -357,16 +356,6 @@ static const struct hwmon_chip_info sch5627_chip_info = {
357356
.info = sch5627_info,
358357
};
359358

360-
static int sch5627_remove(struct platform_device *pdev)
361-
{
362-
struct sch5627_data *data = platform_get_drvdata(pdev);
363-
364-
if (data->watchdog)
365-
sch56xx_watchdog_unregister(data->watchdog);
366-
367-
return 0;
368-
}
369-
370359
static int sch5627_probe(struct platform_device *pdev)
371360
{
372361
struct sch5627_data *data;
@@ -460,9 +449,9 @@ static int sch5627_probe(struct platform_device *pdev)
460449
return PTR_ERR(hwmon_dev);
461450

462451
/* Note failing to register the watchdog is not a fatal error */
463-
data->watchdog = sch56xx_watchdog_register(&pdev->dev, data->addr,
464-
(build_code << 24) | (build_id << 8) | hwmon_rev,
465-
&data->update_lock, 1);
452+
sch56xx_watchdog_register(&pdev->dev, data->addr,
453+
(build_code << 24) | (build_id << 8) | hwmon_rev,
454+
&data->update_lock, 1);
466455

467456
return 0;
468457
}
@@ -472,7 +461,6 @@ static struct platform_driver sch5627_driver = {
472461
.name = DRVNAME,
473462
},
474463
.probe = sch5627_probe,
475-
.remove = sch5627_remove,
476464
};
477465

478466
module_platform_driver(sch5627_driver);

drivers/hwmon/sch5636.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ static const u16 SCH5636_REG_FAN_VAL[SCH5636_NO_FANS] = {
5454
struct sch5636_data {
5555
unsigned short addr;
5656
struct device *hwmon_dev;
57-
struct sch56xx_watchdog_data *watchdog;
5857

5958
struct mutex update_lock;
6059
char valid; /* !=0 if following fields are valid */
@@ -372,9 +371,6 @@ static int sch5636_remove(struct platform_device *pdev)
372371
struct sch5636_data *data = platform_get_drvdata(pdev);
373372
int i;
374373

375-
if (data->watchdog)
376-
sch56xx_watchdog_unregister(data->watchdog);
377-
378374
if (data->hwmon_dev)
379375
hwmon_device_unregister(data->hwmon_dev);
380376

@@ -495,9 +491,8 @@ static int sch5636_probe(struct platform_device *pdev)
495491
}
496492

497493
/* Note failing to register the watchdog is not a fatal error */
498-
data->watchdog = sch56xx_watchdog_register(&pdev->dev, data->addr,
499-
(revision[0] << 8) | revision[1],
500-
&data->update_lock, 0);
494+
sch56xx_watchdog_register(&pdev->dev, data->addr, (revision[0] << 8) | revision[1],
495+
&data->update_lock, 0);
501496

502497
return 0;
503498

drivers/hwmon/sch56xx-common.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ static const struct watchdog_ops watchdog_ops = {
378378
.set_timeout = watchdog_set_timeout,
379379
};
380380

381-
struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent,
382-
u16 addr, u32 revision, struct mutex *io_lock, int check_enabled)
381+
void sch56xx_watchdog_register(struct device *parent, u16 addr, u32 revision,
382+
struct mutex *io_lock, int check_enabled)
383383
{
384384
struct sch56xx_watchdog_data *data;
385385
int err, control, output_enable;
@@ -393,17 +393,17 @@ struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent,
393393
mutex_unlock(io_lock);
394394

395395
if (control < 0)
396-
return NULL;
396+
return;
397397
if (output_enable < 0)
398-
return NULL;
398+
return;
399399
if (check_enabled && !(output_enable & SCH56XX_WDOG_OUTPUT_ENABLE)) {
400400
pr_warn("Watchdog not enabled by BIOS, not registering\n");
401-
return NULL;
401+
return;
402402
}
403403

404-
data = kzalloc(sizeof(struct sch56xx_watchdog_data), GFP_KERNEL);
404+
data = devm_kzalloc(parent, sizeof(struct sch56xx_watchdog_data), GFP_KERNEL);
405405
if (!data)
406-
return NULL;
406+
return;
407407

408408
data->addr = addr;
409409
data->io_lock = io_lock;
@@ -438,24 +438,14 @@ struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent,
438438
data->watchdog_output_enable = output_enable;
439439

440440
watchdog_set_drvdata(&data->wddev, data);
441-
err = watchdog_register_device(&data->wddev);
441+
err = devm_watchdog_register_device(parent, &data->wddev);
442442
if (err) {
443443
pr_err("Registering watchdog chardev: %d\n", err);
444-
kfree(data);
445-
return NULL;
444+
devm_kfree(parent, data);
446445
}
447-
448-
return data;
449446
}
450447
EXPORT_SYMBOL(sch56xx_watchdog_register);
451448

452-
void sch56xx_watchdog_unregister(struct sch56xx_watchdog_data *data)
453-
{
454-
watchdog_unregister_device(&data->wddev);
455-
kfree(data);
456-
}
457-
EXPORT_SYMBOL(sch56xx_watchdog_unregister);
458-
459449
/*
460450
* platform dev find, add and remove functions
461451
*/

drivers/hwmon/sch56xx-common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ int sch56xx_read_virtual_reg16(u16 addr, u16 reg);
1414
int sch56xx_read_virtual_reg12(u16 addr, u16 msb_reg, u16 lsn_reg,
1515
int high_nibble);
1616

17-
struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent,
18-
u16 addr, u32 revision, struct mutex *io_lock, int check_enabled);
17+
void sch56xx_watchdog_register(struct device *parent, u16 addr, u32 revision,
18+
struct mutex *io_lock, int check_enabled);
1919
void sch56xx_watchdog_unregister(struct sch56xx_watchdog_data *data);

0 commit comments

Comments
 (0)