linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/4] Input: adxl34x - use device core to create driver-specific device attributes
@ 2024-06-10 16:42 Dmitry Torokhov
  2024-06-10 16:42 ` [PATCH v2 2/4] Input: adxl34x - use input_set_capability() Dmitry Torokhov
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Dmitry Torokhov @ 2024-06-10 16:42 UTC (permalink / raw)
  To: linux-input, Nuno Sa; +Cc: Michael Hennerich, linux-kernel

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>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

v2: added Nono's ACK

 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(-)

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
-- 
2.45.2.505.gda0bf45e8d-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/4] Input: adxl34x - use input_set_capability()
  2024-06-10 16:42 [PATCH v2 1/4] Input: adxl34x - use device core to create driver-specific device attributes Dmitry Torokhov
@ 2024-06-10 16:42 ` Dmitry Torokhov
  2024-06-11  9:09   ` Nuno Sá
  2024-06-10 16:42 ` [PATCH v2 3/4] Input: adxl34x - switch to using managed resources Dmitry Torokhov
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2024-06-10 16:42 UTC (permalink / raw)
  To: linux-input, Nuno Sa; +Cc: Michael Hennerich, linux-kernel

Switch to using input_set_capability() instead of using __set_bit() to
make clear what exactly kinds of events (EV_KEY, EV_REL) are being
declared.

Also drop redundant calls setting EV_ABS and ABS_X|Y|Z bits as that is
taken care by input_set_abs_params().

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

v2: new patch, split out from devm conversion at Nino's request

 drivers/input/misc/adxl34x.c | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c
index fbe5a56c19d1..830acf29c32b 100644
--- a/drivers/input/misc/adxl34x.c
+++ b/drivers/input/misc/adxl34x.c
@@ -769,18 +769,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);
-
 		if (pdata->data_range & FULL_RES)
 			range = ADXL_FULLRES_MAX_VAL;	/* Signed 13-bit */
 		else
@@ -791,18 +785,18 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq,
 		input_set_abs_params(input_dev, ABS_Z, -range, range, 3, 3);
 	}
 
-	__set_bit(EV_KEY, input_dev->evbit);
-	__set_bit(pdata->ev_code_tap[ADXL_X_AXIS], input_dev->keybit);
-	__set_bit(pdata->ev_code_tap[ADXL_Y_AXIS], input_dev->keybit);
-	__set_bit(pdata->ev_code_tap[ADXL_Z_AXIS], input_dev->keybit);
+	input_set_capability(input_dev, EV_KEY, pdata->ev_code_tap[ADXL_X_AXIS]);
+	input_set_capability(input_dev, EV_KEY, pdata->ev_code_tap[ADXL_Y_AXIS]);
+	input_set_capability(input_dev, EV_KEY, pdata->ev_code_tap[ADXL_Z_AXIS]);
 
 	if (pdata->ev_code_ff) {
 		ac->int_mask = FREE_FALL;
-		__set_bit(pdata->ev_code_ff, input_dev->keybit);
+		input_set_capability(input_dev, EV_KEY, pdata->ev_code_ff);
 	}
 
 	if (pdata->ev_code_act_inactivity)
-		__set_bit(pdata->ev_code_act_inactivity, input_dev->keybit);
+		input_set_capability(input_dev, EV_KEY,
+				     pdata->ev_code_act_inactivity);
 
 	ac->int_mask |= ACTIVITY | INACTIVITY;
 
@@ -874,13 +868,13 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq,
 
 		if (pdata->orientation_enable & ADXL_EN_ORIENTATION_3D)
 			for (i = 0; i < ARRAY_SIZE(pdata->ev_codes_orient_3d); i++)
-				__set_bit(pdata->ev_codes_orient_3d[i],
-					  input_dev->keybit);
+				input_set_capability(input_dev, EV_KEY,
+						     pdata->ev_codes_orient_3d[i]);
 
 		if (pdata->orientation_enable & ADXL_EN_ORIENTATION_2D)
 			for (i = 0; i < ARRAY_SIZE(pdata->ev_codes_orient_2d); i++)
-				__set_bit(pdata->ev_codes_orient_2d[i],
-					  input_dev->keybit);
+				input_set_capability(input_dev, EV_KEY,
+						     pdata->ev_codes_orient_2d[i]);
 	} else {
 		ac->pdata.orientation_enable = 0;
 	}
-- 
2.45.2.505.gda0bf45e8d-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/4] Input: adxl34x - switch to using managed resources
  2024-06-10 16:42 [PATCH v2 1/4] Input: adxl34x - use device core to create driver-specific device attributes Dmitry Torokhov
  2024-06-10 16:42 ` [PATCH v2 2/4] Input: adxl34x - use input_set_capability() Dmitry Torokhov
@ 2024-06-10 16:42 ` Dmitry Torokhov
  2024-06-11  9:11   ` Nuno Sá
  2024-06-10 16:43 ` [PATCH v2 4/4] Input: adxl34x- switch to using "guard" notation Dmitry Torokhov
  2024-06-11  8:45 ` [PATCH v2 1/4] Input: adxl34x - use device core to create driver-specific device attributes Hennerich, Michael
  3 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2024-06-10 16:42 UTC (permalink / raw)
  To: linux-input, Nuno Sa; +Cc: Michael Hennerich, linux-kernel

Switch the driver to use managed resources to simplify error handling.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

v2: conversion to using input_set_capability() moved to a separate patch

 drivers/input/misc/adxl34x-i2c.c |  8 -----
 drivers/input/misc/adxl34x-spi.c |  8 -----
 drivers/input/misc/adxl34x.c     | 53 ++++++++++----------------------
 drivers/input/misc/adxl34x.h     |  1 -
 4 files changed, 17 insertions(+), 53 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 830acf29c32b..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;
@@ -816,16 +814,16 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq,
 
 	AC_WRITE(ac, POWER_CTL, 0);
 
-	err = request_threaded_irq(ac->irq, NULL, adxl34x_irq,
-				   IRQF_ONESHOT, dev_name(dev), ac);
-	if (err) {
+	error = devm_request_threaded_irq(dev, ac->irq, NULL, adxl34x_irq,
+					  IRQF_ONESHOT, dev_name(dev), ac);
+	if (error) {
 		dev_err(dev, "irq %d busy?\n", ac->irq);
-		goto err_free_mem;
+		return ERR_PTR(error);
 	}
 
-	err = input_register_device(input_dev);
-	if (err)
-		goto err_free_irq;
+	error = input_register_device(input_dev);
+	if (error)
+		return ERR_PTR(error);
 
 	AC_WRITE(ac, OFSX, pdata->x_axis_offset);
 	ac->hwcal.x = pdata->x_axis_offset;
@@ -884,26 +882,9 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq,
 	ac->pdata.power_mode &= (PCTL_AUTO_SLEEP | PCTL_LINK);
 
 	return ac;
-
- err_free_irq:
-	free_irq(ac->irq, ac);
- err_free_mem:
-	input_free_device(input_dev);
-	kfree(ac);
- err_out:
-	return ERR_PTR(err);
 }
 EXPORT_SYMBOL_GPL(adxl34x_probe);
 
-void adxl34x_remove(struct adxl34x *ac)
-{
-	free_irq(ac->irq, ac);
-	input_unregister_device(ac->input);
-	dev_dbg(ac->dev, "unregistered accelerometer\n");
-	kfree(ac);
-}
-EXPORT_SYMBOL_GPL(adxl34x_remove);
-
 EXPORT_GPL_SIMPLE_DEV_PM_OPS(adxl34x_pm, adxl34x_suspend, adxl34x_resume);
 
 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
diff --git a/drivers/input/misc/adxl34x.h b/drivers/input/misc/adxl34x.h
index 67e0ddc5c3eb..718e90c2046d 100644
--- a/drivers/input/misc/adxl34x.h
+++ b/drivers/input/misc/adxl34x.h
@@ -23,7 +23,6 @@ struct adxl34x_bus_ops {
 struct adxl34x *adxl34x_probe(struct device *dev, int irq,
 			      bool fifo_delay_default,
 			      const struct adxl34x_bus_ops *bops);
-void adxl34x_remove(struct adxl34x *ac);
 
 extern const struct dev_pm_ops adxl34x_pm;
 extern const struct attribute_group *adxl34x_groups[];
-- 
2.45.2.505.gda0bf45e8d-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 4/4] Input: adxl34x- switch to using "guard" notation
  2024-06-10 16:42 [PATCH v2 1/4] Input: adxl34x - use device core to create driver-specific device attributes Dmitry Torokhov
  2024-06-10 16:42 ` [PATCH v2 2/4] Input: adxl34x - use input_set_capability() Dmitry Torokhov
  2024-06-10 16:42 ` [PATCH v2 3/4] Input: adxl34x - switch to using managed resources Dmitry Torokhov
@ 2024-06-10 16:43 ` Dmitry Torokhov
  2024-06-11  8:45 ` [PATCH v2 1/4] Input: adxl34x - use device core to create driver-specific device attributes Hennerich, Michael
  3 siblings, 0 replies; 7+ messages in thread
From: Dmitry Torokhov @ 2024-06-10 16:43 UTC (permalink / raw)
  To: linux-input, Nuno Sa; +Cc: Michael Hennerich, linux-kernel

Switch to using guard(mutex)() notation to acquire and automatically
release mutexes.

Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

v2: added Nono's ACK

 drivers/input/misc/adxl34x.c | 61 ++++++++++++------------------------
 1 file changed, 20 insertions(+), 41 deletions(-)

diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c
index c6c34005f5d2..7cafbf8d5f1a 100644
--- a/drivers/input/misc/adxl34x.c
+++ b/drivers/input/misc/adxl34x.c
@@ -241,7 +241,8 @@ static void adxl34x_get_triple(struct adxl34x *ac, struct axis_triple *axis)
 
 	ac->bops->read_block(ac->dev, DATAX0, DATAZ1 - DATAX0 + 1, buf);
 
-	mutex_lock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
+
 	ac->saved.x = (s16) le16_to_cpu(buf[0]);
 	axis->x = ac->saved.x;
 
@@ -250,7 +251,6 @@ static void adxl34x_get_triple(struct adxl34x *ac, struct axis_triple *axis)
 
 	ac->saved.z = (s16) le16_to_cpu(buf[2]);
 	axis->z = ac->saved.z;
-	mutex_unlock(&ac->mutex);
 }
 
 static void adxl34x_service_ev_fifo(struct adxl34x *ac)
@@ -416,15 +416,13 @@ static int adxl34x_suspend(struct device *dev)
 {
 	struct adxl34x *ac = dev_get_drvdata(dev);
 
-	mutex_lock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
 
 	if (!ac->suspended && !ac->disabled && ac->opened)
 		__adxl34x_disable(ac);
 
 	ac->suspended = true;
 
-	mutex_unlock(&ac->mutex);
-
 	return 0;
 }
 
@@ -432,15 +430,13 @@ static int adxl34x_resume(struct device *dev)
 {
 	struct adxl34x *ac = dev_get_drvdata(dev);
 
-	mutex_lock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
 
 	if (ac->suspended && !ac->disabled && ac->opened)
 		__adxl34x_enable(ac);
 
 	ac->suspended = false;
 
-	mutex_unlock(&ac->mutex);
-
 	return 0;
 }
 
@@ -464,7 +460,7 @@ static ssize_t adxl34x_disable_store(struct device *dev,
 	if (error)
 		return error;
 
-	mutex_lock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
 
 	if (!ac->suspended && ac->opened) {
 		if (val) {
@@ -478,8 +474,6 @@ static ssize_t adxl34x_disable_store(struct device *dev,
 
 	ac->disabled = !!val;
 
-	mutex_unlock(&ac->mutex);
-
 	return count;
 }
 
@@ -489,16 +483,13 @@ static ssize_t adxl34x_calibrate_show(struct device *dev,
 				      struct device_attribute *attr, char *buf)
 {
 	struct adxl34x *ac = dev_get_drvdata(dev);
-	ssize_t count;
 
-	mutex_lock(&ac->mutex);
-	count = sprintf(buf, "%d,%d,%d\n",
-			ac->hwcal.x * 4 + ac->swcal.x,
-			ac->hwcal.y * 4 + ac->swcal.y,
-			ac->hwcal.z * 4 + ac->swcal.z);
-	mutex_unlock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
 
-	return count;
+	return sprintf(buf, "%d,%d,%d\n",
+		       ac->hwcal.x * 4 + ac->swcal.x,
+		       ac->hwcal.y * 4 + ac->swcal.y,
+		       ac->hwcal.z * 4 + ac->swcal.z);
 }
 
 static ssize_t adxl34x_calibrate_store(struct device *dev,
@@ -512,7 +503,8 @@ static ssize_t adxl34x_calibrate_store(struct device *dev,
 	 * We use HW calibration and handle the remaining bits in SW. (4mg/LSB)
 	 */
 
-	mutex_lock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
+
 	ac->hwcal.x -= (ac->saved.x / 4);
 	ac->swcal.x = ac->saved.x % 4;
 
@@ -525,7 +517,6 @@ static ssize_t adxl34x_calibrate_store(struct device *dev,
 	AC_WRITE(ac, OFSX, (s8) ac->hwcal.x);
 	AC_WRITE(ac, OFSY, (s8) ac->hwcal.y);
 	AC_WRITE(ac, OFSZ, (s8) ac->hwcal.z);
-	mutex_unlock(&ac->mutex);
 
 	return count;
 }
@@ -553,15 +544,13 @@ static ssize_t adxl34x_rate_store(struct device *dev,
 	if (error)
 		return error;
 
-	mutex_lock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
 
 	ac->pdata.data_rate = RATE(val);
 	AC_WRITE(ac, BW_RATE,
 		 ac->pdata.data_rate |
 			(ac->pdata.low_power_mode ? LOW_POWER : 0));
 
-	mutex_unlock(&ac->mutex);
-
 	return count;
 }
 
@@ -588,7 +577,7 @@ static ssize_t adxl34x_autosleep_store(struct device *dev,
 	if (error)
 		return error;
 
-	mutex_lock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
 
 	if (val)
 		ac->pdata.power_mode |= (PCTL_AUTO_SLEEP | PCTL_LINK);
@@ -598,8 +587,6 @@ static ssize_t adxl34x_autosleep_store(struct device *dev,
 	if (!ac->disabled && !ac->suspended && ac->opened)
 		AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE);
 
-	mutex_unlock(&ac->mutex);
-
 	return count;
 }
 
@@ -610,14 +597,11 @@ static ssize_t adxl34x_position_show(struct device *dev,
 				 struct device_attribute *attr, char *buf)
 {
 	struct adxl34x *ac = dev_get_drvdata(dev);
-	ssize_t count;
 
-	mutex_lock(&ac->mutex);
-	count = sprintf(buf, "(%d, %d, %d)\n",
-			ac->saved.x, ac->saved.y, ac->saved.z);
-	mutex_unlock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
 
-	return count;
+	return sprintf(buf, "(%d, %d, %d)\n",
+		       ac->saved.x, ac->saved.y, ac->saved.z);
 }
 
 static DEVICE_ATTR(position, S_IRUGO, adxl34x_position_show, NULL);
@@ -638,9 +622,8 @@ static ssize_t adxl34x_write_store(struct device *dev,
 	if (error)
 		return error;
 
-	mutex_lock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
 	AC_WRITE(ac, val >> 8, val & 0xFF);
-	mutex_unlock(&ac->mutex);
 
 	return count;
 }
@@ -674,15 +657,13 @@ static int adxl34x_input_open(struct input_dev *input)
 {
 	struct adxl34x *ac = input_get_drvdata(input);
 
-	mutex_lock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
 
 	if (!ac->suspended && !ac->disabled)
 		__adxl34x_enable(ac);
 
 	ac->opened = true;
 
-	mutex_unlock(&ac->mutex);
-
 	return 0;
 }
 
@@ -690,14 +671,12 @@ static void adxl34x_input_close(struct input_dev *input)
 {
 	struct adxl34x *ac = input_get_drvdata(input);
 
-	mutex_lock(&ac->mutex);
+	guard(mutex)(&ac->mutex);
 
 	if (!ac->suspended && !ac->disabled)
 		__adxl34x_disable(ac);
 
 	ac->opened = false;
-
-	mutex_unlock(&ac->mutex);
 }
 
 struct adxl34x *adxl34x_probe(struct device *dev, int irq,
-- 
2.45.2.505.gda0bf45e8d-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* RE: [PATCH v2 1/4] Input: adxl34x - use device core to create driver-specific device attributes
  2024-06-10 16:42 [PATCH v2 1/4] Input: adxl34x - use device core to create driver-specific device attributes Dmitry Torokhov
                   ` (2 preceding siblings ...)
  2024-06-10 16:43 ` [PATCH v2 4/4] Input: adxl34x- switch to using "guard" notation Dmitry Torokhov
@ 2024-06-11  8:45 ` Hennerich, Michael
  3 siblings, 0 replies; 7+ messages in thread
From: Hennerich, Michael @ 2024-06-11  8:45 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input@vger.kernel.org, Sa, Nuno
  Cc: linux-kernel@vger.kernel.org



> -----Original Message-----
> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Sent: Monday, June 10, 2024 6:43 PM
> To: linux-input@vger.kernel.org; Sa, Nuno <Nuno.Sa@analog.com>
> Cc: Hennerich, Michael <Michael.Hennerich@analog.com>; linux-
> kernel@vger.kernel.org
> Subject: [PATCH v2 1/4] Input: adxl34x - use device core to create driver-
> specific device attributes
> 
> 
> 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>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Acked-by: Michael Hennerich <michael.hennerich@analog.com>

> ---
> 
> v2: added Nono's ACK
> 
>  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(-)
> 
> 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
> --
> 2.45.2.505.gda0bf45e8d-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/4] Input: adxl34x - use input_set_capability()
  2024-06-10 16:42 ` [PATCH v2 2/4] Input: adxl34x - use input_set_capability() Dmitry Torokhov
@ 2024-06-11  9:09   ` Nuno Sá
  0 siblings, 0 replies; 7+ messages in thread
From: Nuno Sá @ 2024-06-11  9:09 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, Nuno Sa; +Cc: Michael Hennerich, linux-kernel

On Mon, 2024-06-10 at 09:42 -0700, Dmitry Torokhov wrote:
> Switch to using input_set_capability() instead of using __set_bit() to
> make clear what exactly kinds of events (EV_KEY, EV_REL) are being
> declared.
> 
> Also drop redundant calls setting EV_ABS and ABS_X|Y|Z bits as that is
> taken care by input_set_abs_params().
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---

Reviewed-by: Nuno Sa <nuno.sa@analog.com>

> 
> v2: new patch, split out from devm conversion at Nino's request
> 
>  drivers/input/misc/adxl34x.c | 32 +++++++++++++-------------------
>  1 file changed, 13 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c
> index fbe5a56c19d1..830acf29c32b 100644
> --- a/drivers/input/misc/adxl34x.c
> +++ b/drivers/input/misc/adxl34x.c
> @@ -769,18 +769,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);
> -
>  		if (pdata->data_range & FULL_RES)
>  			range = ADXL_FULLRES_MAX_VAL;	/* Signed 13-bit */
>  		else
> @@ -791,18 +785,18 @@ struct adxl34x *adxl34x_probe(struct device *dev, int
> irq,
>  		input_set_abs_params(input_dev, ABS_Z, -range, range, 3, 3);
>  	}
>  
> -	__set_bit(EV_KEY, input_dev->evbit);
> -	__set_bit(pdata->ev_code_tap[ADXL_X_AXIS], input_dev->keybit);
> -	__set_bit(pdata->ev_code_tap[ADXL_Y_AXIS], input_dev->keybit);
> -	__set_bit(pdata->ev_code_tap[ADXL_Z_AXIS], input_dev->keybit);
> +	input_set_capability(input_dev, EV_KEY, pdata-
> >ev_code_tap[ADXL_X_AXIS]);
> +	input_set_capability(input_dev, EV_KEY, pdata-
> >ev_code_tap[ADXL_Y_AXIS]);
> +	input_set_capability(input_dev, EV_KEY, pdata-
> >ev_code_tap[ADXL_Z_AXIS]);
>  
>  	if (pdata->ev_code_ff) {
>  		ac->int_mask = FREE_FALL;
> -		__set_bit(pdata->ev_code_ff, input_dev->keybit);
> +		input_set_capability(input_dev, EV_KEY, pdata->ev_code_ff);
>  	}
>  
>  	if (pdata->ev_code_act_inactivity)
> -		__set_bit(pdata->ev_code_act_inactivity, input_dev->keybit);
> +		input_set_capability(input_dev, EV_KEY,
> +				     pdata->ev_code_act_inactivity);
>  
>  	ac->int_mask |= ACTIVITY | INACTIVITY;
>  
> @@ -874,13 +868,13 @@ struct adxl34x *adxl34x_probe(struct device *dev, int
> irq,
>  
>  		if (pdata->orientation_enable & ADXL_EN_ORIENTATION_3D)
>  			for (i = 0; i < ARRAY_SIZE(pdata-
> >ev_codes_orient_3d); i++)
> -				__set_bit(pdata->ev_codes_orient_3d[i],
> -					  input_dev->keybit);
> +				input_set_capability(input_dev, EV_KEY,
> +						     pdata-
> >ev_codes_orient_3d[i]);
>  
>  		if (pdata->orientation_enable & ADXL_EN_ORIENTATION_2D)
>  			for (i = 0; i < ARRAY_SIZE(pdata-
> >ev_codes_orient_2d); i++)
> -				__set_bit(pdata->ev_codes_orient_2d[i],
> -					  input_dev->keybit);
> +				input_set_capability(input_dev, EV_KEY,
> +						     pdata-
> >ev_codes_orient_2d[i]);
>  	} else {
>  		ac->pdata.orientation_enable = 0;
>  	}


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 3/4] Input: adxl34x - switch to using managed resources
  2024-06-10 16:42 ` [PATCH v2 3/4] Input: adxl34x - switch to using managed resources Dmitry Torokhov
@ 2024-06-11  9:11   ` Nuno Sá
  0 siblings, 0 replies; 7+ messages in thread
From: Nuno Sá @ 2024-06-11  9:11 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, Nuno Sa; +Cc: Michael Hennerich, linux-kernel

On Mon, 2024-06-10 at 09:42 -0700, Dmitry Torokhov wrote:
> Switch the driver to use managed resources to simplify error handling.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---

Reviewed-by: Nuno Sa <nuno.sa@analog.com>



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-06-11  9:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-10 16:42 [PATCH v2 1/4] Input: adxl34x - use device core to create driver-specific device attributes Dmitry Torokhov
2024-06-10 16:42 ` [PATCH v2 2/4] Input: adxl34x - use input_set_capability() Dmitry Torokhov
2024-06-11  9:09   ` Nuno Sá
2024-06-10 16:42 ` [PATCH v2 3/4] Input: adxl34x - switch to using managed resources Dmitry Torokhov
2024-06-11  9:11   ` Nuno Sá
2024-06-10 16:43 ` [PATCH v2 4/4] Input: adxl34x- switch to using "guard" notation Dmitry Torokhov
2024-06-11  8:45 ` [PATCH v2 1/4] Input: adxl34x - use device core to create driver-specific device attributes Hennerich, Michael

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).