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

hwmon: (gpio-fan) Use devm_thermal_of_cooling_device_register

Call devm_thermal_of_cooling_device_register() to register the cooling
device. Also use devm_add_action_or_reset() to stop the fan on device
removal. This fixes a race condition since the fan was stopped before
the hwmon device was removed.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>

authored by

Guenter Roeck and committed by
Eduardo Valentin
95347845 389c0ad1

+9 -16
+9 -16
drivers/hwmon/gpio-fan.c
··· 498 498 }; 499 499 MODULE_DEVICE_TABLE(of, of_gpio_fan_match); 500 500 501 + static void gpio_fan_stop(void *data) 502 + { 503 + set_fan_speed(data, 0); 504 + } 505 + 501 506 static int gpio_fan_probe(struct platform_device *pdev) 502 507 { 503 508 int err; ··· 537 532 err = fan_ctrl_init(fan_data); 538 533 if (err) 539 534 return err; 535 + devm_add_action_or_reset(dev, gpio_fan_stop, fan_data); 540 536 } 541 537 542 538 /* Make this driver part of hwmon class. */ ··· 549 543 return PTR_ERR(fan_data->hwmon_dev); 550 544 551 545 /* Optional cooling device register for Device tree platforms */ 552 - fan_data->cdev = thermal_of_cooling_device_register(np, 553 - "gpio-fan", 554 - fan_data, 555 - &gpio_fan_cool_ops); 546 + fan_data->cdev = devm_thermal_of_cooling_device_register(dev, np, 547 + "gpio-fan", fan_data, &gpio_fan_cool_ops); 556 548 557 549 dev_info(dev, "GPIO fan initialized\n"); 558 550 559 551 return 0; 560 552 } 561 553 562 - static int gpio_fan_remove(struct platform_device *pdev) 554 + static void gpio_fan_shutdown(struct platform_device *pdev) 563 555 { 564 556 struct gpio_fan_data *fan_data = platform_get_drvdata(pdev); 565 557 566 - if (!IS_ERR(fan_data->cdev)) 567 - thermal_cooling_device_unregister(fan_data->cdev); 568 - 569 558 if (fan_data->gpios) 570 559 set_fan_speed(fan_data, 0); 571 - 572 - return 0; 573 - } 574 - 575 - static void gpio_fan_shutdown(struct platform_device *pdev) 576 - { 577 - gpio_fan_remove(pdev); 578 560 } 579 561 580 562 #ifdef CONFIG_PM_SLEEP ··· 596 602 597 603 static struct platform_driver gpio_fan_driver = { 598 604 .probe = gpio_fan_probe, 599 - .remove = gpio_fan_remove, 600 605 .shutdown = gpio_fan_shutdown, 601 606 .driver = { 602 607 .name = "gpio-fan",