summaryrefslogtreecommitdiff
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2014-12-29 15:13:06 -0800
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2015-01-08 13:55:30 -0800
commitb388de88308fde104fb6520dbf9e7b342fd5761a (patch)
tree584789383e65149142704cc46e372311a3f33bc4 /drivers/input
parent5b6c26a9f6437c4467f5d7cbf0313a7ae2be86b1 (diff)
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>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/misc/axp20x-pek.c64
1 files changed, 36 insertions, 28 deletions
diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
index 8dbd097ac939..f1c844739cd7 100644
--- a/drivers/input/misc/axp20x-pek.c
+++ b/drivers/input/misc/axp20x-pek.c
@@ -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",
},