Commit 9ebe010e authored by Guenter Roeck's avatar Guenter Roeck Committed by Eduardo Valentin

hwmon: (mlxreg-fan) Use devm_thermal_of_cooling_device_register

Call devm_thermal_of_cooling_device_register() to register the cooling
device. Also introduce struct device *dev = &pdev->dev; to make the code
easier to read.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarEduardo Valentin <edubezval@gmail.com>
parent 95347845
...@@ -420,42 +420,42 @@ static int mlxreg_fan_config(struct mlxreg_fan *fan, ...@@ -420,42 +420,42 @@ static int mlxreg_fan_config(struct mlxreg_fan *fan,
static int mlxreg_fan_probe(struct platform_device *pdev) static int mlxreg_fan_probe(struct platform_device *pdev)
{ {
struct mlxreg_core_platform_data *pdata; struct mlxreg_core_platform_data *pdata;
struct device *dev = &pdev->dev;
struct mlxreg_fan *fan; struct mlxreg_fan *fan;
struct device *hwm; struct device *hwm;
int err; int err;
pdata = dev_get_platdata(&pdev->dev); pdata = dev_get_platdata(dev);
if (!pdata) { if (!pdata) {
dev_err(&pdev->dev, "Failed to get platform data.\n"); dev_err(dev, "Failed to get platform data.\n");
return -EINVAL; return -EINVAL;
} }
fan = devm_kzalloc(&pdev->dev, sizeof(*fan), GFP_KERNEL); fan = devm_kzalloc(dev, sizeof(*fan), GFP_KERNEL);
if (!fan) if (!fan)
return -ENOMEM; return -ENOMEM;
fan->dev = &pdev->dev; fan->dev = dev;
fan->regmap = pdata->regmap; fan->regmap = pdata->regmap;
platform_set_drvdata(pdev, fan);
err = mlxreg_fan_config(fan, pdata); err = mlxreg_fan_config(fan, pdata);
if (err) if (err)
return err; return err;
hwm = devm_hwmon_device_register_with_info(&pdev->dev, "mlxreg_fan", hwm = devm_hwmon_device_register_with_info(dev, "mlxreg_fan",
fan, fan,
&mlxreg_fan_hwmon_chip_info, &mlxreg_fan_hwmon_chip_info,
NULL); NULL);
if (IS_ERR(hwm)) { if (IS_ERR(hwm)) {
dev_err(&pdev->dev, "Failed to register hwmon device\n"); dev_err(dev, "Failed to register hwmon device\n");
return PTR_ERR(hwm); return PTR_ERR(hwm);
} }
if (IS_REACHABLE(CONFIG_THERMAL)) { if (IS_REACHABLE(CONFIG_THERMAL)) {
fan->cdev = thermal_cooling_device_register("mlxreg_fan", fan, fan->cdev = devm_thermal_of_cooling_device_register(dev,
&mlxreg_fan_cooling_ops); NULL, "mlxreg_fan", fan, &mlxreg_fan_cooling_ops);
if (IS_ERR(fan->cdev)) { if (IS_ERR(fan->cdev)) {
dev_err(&pdev->dev, "Failed to register cooling device\n"); dev_err(dev, "Failed to register cooling device\n");
return PTR_ERR(fan->cdev); return PTR_ERR(fan->cdev);
} }
} }
...@@ -463,22 +463,11 @@ static int mlxreg_fan_probe(struct platform_device *pdev) ...@@ -463,22 +463,11 @@ static int mlxreg_fan_probe(struct platform_device *pdev)
return 0; return 0;
} }
static int mlxreg_fan_remove(struct platform_device *pdev)
{
struct mlxreg_fan *fan = platform_get_drvdata(pdev);
if (IS_REACHABLE(CONFIG_THERMAL))
thermal_cooling_device_unregister(fan->cdev);
return 0;
}
static struct platform_driver mlxreg_fan_driver = { static struct platform_driver mlxreg_fan_driver = {
.driver = { .driver = {
.name = "mlxreg-fan", .name = "mlxreg-fan",
}, },
.probe = mlxreg_fan_probe, .probe = mlxreg_fan_probe,
.remove = mlxreg_fan_remove,
}; };
module_platform_driver(mlxreg_fan_driver); module_platform_driver(mlxreg_fan_driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment