mirror of
https://github.com/torvalds/linux.git
synced 2024-12-24 11:51:27 +00:00
Input: axp20x-pek - switch over to using attribute group
Instead of registering device attributes individually let's use attribute groups and also devm_* infrastructure to ease cleanup. Tested-by: Chen-Yu Tsai <wens@csie.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
parent
5b6c26a9f6
commit
b388de8830
@ -138,17 +138,28 @@ static ssize_t axp20x_store_ext_attr(struct device *dev,
|
||||
axp20x_ea->mask, idx);
|
||||
if (ret != 0)
|
||||
return -EINVAL;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static struct dev_ext_attribute axp20x_dev_attr_startup = {
|
||||
.attr = __ATTR(startup, 0644, axp20x_show_ext_attr, axp20x_store_ext_attr),
|
||||
.var = &axp20x_pek_startup_ext_attr
|
||||
.var = &axp20x_pek_startup_ext_attr,
|
||||
};
|
||||
|
||||
static struct dev_ext_attribute axp20x_dev_attr_shutdown = {
|
||||
.attr = __ATTR(shutdown, 0644, axp20x_show_ext_attr, axp20x_store_ext_attr),
|
||||
.var = &axp20x_pek_shutdown_ext_attr
|
||||
.var = &axp20x_pek_shutdown_ext_attr,
|
||||
};
|
||||
|
||||
static struct attribute *axp20x_attributes[] = {
|
||||
&axp20x_dev_attr_startup.attr.attr,
|
||||
&axp20x_dev_attr_shutdown.attr.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group axp20x_attribute_group = {
|
||||
.attrs = axp20x_attributes,
|
||||
};
|
||||
|
||||
static irqreturn_t axp20x_pek_irq(int irq, void *pwr)
|
||||
@ -166,6 +177,13 @@ static irqreturn_t axp20x_pek_irq(int irq, void *pwr)
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static void axp20x_remove_sysfs_group(void *_data)
|
||||
{
|
||||
struct device *dev = _data;
|
||||
|
||||
sysfs_remove_group(&dev->kobj, &axp20x_attribute_group);
|
||||
}
|
||||
|
||||
static int axp20x_pek_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct axp20x_pek *axp20x_pek;
|
||||
@ -214,12 +232,11 @@ static int axp20x_pek_probe(struct platform_device *pdev)
|
||||
input_set_drvdata(idev, axp20x_pek);
|
||||
|
||||
error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbr,
|
||||
axp20x_pek_irq, 0,
|
||||
"axp20x-pek-dbr", idev);
|
||||
axp20x_pek_irq, 0,
|
||||
"axp20x-pek-dbr", idev);
|
||||
if (error < 0) {
|
||||
dev_err(axp20x->dev, "Failed to request dbr IRQ#%d: %d\n",
|
||||
axp20x_pek->irq_dbr, error);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -232,45 +249,36 @@ static int axp20x_pek_probe(struct platform_device *pdev)
|
||||
return error;
|
||||
}
|
||||
|
||||
error = device_create_file(&pdev->dev, &axp20x_dev_attr_startup.attr);
|
||||
if (error)
|
||||
error = sysfs_create_group(&pdev->dev.kobj, &axp20x_attribute_group);
|
||||
if (error) {
|
||||
dev_err(axp20x->dev, "Failed to create sysfs attributes: %d\n",
|
||||
error);
|
||||
return error;
|
||||
}
|
||||
|
||||
error = device_create_file(&pdev->dev, &axp20x_dev_attr_shutdown.attr);
|
||||
if (error)
|
||||
goto clear_startup_attr;
|
||||
error = devm_add_action(&pdev->dev,
|
||||
axp20x_remove_sysfs_group, &pdev->dev);
|
||||
if (error) {
|
||||
axp20x_remove_sysfs_group(&pdev->dev);
|
||||
dev_err(&pdev->dev, "Failed to add sysfs cleanup action: %d\n",
|
||||
error);
|
||||
return error;
|
||||
}
|
||||
|
||||
error = input_register_device(idev);
|
||||
if (error) {
|
||||
dev_err(axp20x->dev, "Can't register input device: %d\n",
|
||||
error);
|
||||
goto clear_attr;
|
||||
return error;
|
||||
}
|
||||
|
||||
platform_set_drvdata(pdev, axp20x_pek);
|
||||
|
||||
return 0;
|
||||
|
||||
clear_attr:
|
||||
device_remove_file(&pdev->dev, &axp20x_dev_attr_shutdown.attr);
|
||||
|
||||
clear_startup_attr:
|
||||
device_remove_file(&pdev->dev, &axp20x_dev_attr_startup.attr);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static int axp20x_pek_remove(struct platform_device *pdev)
|
||||
{
|
||||
device_remove_file(&pdev->dev, &axp20x_dev_attr_shutdown.attr);
|
||||
device_remove_file(&pdev->dev, &axp20x_dev_attr_startup.attr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver axp20x_pek_driver = {
|
||||
.probe = axp20x_pek_probe,
|
||||
.remove = axp20x_pek_remove,
|
||||
.driver = {
|
||||
.name = "axp20x-pek",
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user