hwmon: (smsc47m1) Convert to use devm_ functions
Convert to use devm_ functions to reduce code size and simplify the code. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Jean Delvare <khali@linux-fr.org>
This commit is contained in:
parent
e43d5fefa7
commit
08ad7c9522
|
@ -584,18 +584,17 @@ static void smsc47m1_restore(const struct smsc47m1_sio_data *sio_data)
|
||||||
|
|
||||||
#define CHECK 1
|
#define CHECK 1
|
||||||
#define REQUEST 2
|
#define REQUEST 2
|
||||||
#define RELEASE 3
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function can be used to:
|
* This function can be used to:
|
||||||
* - test for resource conflicts with ACPI
|
* - test for resource conflicts with ACPI
|
||||||
* - request the resources
|
* - request the resources
|
||||||
* - release the resources
|
|
||||||
* We only allocate the I/O ports we really need, to minimize the risk of
|
* We only allocate the I/O ports we really need, to minimize the risk of
|
||||||
* conflicts with ACPI or with other drivers.
|
* conflicts with ACPI or with other drivers.
|
||||||
*/
|
*/
|
||||||
static int smsc47m1_handle_resources(unsigned short address, enum chips type,
|
static int __init smsc47m1_handle_resources(unsigned short address,
|
||||||
int action, struct device *dev)
|
enum chips type, int action,
|
||||||
|
struct device *dev)
|
||||||
{
|
{
|
||||||
static const u8 ports_m1[] = {
|
static const u8 ports_m1[] = {
|
||||||
/* register, region length */
|
/* register, region length */
|
||||||
|
@ -642,21 +641,13 @@ static int smsc47m1_handle_resources(unsigned short address, enum chips type,
|
||||||
break;
|
break;
|
||||||
case REQUEST:
|
case REQUEST:
|
||||||
/* Request the resources */
|
/* Request the resources */
|
||||||
if (!request_region(start, len, DRVNAME)) {
|
if (!devm_request_region(dev, start, len, DRVNAME)) {
|
||||||
dev_err(dev, "Region 0x%hx-0x%hx already in "
|
dev_err(dev,
|
||||||
"use!\n", start, start + len);
|
"Region 0x%hx-0x%hx already in use!\n",
|
||||||
|
start, start + len);
|
||||||
/* Undo all requests */
|
|
||||||
for (i -= 2; i >= 0; i -= 2)
|
|
||||||
release_region(address + ports[i],
|
|
||||||
ports[i + 1]);
|
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RELEASE:
|
|
||||||
/* Release the resources */
|
|
||||||
release_region(start, len);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -694,11 +685,9 @@ static int __init smsc47m1_probe(struct platform_device *pdev)
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
data = kzalloc(sizeof(struct smsc47m1_data), GFP_KERNEL);
|
data = devm_kzalloc(dev, sizeof(struct smsc47m1_data), GFP_KERNEL);
|
||||||
if (!data) {
|
if (!data)
|
||||||
err = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto error_release;
|
|
||||||
}
|
|
||||||
|
|
||||||
data->addr = res->start;
|
data->addr = res->start;
|
||||||
data->type = sio_data->type;
|
data->type = sio_data->type;
|
||||||
|
@ -733,8 +722,7 @@ static int __init smsc47m1_probe(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
if (!(fan1 || fan2 || fan3 || pwm1 || pwm2 || pwm3)) {
|
if (!(fan1 || fan2 || fan3 || pwm1 || pwm2 || pwm3)) {
|
||||||
dev_warn(dev, "Device not configured, will not use\n");
|
dev_warn(dev, "Device not configured, will not use\n");
|
||||||
err = -ENODEV;
|
return -ENODEV;
|
||||||
goto error_free;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -810,27 +798,16 @@ static int __init smsc47m1_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
error_remove_files:
|
error_remove_files:
|
||||||
smsc47m1_remove_files(dev);
|
smsc47m1_remove_files(dev);
|
||||||
error_free:
|
|
||||||
platform_set_drvdata(pdev, NULL);
|
|
||||||
kfree(data);
|
|
||||||
error_release:
|
|
||||||
smsc47m1_handle_resources(res->start, sio_data->type, RELEASE, dev);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __exit smsc47m1_remove(struct platform_device *pdev)
|
static int __exit smsc47m1_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct smsc47m1_data *data = platform_get_drvdata(pdev);
|
struct smsc47m1_data *data = platform_get_drvdata(pdev);
|
||||||
struct resource *res;
|
|
||||||
|
|
||||||
hwmon_device_unregister(data->hwmon_dev);
|
hwmon_device_unregister(data->hwmon_dev);
|
||||||
smsc47m1_remove_files(&pdev->dev);
|
smsc47m1_remove_files(&pdev->dev);
|
||||||
|
|
||||||
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
|
|
||||||
smsc47m1_handle_resources(res->start, data->type, RELEASE, &pdev->dev);
|
|
||||||
platform_set_drvdata(pdev, NULL);
|
|
||||||
kfree(data);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue