diff mbox series

[1/3] Input: adxl34x - use device core to create driver-specific device attributes

Message ID 20240609234122.603796-1-dmitry.torokhov@gmail.com
State Accepted
Commit 6f7e4f81f738ac765318c54097a6235203073049
Headers show
Series [1/3] Input: adxl34x - use device core to create driver-specific device attributes | expand

Commit Message

Dmitry Torokhov June 9, 2024, 11:41 p.m. UTC
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.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/misc/adxl34x-i2c.c |  1 +
 drivers/input/misc/adxl34x-spi.c |  1 +
 drivers/input/misc/adxl34x.c     | 15 +++++++--------
 drivers/input/misc/adxl34x.h     |  1 +
 4 files changed, 10 insertions(+), 8 deletions(-)

Comments

Nuno Sá June 10, 2024, 9:25 a.m. UTC | #1
On Sun, 2024-06-09 at 16:41 -0700, Dmitry Torokhov wrote:
> Switch the driver to use managed resources to simplify error handling.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/input/misc/adxl34x-i2c.c |  8 ---
>  drivers/input/misc/adxl34x-spi.c |  8 ---
>  drivers/input/misc/adxl34x.c     | 85 +++++++++++---------------------
>  drivers/input/misc/adxl34x.h     |  1 -
>  4 files changed, 30 insertions(+), 72 deletions(-)
> 
> diff --git a/drivers/input/misc/adxl34x-i2c.c b/drivers/input/misc/adxl34x-
> i2c.c
> index 7531c7b2d657..c05d898898e8 100644
> --- a/drivers/input/misc/adxl34x-i2c.c
> +++ b/drivers/input/misc/adxl34x-i2c.c
> @@ -98,13 +98,6 @@ static int adxl34x_i2c_probe(struct i2c_client *client)
>  	return 0;
>  }
>  
> -static void adxl34x_i2c_remove(struct i2c_client *client)
> -{
> -	struct adxl34x *ac = i2c_get_clientdata(client);
> -
> -	adxl34x_remove(ac);
> -}
> -
>  static const struct i2c_device_id adxl34x_id[] = {
>  	{ "adxl34x" },
>  	{ }
> @@ -137,7 +130,6 @@ static struct i2c_driver adxl34x_driver = {
>  		.of_match_table = adxl34x_of_id,
>  	},
>  	.probe    = adxl34x_i2c_probe,
> -	.remove   = adxl34x_i2c_remove,
>  	.id_table = adxl34x_id,
>  };
>  
> diff --git a/drivers/input/misc/adxl34x-spi.c b/drivers/input/misc/adxl34x-
> spi.c
> index 2befcc4df0be..fd716d861832 100644
> --- a/drivers/input/misc/adxl34x-spi.c
> +++ b/drivers/input/misc/adxl34x-spi.c
> @@ -87,13 +87,6 @@ static int adxl34x_spi_probe(struct spi_device *spi)
>  	return 0;
>  }
>  
> -static void adxl34x_spi_remove(struct spi_device *spi)
> -{
> -	struct adxl34x *ac = spi_get_drvdata(spi);
> -
> -	adxl34x_remove(ac);
> -}
> -
>  static struct spi_driver adxl34x_driver = {
>  	.driver = {
>  		.name = "adxl34x",
> @@ -101,7 +94,6 @@ static struct spi_driver adxl34x_driver = {
>  		.pm = pm_sleep_ptr(&adxl34x_pm),
>  	},
>  	.probe   = adxl34x_spi_probe,
> -	.remove  = adxl34x_spi_remove,
>  };
>  
>  module_spi_driver(adxl34x_driver);
> diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c
> index fbe5a56c19d1..c6c34005f5d2 100644
> --- a/drivers/input/misc/adxl34x.c
> +++ b/drivers/input/misc/adxl34x.c
> @@ -707,21 +707,21 @@ struct adxl34x *adxl34x_probe(struct device *dev, int
> irq,
>  	struct adxl34x *ac;
>  	struct input_dev *input_dev;
>  	const struct adxl34x_platform_data *pdata;
> -	int err, range, i;
> +	int error, range, i;
>  	int revid;
>  
>  	if (!irq) {
>  		dev_err(dev, "no IRQ?\n");
> -		err = -ENODEV;
> -		goto err_out;
> +		return ERR_PTR(-ENODEV);
>  	}
>  
> -	ac = kzalloc(sizeof(*ac), GFP_KERNEL);
> -	input_dev = input_allocate_device();
> -	if (!ac || !input_dev) {
> -		err = -ENOMEM;
> -		goto err_free_mem;
> -	}
> +	ac = devm_kzalloc(dev, sizeof(*ac), GFP_KERNEL);
> +	if (!ac)
> +		return ERR_PTR(-ENOMEM);
> +
> +	input_dev = devm_input_allocate_device(dev);
> +	if (!input_dev)
> +		return ERR_PTR(-ENOMEM);
>  
>  	ac->fifo_delay = fifo_delay_default;
>  
> @@ -754,14 +754,12 @@ struct adxl34x *adxl34x_probe(struct device *dev, int
> irq,
>  		break;
>  	default:
>  		dev_err(dev, "Failed to probe %s\n", input_dev->name);
> -		err = -ENODEV;
> -		goto err_free_mem;
> +		return ERR_PTR(-ENODEV);
>  	}
>  
>  	snprintf(ac->phys, sizeof(ac->phys), "%s/input0", dev_name(dev));
>  
>  	input_dev->phys = ac->phys;
> -	input_dev->dev.parent = dev;
>  	input_dev->id.product = ac->model;
>  	input_dev->id.bustype = bops->bustype;
>  	input_dev->open = adxl34x_input_open;
> @@ -769,18 +767,12 @@ struct adxl34x *adxl34x_probe(struct device *dev, int
> irq,
>  
>  	input_set_drvdata(input_dev, ac);
>  
> -	__set_bit(ac->pdata.ev_type, input_dev->evbit);
> -
>  	if (ac->pdata.ev_type == EV_REL) {
> -		__set_bit(REL_X, input_dev->relbit);
> -		__set_bit(REL_Y, input_dev->relbit);
> -		__set_bit(REL_Z, input_dev->relbit);
> +		input_set_capability(input_dev, EV_REL, REL_X);
> +		input_set_capability(input_dev, EV_REL, REL_Y);
> +		input_set_capability(input_dev, EV_REL, REL_Z);
>  	} else {
>  		/* EV_ABS */
> -		__set_bit(ABS_X, input_dev->absbit);
> -		__set_bit(ABS_Y, input_dev->absbit);
> -		__set_bit(ABS_Z, input_dev->absbit);

Are these somehow default or already set? I guess in input_set_abs_params()...
Anyways, the move from "raw" __set_bits() to input APIs should maybe be done in
a separate patch? They are unrelated with the current one.

- Nuno Sá
diff mbox series

Patch

diff --git a/drivers/input/misc/adxl34x-i2c.c b/drivers/input/misc/adxl34x-i2c.c
index d4014e367c77..7531c7b2d657 100644
--- a/drivers/input/misc/adxl34x-i2c.c
+++ b/drivers/input/misc/adxl34x-i2c.c
@@ -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,
 	},
diff --git a/drivers/input/misc/adxl34x-spi.c b/drivers/input/misc/adxl34x-spi.c
index f1094a8ccdd5..2befcc4df0be 100644
--- a/drivers/input/misc/adxl34x-spi.c
+++ b/drivers/input/misc/adxl34x-spi.c
@@ -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,
diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c
index a3f45e0ee0c7..fbe5a56c19d1 100644
--- a/drivers/input/misc/adxl34x.c
+++ b/drivers/input/misc/adxl34x.c
@@ -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");
diff --git a/drivers/input/misc/adxl34x.h b/drivers/input/misc/adxl34x.h
index f9272a2e7a96..67e0ddc5c3eb 100644
--- a/drivers/input/misc/adxl34x.h
+++ b/drivers/input/misc/adxl34x.h
@@ -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