]> www.infradead.org Git - linux.git/commitdiff
Input: adxl34x - use device core to create driver-specific device attributes
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 10 Jun 2024 16:42:57 +0000 (09:42 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 11 Jun 2024 18:17:44 +0000 (11:17 -0700)
Instead of creating driver-specific device attributes with
sysfs_create_group() have device core do this by setting up dev_groups
pointer in the driver structure.

Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
Link: https://lore.kernel.org/r/20240610164301.1048482-1-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/misc/adxl34x-i2c.c
drivers/input/misc/adxl34x-spi.c
drivers/input/misc/adxl34x.c
drivers/input/misc/adxl34x.h

index d4014e367c770c37fa71979c2437925db9ec0cc9..7531c7b2d65722356d83b916e6898fed94a5f3fe 100644 (file)
@@ -132,6 +132,7 @@ MODULE_DEVICE_TABLE(of, adxl34x_of_id);
 static struct i2c_driver adxl34x_driver = {
        .driver = {
                .name = "adxl34x",
+               .dev_groups = adxl34x_groups,
                .pm = pm_sleep_ptr(&adxl34x_pm),
                .of_match_table = adxl34x_of_id,
        },
index f1094a8ccdd5f31a708a37464aefab2aada5e11e..2befcc4df0beef4eaa34c85e275b1d8c28c173c5 100644 (file)
@@ -97,6 +97,7 @@ static void adxl34x_spi_remove(struct spi_device *spi)
 static struct spi_driver adxl34x_driver = {
        .driver = {
                .name = "adxl34x",
+               .dev_groups = adxl34x_groups,
                .pm = pm_sleep_ptr(&adxl34x_pm),
        },
        .probe   = adxl34x_spi_probe,
index a3f45e0ee0c754080a137f8d71289079fc3701dc..fbe5a56c19d11bafe39ea849b0797a9d4e6ba34d 100644 (file)
@@ -664,6 +664,12 @@ static const struct attribute_group adxl34x_attr_group = {
        .attrs = adxl34x_attributes,
 };
 
+const struct attribute_group *adxl34x_groups[] = {
+       &adxl34x_attr_group,
+       NULL
+};
+EXPORT_SYMBOL_GPL(adxl34x_groups);
+
 static int adxl34x_input_open(struct input_dev *input)
 {
        struct adxl34x *ac = input_get_drvdata(input);
@@ -823,13 +829,9 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq,
                goto err_free_mem;
        }
 
-       err = sysfs_create_group(&dev->kobj, &adxl34x_attr_group);
-       if (err)
-               goto err_free_irq;
-
        err = input_register_device(input_dev);
        if (err)
-               goto err_remove_attr;
+               goto err_free_irq;
 
        AC_WRITE(ac, OFSX, pdata->x_axis_offset);
        ac->hwcal.x = pdata->x_axis_offset;
@@ -889,8 +891,6 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq,
 
        return ac;
 
- err_remove_attr:
-       sysfs_remove_group(&dev->kobj, &adxl34x_attr_group);
  err_free_irq:
        free_irq(ac->irq, ac);
  err_free_mem:
@@ -903,7 +903,6 @@ EXPORT_SYMBOL_GPL(adxl34x_probe);
 
 void adxl34x_remove(struct adxl34x *ac)
 {
-       sysfs_remove_group(&ac->dev->kobj, &adxl34x_attr_group);
        free_irq(ac->irq, ac);
        input_unregister_device(ac->input);
        dev_dbg(ac->dev, "unregistered accelerometer\n");
index f9272a2e7a96d636064fcadcb5d4a11342a03a02..67e0ddc5c3eb2b6141ff0947d19ae346d8d0b7ad 100644 (file)
@@ -26,5 +26,6 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq,
 void adxl34x_remove(struct adxl34x *ac);
 
 extern const struct dev_pm_ops adxl34x_pm;
+extern const struct attribute_group *adxl34x_groups[];
 
 #endif