Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Armin Wolf and committed by
Guenter Roeck
2be5f0d7 ba9c5fc3

+16 -43
+3 -15
drivers/hwmon/sch5627.c
··· 64 64 65 65 struct sch5627_data { 66 66 unsigned short addr; 67 - struct sch56xx_watchdog_data *watchdog; 68 67 u8 control; 69 68 u8 temp_max[SCH5627_NO_TEMPS]; 70 69 u8 temp_crit[SCH5627_NO_TEMPS]; ··· 356 357 .info = sch5627_info, 357 358 }; 358 359 359 - static int sch5627_remove(struct platform_device *pdev) 360 - { 361 - struct sch5627_data *data = platform_get_drvdata(pdev); 362 - 363 - if (data->watchdog) 364 - sch56xx_watchdog_unregister(data->watchdog); 365 - 366 - return 0; 367 - } 368 - 369 360 static int sch5627_probe(struct platform_device *pdev) 370 361 { 371 362 struct sch5627_data *data; ··· 449 460 return PTR_ERR(hwmon_dev); 450 461 451 462 /* Note failing to register the watchdog is not a fatal error */ 452 - data->watchdog = sch56xx_watchdog_register(&pdev->dev, data->addr, 453 - (build_code << 24) | (build_id << 8) | hwmon_rev, 454 - &data->update_lock, 1); 463 + sch56xx_watchdog_register(&pdev->dev, data->addr, 464 + (build_code << 24) | (build_id << 8) | hwmon_rev, 465 + &data->update_lock, 1); 455 466 456 467 return 0; 457 468 } ··· 461 472 .name = DRVNAME, 462 473 }, 463 474 .probe = sch5627_probe, 464 - .remove = sch5627_remove, 465 475 }; 466 476 467 477 module_platform_driver(sch5627_driver);
+2 -7
drivers/hwmon/sch5636.c
··· 54 54 struct sch5636_data { 55 55 unsigned short addr; 56 56 struct device *hwmon_dev; 57 - struct sch56xx_watchdog_data *watchdog; 58 57 59 58 struct mutex update_lock; 60 59 char valid; /* !=0 if following fields are valid */ ··· 371 372 struct sch5636_data *data = platform_get_drvdata(pdev); 372 373 int i; 373 374 374 - if (data->watchdog) 375 - sch56xx_watchdog_unregister(data->watchdog); 376 - 377 375 if (data->hwmon_dev) 378 376 hwmon_device_unregister(data->hwmon_dev); 379 377 ··· 491 495 } 492 496 493 497 /* Note failing to register the watchdog is not a fatal error */ 494 - data->watchdog = sch56xx_watchdog_register(&pdev->dev, data->addr, 495 - (revision[0] << 8) | revision[1], 496 - &data->update_lock, 0); 498 + sch56xx_watchdog_register(&pdev->dev, data->addr, (revision[0] << 8) | revision[1], 499 + &data->update_lock, 0); 497 500 498 501 return 0; 499 502
+9 -19
drivers/hwmon/sch56xx-common.c
··· 378 378 .set_timeout = watchdog_set_timeout, 379 379 }; 380 380 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) 383 383 { 384 384 struct sch56xx_watchdog_data *data; 385 385 int err, control, output_enable; ··· 393 393 mutex_unlock(io_lock); 394 394 395 395 if (control < 0) 396 - return NULL; 396 + return; 397 397 if (output_enable < 0) 398 - return NULL; 398 + return; 399 399 if (check_enabled && !(output_enable & SCH56XX_WDOG_OUTPUT_ENABLE)) { 400 400 pr_warn("Watchdog not enabled by BIOS, not registering\n"); 401 - return NULL; 401 + return; 402 402 } 403 403 404 - data = kzalloc(sizeof(struct sch56xx_watchdog_data), GFP_KERNEL); 404 + data = devm_kzalloc(parent, sizeof(struct sch56xx_watchdog_data), GFP_KERNEL); 405 405 if (!data) 406 - return NULL; 406 + return; 407 407 408 408 data->addr = addr; 409 409 data->io_lock = io_lock; ··· 438 438 data->watchdog_output_enable = output_enable; 439 439 440 440 watchdog_set_drvdata(&data->wddev, data); 441 - err = watchdog_register_device(&data->wddev); 441 + err = devm_watchdog_register_device(parent, &data->wddev); 442 442 if (err) { 443 443 pr_err("Registering watchdog chardev: %d\n", err); 444 - kfree(data); 445 - return NULL; 444 + devm_kfree(parent, data); 446 445 } 447 - 448 - return data; 449 446 } 450 447 EXPORT_SYMBOL(sch56xx_watchdog_register); 451 - 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 448 459 449 /* 460 450 * platform dev find, add and remove functions
+2 -2
drivers/hwmon/sch56xx-common.h
··· 14 14 int sch56xx_read_virtual_reg12(u16 addr, u16 msb_reg, u16 lsn_reg, 15 15 int high_nibble); 16 16 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); 19 19 void sch56xx_watchdog_unregister(struct sch56xx_watchdog_data *data);