All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/23] counter: cleanups and device lifetime fixes
@ 2021-12-27  9:45 ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Patrick Havelange,
	Kamel Bouhara, linux-arm-kernel, Syed Nayyar Waris,
	Oleksij Rempel, Jarkko Nikula, David Lechner, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, linux-stm32, Jonathan Corbet,
	linux-doc, Ahmad Fatoum, Felipe Balbi (Intel),
	Raymond Tan, Benjamin Gaignard

Hello,

this is v2 of this series, it's goal is to fix struct device lifetime issues as
pointed out in patch #13. The patches up to patch #12 are only prepatory and
cleanup patches. Patch #13 provides the needed functions to fix the issues in
all drivers (patches #15 to #22). The last patch removes the then unused API
calls.

The changes compared to v1 is only build fixes that I missed to include in v1,
they were only in my working copy. Additionally I changed:

diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
index cdc6004a7e77..3f7dc5718423 100644
--- a/drivers/counter/counter-core.c
+++ b/drivers/counter/counter-core.c
@@ -27,7 +27,7 @@ static DEFINE_IDA(counter_ida);
 
 struct counter_device_allochelper {
 	struct counter_device counter;
-	unsigned long privdata[0];
+	unsigned long privdata[];
 };
 
 static void counter_device_release(struct device *dev)

The stm32-timer-cnt driver was used to test
this series, the other drivers are only compile tested.


To complete the information from the v1 thread: There are a few more
issues I found while working on this patch set:

 - 104_QUAD_8 depends on X86, but compiles fine on ARCH=arm. Maybe
   adding support for COMPILE_TEST would be a good idea.

 - 104-quad-8.c uses devm_request_irq() and (now) devm_counter_add(). On
   unbind an irq might be pending which results in quad8_irq_handler()
   calling counter_push_event() for a counter that is already
   unregistered. (The issue exists also without my changes.)

 - I think intel-qep.c makes the counter unfunctional in
   intel_qep_remove before the counter is unregistered.

 - I wonder why counter is a bus and not a class device type. There is
   no driver that would ever bind a counter device, is there? So
   /sys/bus/counter/driver is always empty.

Do whatever you want with this list, I won't address these in the near
future.

Uwe Kleine-König (23):
  counter: Use container_of instead of drvdata to track counter_device
  counter: ftm-quaddec: Drop unused platform_set_drvdata()
  counter: microchip-tcb-capture: Drop unused platform_set_drvdata()
  counter: Provide a wrapper to access device private data
  counter: 104-quad-8: Convert to counter_priv() wrapper
  counter: interrupt-cnt: Convert to counter_priv() wrapper
  counter: microchip-tcb-capture: Convert to counter_priv() wrapper
  counter: intel-qep: Convert to counter_priv() wrapper
  counter: ftm-quaddec: Convert to counter_priv() wrapper
  counter: ti-eqep: Convert to counter_priv() wrapper
  counter: stm32-lptimer-cnt: Convert to counter_priv() wrapper
  counter: stm32-timer-cnt: Convert to counter_priv() wrapper
  counter: Provide alternative counter registration functions
  counter: Update documentation for new counter registration functions
  counter: 104-quad-8: Convert to new counter registration
  counter: interrupt-cnt: Convert to new counter registration
  counter: intel-qep: Convert to new counter registration
  counter: ftm-quaddec: Convert to new counter registration
  counter: microchip-tcb-capture: Convert to new counter registration
  counter: stm32-timer-cnt: Convert to new counter registration
  counter: stm32-lptimer-cnt: Convert to new counter registration
  counter: ti-eqep: Convert to new counter registration
  counter: remove old and now unused registration API

 Documentation/driver-api/generic-counter.rst |  10 +-
 drivers/counter/104-quad-8.c                 |  93 +++++-----
 drivers/counter/counter-core.c               | 168 +++++++++++++------
 drivers/counter/ftm-quaddec.c                |  37 ++--
 drivers/counter/intel-qep.c                  |  46 ++---
 drivers/counter/interrupt-cnt.c              |  38 +++--
 drivers/counter/microchip-tcb-capture.c      |  44 ++---
 drivers/counter/stm32-lptimer-cnt.c          |  51 +++---
 drivers/counter/stm32-timer-cnt.c            |  48 +++---
 drivers/counter/ti-eqep.c                    |  47 +++---
 include/linux/counter.h                      |  15 +-
 11 files changed, 348 insertions(+), 249 deletions(-)


base-commit: a7904a538933c525096ca2ccde1e60d0ee62c08e
-- 
2.33.0


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

* [PATCH v2 00/23] counter: cleanups and device lifetime fixes
@ 2021-12-27  9:45 ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Patrick Havelange,
	Kamel Bouhara, linux-arm-kernel, Syed Nayyar Waris,
	Oleksij Rempel, Jarkko Nikula, David Lechner, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, linux-stm32, Jonathan Corbet,
	linux-doc, Ahmad Fatoum, Felipe Balbi (Intel),
	Raymond Tan, Benjamin Gaignard

Hello,

this is v2 of this series, it's goal is to fix struct device lifetime issues as
pointed out in patch #13. The patches up to patch #12 are only prepatory and
cleanup patches. Patch #13 provides the needed functions to fix the issues in
all drivers (patches #15 to #22). The last patch removes the then unused API
calls.

The changes compared to v1 is only build fixes that I missed to include in v1,
they were only in my working copy. Additionally I changed:

diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
index cdc6004a7e77..3f7dc5718423 100644
--- a/drivers/counter/counter-core.c
+++ b/drivers/counter/counter-core.c
@@ -27,7 +27,7 @@ static DEFINE_IDA(counter_ida);
 
 struct counter_device_allochelper {
 	struct counter_device counter;
-	unsigned long privdata[0];
+	unsigned long privdata[];
 };
 
 static void counter_device_release(struct device *dev)

The stm32-timer-cnt driver was used to test
this series, the other drivers are only compile tested.


To complete the information from the v1 thread: There are a few more
issues I found while working on this patch set:

 - 104_QUAD_8 depends on X86, but compiles fine on ARCH=arm. Maybe
   adding support for COMPILE_TEST would be a good idea.

 - 104-quad-8.c uses devm_request_irq() and (now) devm_counter_add(). On
   unbind an irq might be pending which results in quad8_irq_handler()
   calling counter_push_event() for a counter that is already
   unregistered. (The issue exists also without my changes.)

 - I think intel-qep.c makes the counter unfunctional in
   intel_qep_remove before the counter is unregistered.

 - I wonder why counter is a bus and not a class device type. There is
   no driver that would ever bind a counter device, is there? So
   /sys/bus/counter/driver is always empty.

Do whatever you want with this list, I won't address these in the near
future.

Uwe Kleine-König (23):
  counter: Use container_of instead of drvdata to track counter_device
  counter: ftm-quaddec: Drop unused platform_set_drvdata()
  counter: microchip-tcb-capture: Drop unused platform_set_drvdata()
  counter: Provide a wrapper to access device private data
  counter: 104-quad-8: Convert to counter_priv() wrapper
  counter: interrupt-cnt: Convert to counter_priv() wrapper
  counter: microchip-tcb-capture: Convert to counter_priv() wrapper
  counter: intel-qep: Convert to counter_priv() wrapper
  counter: ftm-quaddec: Convert to counter_priv() wrapper
  counter: ti-eqep: Convert to counter_priv() wrapper
  counter: stm32-lptimer-cnt: Convert to counter_priv() wrapper
  counter: stm32-timer-cnt: Convert to counter_priv() wrapper
  counter: Provide alternative counter registration functions
  counter: Update documentation for new counter registration functions
  counter: 104-quad-8: Convert to new counter registration
  counter: interrupt-cnt: Convert to new counter registration
  counter: intel-qep: Convert to new counter registration
  counter: ftm-quaddec: Convert to new counter registration
  counter: microchip-tcb-capture: Convert to new counter registration
  counter: stm32-timer-cnt: Convert to new counter registration
  counter: stm32-lptimer-cnt: Convert to new counter registration
  counter: ti-eqep: Convert to new counter registration
  counter: remove old and now unused registration API

 Documentation/driver-api/generic-counter.rst |  10 +-
 drivers/counter/104-quad-8.c                 |  93 +++++-----
 drivers/counter/counter-core.c               | 168 +++++++++++++------
 drivers/counter/ftm-quaddec.c                |  37 ++--
 drivers/counter/intel-qep.c                  |  46 ++---
 drivers/counter/interrupt-cnt.c              |  38 +++--
 drivers/counter/microchip-tcb-capture.c      |  44 ++---
 drivers/counter/stm32-lptimer-cnt.c          |  51 +++---
 drivers/counter/stm32-timer-cnt.c            |  48 +++---
 drivers/counter/ti-eqep.c                    |  47 +++---
 include/linux/counter.h                      |  15 +-
 11 files changed, 348 insertions(+), 249 deletions(-)


base-commit: a7904a538933c525096ca2ccde1e60d0ee62c08e
-- 
2.33.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 01/23] counter: Use container_of instead of drvdata to track counter_device
  2021-12-27  9:45 ` Uwe Kleine-König
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 17:14   ` Jonathan Cameron
  2021-12-29  6:38   ` William Breathitt Gray
  -1 siblings, 2 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel

The counter core uses drvdata to find a struct counter_device from a
struct device. However as the device is a member of struct counter_device,
the lookup can be done faster (and a bit type safe) using container_of.

There are no other users of drvdata, so the call to dev_set_drvdata can
go away, too.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/counter-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
index 5acc54539623..f053a43c6c04 100644
--- a/drivers/counter/counter-core.c
+++ b/drivers/counter/counter-core.c
@@ -26,7 +26,8 @@ static DEFINE_IDA(counter_ida);
 
 static void counter_device_release(struct device *dev)
 {
-	struct counter_device *const counter = dev_get_drvdata(dev);
+	struct counter_device *const counter =
+		container_of(dev, struct counter_device, dev);
 
 	counter_chrdev_remove(counter);
 	ida_free(&counter_ida, dev->id);
@@ -78,7 +79,6 @@ int counter_register(struct counter_device *const counter)
 		dev->of_node = counter->parent->of_node;
 	}
 	device_initialize(dev);
-	dev_set_drvdata(dev, counter);
 
 	err = counter_sysfs_add(counter);
 	if (err < 0)
-- 
2.33.0


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

* [PATCH v2 02/23] counter: ftm-quaddec: Drop unused platform_set_drvdata()
  2021-12-27  9:45 ` Uwe Kleine-König
  (?)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 17:37   ` Jonathan Cameron
  2021-12-29  6:42   ` William Breathitt Gray
  -1 siblings, 2 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Patrick Havelange,
	Syed Nayyar Waris

The driver doesn't ever use platform_get_drvdata, so drop this unused
call.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/ftm-quaddec.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
index 5ef0478709cd..9272f7b58beb 100644
--- a/drivers/counter/ftm-quaddec.c
+++ b/drivers/counter/ftm-quaddec.c
@@ -269,8 +269,6 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
 	if (!ftm)
 		return -ENOMEM;
 
-	platform_set_drvdata(pdev, ftm);
-
 	io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!io) {
 		dev_err(&pdev->dev, "Failed to get memory region\n");
-- 
2.33.0


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

* [PATCH v2 03/23] counter: microchip-tcb-capture: Drop unused platform_set_drvdata()
  2021-12-27  9:45 ` Uwe Kleine-König
@ 2021-12-27  9:45   ` Uwe Kleine-König
  -1 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Kamel Bouhara,
	linux-arm-kernel

The driver doesn't ever use platform_get_drvdata, so drop this unused
call.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/microchip-tcb-capture.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
index 0ab1b2716784..bb69f2e0ba93 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -307,8 +307,6 @@ static int mchp_tc_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
-	platform_set_drvdata(pdev, priv);
-
 	match = of_match_node(atmel_tc_of_match, np->parent);
 	tcb_config = match->data;
 	if (!tcb_config) {
-- 
2.33.0


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

* [PATCH v2 03/23] counter: microchip-tcb-capture: Drop unused platform_set_drvdata()
@ 2021-12-27  9:45   ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Kamel Bouhara,
	linux-arm-kernel

The driver doesn't ever use platform_get_drvdata, so drop this unused
call.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/microchip-tcb-capture.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
index 0ab1b2716784..bb69f2e0ba93 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -307,8 +307,6 @@ static int mchp_tc_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
-	platform_set_drvdata(pdev, priv);
-
 	match = of_match_node(atmel_tc_of_match, np->parent);
 	tcb_config = match->data;
 	if (!tcb_config) {
-- 
2.33.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 04/23] counter: Provide a wrapper to access device private data
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (3 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-27 11:02   ` Greg Kroah-Hartman
                     ` (2 more replies)
  -1 siblings, 3 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel

For now this just wraps accessing struct counter_device::priv. However
this is about to change and converting drivers to this helper
individually makes fixing device lifetime issues result in easier to
review patches.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/counter-core.c | 12 ++++++++++++
 include/linux/counter.h        |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
index f053a43c6c04..00c41f28c101 100644
--- a/drivers/counter/counter-core.c
+++ b/drivers/counter/counter-core.c
@@ -45,6 +45,18 @@ static struct bus_type counter_bus_type = {
 
 static dev_t counter_devt;
 
+/**
+ * counter_priv - access counter device private data
+ * @counter: counter device
+ *
+ * Get the counter device private data
+ */
+void *counter_priv(const struct counter_device *const counter)
+{
+	return counter->priv;
+}
+EXPORT_SYMBOL_GPL(counter_priv);
+
 /**
  * counter_register - register Counter to the system
  * @counter:	pointer to Counter to register
diff --git a/include/linux/counter.h b/include/linux/counter.h
index b7d0a00a61cf..8daaa38c71d8 100644
--- a/include/linux/counter.h
+++ b/include/linux/counter.h
@@ -329,6 +329,8 @@ struct counter_device {
 	struct mutex ops_exist_lock;
 };
 
+void *counter_priv(const struct counter_device *const counter);
+
 int counter_register(struct counter_device *const counter);
 void counter_unregister(struct counter_device *const counter);
 int devm_counter_register(struct device *dev,
-- 
2.33.0


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

* [PATCH v2 05/23] counter: 104-quad-8: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (4 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 18:02   ` Jonathan Cameron
  2021-12-29  7:27   ` William Breathitt Gray
  -1 siblings, 2 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Syed Nayyar Waris

This is a straight forward conversion to the new counter_priv() wrapper.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/104-quad-8.c | 58 ++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 1cbd60aaed69..6e5286cd1d4e 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -113,7 +113,7 @@ static int quad8_signal_read(struct counter_device *counter,
 			     struct counter_signal *signal,
 			     enum counter_signal_level *level)
 {
-	const struct quad8 *const priv = counter->priv;
+	const struct quad8 *const priv = counter_priv(counter);
 	unsigned int state;
 
 	/* Only Index signal levels can be read */
@@ -131,7 +131,7 @@ static int quad8_signal_read(struct counter_device *counter,
 static int quad8_count_read(struct counter_device *counter,
 			    struct counter_count *count, u64 *val)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	const int base_offset = priv->base + 2 * count->id;
 	unsigned int flags;
 	unsigned int borrow;
@@ -163,7 +163,7 @@ static int quad8_count_read(struct counter_device *counter,
 static int quad8_count_write(struct counter_device *counter,
 			     struct counter_count *count, u64 val)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	const int base_offset = priv->base + 2 * count->id;
 	unsigned long irqflags;
 	int i;
@@ -213,7 +213,7 @@ static int quad8_function_read(struct counter_device *counter,
 			       struct counter_count *count,
 			       enum counter_function *function)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	const int id = count->id;
 	unsigned long irqflags;
 
@@ -243,7 +243,7 @@ static int quad8_function_write(struct counter_device *counter,
 				struct counter_count *count,
 				enum counter_function function)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	const int id = count->id;
 	unsigned int *const quadrature_mode = priv->quadrature_mode + id;
 	unsigned int *const scale = priv->quadrature_scale + id;
@@ -305,7 +305,7 @@ static int quad8_direction_read(struct counter_device *counter,
 				struct counter_count *count,
 				enum counter_count_direction *direction)
 {
-	const struct quad8 *const priv = counter->priv;
+	const struct quad8 *const priv = counter_priv(counter);
 	unsigned int ud_flag;
 	const unsigned int flag_addr = priv->base + 2 * count->id + 1;
 
@@ -335,7 +335,7 @@ static int quad8_action_read(struct counter_device *counter,
 			     struct counter_synapse *synapse,
 			     enum counter_synapse_action *action)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	int err;
 	enum counter_function function;
 	const size_t signal_a_id = count->synapses[0].signal->id;
@@ -399,7 +399,7 @@ enum {
 
 static int quad8_events_configure(struct counter_device *counter)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	unsigned long irq_enabled = 0;
 	unsigned long irqflags;
 	size_t channel;
@@ -442,7 +442,7 @@ static int quad8_events_configure(struct counter_device *counter)
 static int quad8_watch_validate(struct counter_device *counter,
 				const struct counter_watch *watch)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 
 	if (watch->channel > QUAD8_NUM_COUNTERS - 1)
 		return -EINVAL;
@@ -497,7 +497,7 @@ static int quad8_index_polarity_get(struct counter_device *counter,
 				    struct counter_signal *signal,
 				    u32 *index_polarity)
 {
-	const struct quad8 *const priv = counter->priv;
+	const struct quad8 *const priv = counter_priv(counter);
 	const size_t channel_id = signal->id - 16;
 
 	*index_polarity = priv->index_polarity[channel_id];
@@ -509,7 +509,7 @@ static int quad8_index_polarity_set(struct counter_device *counter,
 				    struct counter_signal *signal,
 				    u32 index_polarity)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	const size_t channel_id = signal->id - 16;
 	const int base_offset = priv->base + 2 * channel_id + 1;
 	unsigned long irqflags;
@@ -538,7 +538,7 @@ static int quad8_synchronous_mode_get(struct counter_device *counter,
 				      struct counter_signal *signal,
 				      u32 *synchronous_mode)
 {
-	const struct quad8 *const priv = counter->priv;
+	const struct quad8 *const priv = counter_priv(counter);
 	const size_t channel_id = signal->id - 16;
 
 	*synchronous_mode = priv->synchronous_mode[channel_id];
@@ -550,7 +550,7 @@ static int quad8_synchronous_mode_set(struct counter_device *counter,
 				      struct counter_signal *signal,
 				      u32 synchronous_mode)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	const size_t channel_id = signal->id - 16;
 	const int base_offset = priv->base + 2 * channel_id + 1;
 	unsigned long irqflags;
@@ -589,7 +589,7 @@ static int quad8_count_mode_read(struct counter_device *counter,
 				 struct counter_count *count,
 				 enum counter_count_mode *cnt_mode)
 {
-	const struct quad8 *const priv = counter->priv;
+	const struct quad8 *const priv = counter_priv(counter);
 
 	/* Map 104-QUAD-8 count mode to Generic Counter count mode */
 	switch (priv->count_mode[count->id]) {
@@ -614,7 +614,7 @@ static int quad8_count_mode_write(struct counter_device *counter,
 				  struct counter_count *count,
 				  enum counter_count_mode cnt_mode)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	unsigned int count_mode;
 	unsigned int mode_cfg;
 	const int base_offset = priv->base + 2 * count->id + 1;
@@ -661,7 +661,7 @@ static int quad8_count_mode_write(struct counter_device *counter,
 static int quad8_count_enable_read(struct counter_device *counter,
 				   struct counter_count *count, u8 *enable)
 {
-	const struct quad8 *const priv = counter->priv;
+	const struct quad8 *const priv = counter_priv(counter);
 
 	*enable = priv->ab_enable[count->id];
 
@@ -671,7 +671,7 @@ static int quad8_count_enable_read(struct counter_device *counter,
 static int quad8_count_enable_write(struct counter_device *counter,
 				    struct counter_count *count, u8 enable)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	const int base_offset = priv->base + 2 * count->id;
 	unsigned long irqflags;
 	unsigned int ior_cfg;
@@ -699,7 +699,7 @@ static const char *const quad8_noise_error_states[] = {
 static int quad8_error_noise_get(struct counter_device *counter,
 				 struct counter_count *count, u32 *noise_error)
 {
-	const struct quad8 *const priv = counter->priv;
+	const struct quad8 *const priv = counter_priv(counter);
 	const int base_offset = priv->base + 2 * count->id + 1;
 
 	*noise_error = !!(inb(base_offset) & QUAD8_FLAG_E);
@@ -710,7 +710,7 @@ static int quad8_error_noise_get(struct counter_device *counter,
 static int quad8_count_preset_read(struct counter_device *counter,
 				   struct counter_count *count, u64 *preset)
 {
-	const struct quad8 *const priv = counter->priv;
+	const struct quad8 *const priv = counter_priv(counter);
 
 	*preset = priv->preset[count->id];
 
@@ -736,7 +736,7 @@ static void quad8_preset_register_set(struct quad8 *const priv, const int id,
 static int quad8_count_preset_write(struct counter_device *counter,
 				    struct counter_count *count, u64 preset)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	unsigned long irqflags;
 
 	/* Only 24-bit values are supported */
@@ -755,7 +755,7 @@ static int quad8_count_preset_write(struct counter_device *counter,
 static int quad8_count_ceiling_read(struct counter_device *counter,
 				    struct counter_count *count, u64 *ceiling)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	unsigned long irqflags;
 
 	spin_lock_irqsave(&priv->lock, irqflags);
@@ -780,7 +780,7 @@ static int quad8_count_ceiling_read(struct counter_device *counter,
 static int quad8_count_ceiling_write(struct counter_device *counter,
 				     struct counter_count *count, u64 ceiling)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	unsigned long irqflags;
 
 	/* Only 24-bit values are supported */
@@ -807,7 +807,7 @@ static int quad8_count_preset_enable_read(struct counter_device *counter,
 					  struct counter_count *count,
 					  u8 *preset_enable)
 {
-	const struct quad8 *const priv = counter->priv;
+	const struct quad8 *const priv = counter_priv(counter);
 
 	*preset_enable = !priv->preset_enable[count->id];
 
@@ -818,7 +818,7 @@ static int quad8_count_preset_enable_write(struct counter_device *counter,
 					   struct counter_count *count,
 					   u8 preset_enable)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	const int base_offset = priv->base + 2 * count->id + 1;
 	unsigned long irqflags;
 	unsigned int ior_cfg;
@@ -845,7 +845,7 @@ static int quad8_signal_cable_fault_read(struct counter_device *counter,
 					 struct counter_signal *signal,
 					 u8 *cable_fault)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	const size_t channel_id = signal->id / 2;
 	unsigned long irqflags;
 	bool disabled;
@@ -875,7 +875,7 @@ static int quad8_signal_cable_fault_enable_read(struct counter_device *counter,
 						struct counter_signal *signal,
 						u8 *enable)
 {
-	const struct quad8 *const priv = counter->priv;
+	const struct quad8 *const priv = counter_priv(counter);
 	const size_t channel_id = signal->id / 2;
 
 	*enable = !!(priv->cable_fault_enable & BIT(channel_id));
@@ -887,7 +887,7 @@ static int quad8_signal_cable_fault_enable_write(struct counter_device *counter,
 						 struct counter_signal *signal,
 						 u8 enable)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	const size_t channel_id = signal->id / 2;
 	unsigned long irqflags;
 	unsigned int cable_fault_enable;
@@ -913,7 +913,7 @@ static int quad8_signal_fck_prescaler_read(struct counter_device *counter,
 					   struct counter_signal *signal,
 					   u8 *prescaler)
 {
-	const struct quad8 *const priv = counter->priv;
+	const struct quad8 *const priv = counter_priv(counter);
 
 	*prescaler = priv->fck_prescaler[signal->id / 2];
 
@@ -924,7 +924,7 @@ static int quad8_signal_fck_prescaler_write(struct counter_device *counter,
 					    struct counter_signal *signal,
 					    u8 prescaler)
 {
-	struct quad8 *const priv = counter->priv;
+	struct quad8 *const priv = counter_priv(counter);
 	const size_t channel_id = signal->id / 2;
 	const int base_offset = priv->base + 2 * channel_id;
 	unsigned long irqflags;
-- 
2.33.0


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

* [PATCH v2 06/23] counter: interrupt-cnt: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (5 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 18:04   ` Jonathan Cameron
  2021-12-29  7:34   ` William Breathitt Gray
  -1 siblings, 2 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Oleksij Rempel, Ahmad Fatoum

This is a straight forward conversion to the new counter_priv() wrapper.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/interrupt-cnt.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c
index 8514a87fcbee..4bf706ef46e2 100644
--- a/drivers/counter/interrupt-cnt.c
+++ b/drivers/counter/interrupt-cnt.c
@@ -37,7 +37,7 @@ static irqreturn_t interrupt_cnt_isr(int irq, void *dev_id)
 static int interrupt_cnt_enable_read(struct counter_device *counter,
 				     struct counter_count *count, u8 *enable)
 {
-	struct interrupt_cnt_priv *priv = counter->priv;
+	struct interrupt_cnt_priv *priv = counter_priv(counter);
 
 	*enable = priv->enabled;
 
@@ -47,7 +47,7 @@ static int interrupt_cnt_enable_read(struct counter_device *counter,
 static int interrupt_cnt_enable_write(struct counter_device *counter,
 				      struct counter_count *count, u8 enable)
 {
-	struct interrupt_cnt_priv *priv = counter->priv;
+	struct interrupt_cnt_priv *priv = counter_priv(counter);
 
 	if (priv->enabled == enable)
 		return 0;
@@ -85,7 +85,7 @@ static int interrupt_cnt_action_read(struct counter_device *counter,
 static int interrupt_cnt_read(struct counter_device *counter,
 			      struct counter_count *count, u64 *val)
 {
-	struct interrupt_cnt_priv *priv = counter->priv;
+	struct interrupt_cnt_priv *priv = counter_priv(counter);
 
 	*val = atomic_read(&priv->count);
 
@@ -95,7 +95,7 @@ static int interrupt_cnt_read(struct counter_device *counter,
 static int interrupt_cnt_write(struct counter_device *counter,
 			       struct counter_count *count, const u64 val)
 {
-	struct interrupt_cnt_priv *priv = counter->priv;
+	struct interrupt_cnt_priv *priv = counter_priv(counter);
 
 	if (val != (typeof(priv->count.counter))val)
 		return -ERANGE;
@@ -122,7 +122,7 @@ static int interrupt_cnt_signal_read(struct counter_device *counter,
 				     struct counter_signal *signal,
 				     enum counter_signal_level *level)
 {
-	struct interrupt_cnt_priv *priv = counter->priv;
+	struct interrupt_cnt_priv *priv = counter_priv(counter);
 	int ret;
 
 	if (!priv->gpio)
-- 
2.33.0


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

* [PATCH v2 07/23] counter: microchip-tcb-capture: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` Uwe Kleine-König
@ 2021-12-27  9:45   ` Uwe Kleine-König
  -1 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Kamel Bouhara,
	linux-arm-kernel

This is a straight forward conversion to the new counter_priv() wrapper.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/microchip-tcb-capture.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
index bb69f2e0ba93..1b56b7444668 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -72,7 +72,7 @@ static int mchp_tc_count_function_read(struct counter_device *counter,
 				       struct counter_count *count,
 				       enum counter_function *function)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 
 	if (priv->qdec_mode)
 		*function = COUNTER_FUNCTION_QUADRATURE_X4;
@@ -86,7 +86,7 @@ static int mchp_tc_count_function_write(struct counter_device *counter,
 					struct counter_count *count,
 					enum counter_function function)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 	u32 bmr, cmr;
 
 	regmap_read(priv->regmap, ATMEL_TC_BMR, &bmr);
@@ -148,7 +148,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter,
 				     struct counter_signal *signal,
 				     enum counter_signal_level *lvl)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 	bool sigstatus;
 	u32 sr;
 
@@ -169,7 +169,7 @@ static int mchp_tc_count_action_read(struct counter_device *counter,
 				     struct counter_synapse *synapse,
 				     enum counter_synapse_action *action)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 	u32 cmr;
 
 	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
@@ -197,7 +197,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
 				      struct counter_synapse *synapse,
 				      enum counter_synapse_action action)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 	u32 edge = ATMEL_TC_ETRGEDG_NONE;
 
 	/* QDEC mode is rising edge only */
@@ -230,7 +230,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
 static int mchp_tc_count_read(struct counter_device *counter,
 			      struct counter_count *count, u64 *val)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 	u32 cnt;
 
 	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CV), &cnt);
-- 
2.33.0


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

* [PATCH v2 07/23] counter: microchip-tcb-capture: Convert to counter_priv() wrapper
@ 2021-12-27  9:45   ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Kamel Bouhara,
	linux-arm-kernel

This is a straight forward conversion to the new counter_priv() wrapper.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/microchip-tcb-capture.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
index bb69f2e0ba93..1b56b7444668 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -72,7 +72,7 @@ static int mchp_tc_count_function_read(struct counter_device *counter,
 				       struct counter_count *count,
 				       enum counter_function *function)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 
 	if (priv->qdec_mode)
 		*function = COUNTER_FUNCTION_QUADRATURE_X4;
@@ -86,7 +86,7 @@ static int mchp_tc_count_function_write(struct counter_device *counter,
 					struct counter_count *count,
 					enum counter_function function)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 	u32 bmr, cmr;
 
 	regmap_read(priv->regmap, ATMEL_TC_BMR, &bmr);
@@ -148,7 +148,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter,
 				     struct counter_signal *signal,
 				     enum counter_signal_level *lvl)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 	bool sigstatus;
 	u32 sr;
 
@@ -169,7 +169,7 @@ static int mchp_tc_count_action_read(struct counter_device *counter,
 				     struct counter_synapse *synapse,
 				     enum counter_synapse_action *action)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 	u32 cmr;
 
 	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
@@ -197,7 +197,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
 				      struct counter_synapse *synapse,
 				      enum counter_synapse_action action)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 	u32 edge = ATMEL_TC_ETRGEDG_NONE;
 
 	/* QDEC mode is rising edge only */
@@ -230,7 +230,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
 static int mchp_tc_count_read(struct counter_device *counter,
 			      struct counter_count *count, u64 *val)
 {
-	struct mchp_tc_data *const priv = counter->priv;
+	struct mchp_tc_data *const priv = counter_priv(counter);
 	u32 cnt;
 
 	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CV), &cnt);
-- 
2.33.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 08/23] counter: intel-qep: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (7 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 18:06   ` Jonathan Cameron
                     ` (2 more replies)
  -1 siblings, 3 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Jarkko Nikula,
	Felipe Balbi (Intel),
	Raymond Tan

This is a straight forward conversion to the new counter_priv() wrapper.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/intel-qep.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c
index 0924d16de6e2..8f84a48508ac 100644
--- a/drivers/counter/intel-qep.c
+++ b/drivers/counter/intel-qep.c
@@ -109,7 +109,7 @@ static void intel_qep_init(struct intel_qep *qep)
 static int intel_qep_count_read(struct counter_device *counter,
 				struct counter_count *count, u64 *val)
 {
-	struct intel_qep *const qep = counter->priv;
+	struct intel_qep *const qep = counter_priv(counter);
 
 	pm_runtime_get_sync(qep->dev);
 	*val = intel_qep_readl(qep, INTEL_QEPCOUNT);
@@ -176,7 +176,7 @@ static struct counter_synapse intel_qep_count_synapses[] = {
 static int intel_qep_ceiling_read(struct counter_device *counter,
 				  struct counter_count *count, u64 *ceiling)
 {
-	struct intel_qep *qep = counter->priv;
+	struct intel_qep *qep = counter_priv(counter);
 
 	pm_runtime_get_sync(qep->dev);
 	*ceiling = intel_qep_readl(qep, INTEL_QEPMAX);
@@ -188,7 +188,7 @@ static int intel_qep_ceiling_read(struct counter_device *counter,
 static int intel_qep_ceiling_write(struct counter_device *counter,
 				   struct counter_count *count, u64 max)
 {
-	struct intel_qep *qep = counter->priv;
+	struct intel_qep *qep = counter_priv(counter);
 	int ret = 0;
 
 	/* Intel QEP ceiling configuration only supports 32-bit values */
@@ -213,7 +213,7 @@ static int intel_qep_ceiling_write(struct counter_device *counter,
 static int intel_qep_enable_read(struct counter_device *counter,
 				 struct counter_count *count, u8 *enable)
 {
-	struct intel_qep *qep = counter->priv;
+	struct intel_qep *qep = counter_priv(counter);
 
 	*enable = qep->enabled;
 
@@ -223,7 +223,7 @@ static int intel_qep_enable_read(struct counter_device *counter,
 static int intel_qep_enable_write(struct counter_device *counter,
 				  struct counter_count *count, u8 val)
 {
-	struct intel_qep *qep = counter->priv;
+	struct intel_qep *qep = counter_priv(counter);
 	u32 reg;
 	bool changed;
 
@@ -256,7 +256,7 @@ static int intel_qep_spike_filter_ns_read(struct counter_device *counter,
 					  struct counter_count *count,
 					  u64 *length)
 {
-	struct intel_qep *qep = counter->priv;
+	struct intel_qep *qep = counter_priv(counter);
 	u32 reg;
 
 	pm_runtime_get_sync(qep->dev);
@@ -277,7 +277,7 @@ static int intel_qep_spike_filter_ns_write(struct counter_device *counter,
 					   struct counter_count *count,
 					   u64 length)
 {
-	struct intel_qep *qep = counter->priv;
+	struct intel_qep *qep = counter_priv(counter);
 	u32 reg;
 	bool enable;
 	int ret = 0;
@@ -326,7 +326,7 @@ static int intel_qep_preset_enable_read(struct counter_device *counter,
 					struct counter_count *count,
 					u8 *preset_enable)
 {
-	struct intel_qep *qep = counter->priv;
+	struct intel_qep *qep = counter_priv(counter);
 	u32 reg;
 
 	pm_runtime_get_sync(qep->dev);
@@ -341,7 +341,7 @@ static int intel_qep_preset_enable_read(struct counter_device *counter,
 static int intel_qep_preset_enable_write(struct counter_device *counter,
 					 struct counter_count *count, u8 val)
 {
-	struct intel_qep *qep = counter->priv;
+	struct intel_qep *qep = counter_priv(counter);
 	u32 reg;
 	int ret = 0;
 
-- 
2.33.0


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

* [PATCH v2 09/23] counter: ftm-quaddec: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (8 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 18:07   ` Jonathan Cameron
  2021-12-29  7:36   ` William Breathitt Gray
  -1 siblings, 2 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Patrick Havelange,
	Syed Nayyar Waris

This is a straight forward conversion to the new counter_priv() wrapper.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/ftm-quaddec.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
index 9272f7b58beb..f5d92df6a611 100644
--- a/drivers/counter/ftm-quaddec.c
+++ b/drivers/counter/ftm-quaddec.c
@@ -118,7 +118,7 @@ static void ftm_quaddec_disable(void *ftm)
 static int ftm_quaddec_get_prescaler(struct counter_device *counter,
 				     struct counter_count *count, u32 *cnt_mode)
 {
-	struct ftm_quaddec *ftm = counter->priv;
+	struct ftm_quaddec *ftm = counter_priv(counter);
 	uint32_t scflags;
 
 	ftm_read(ftm, FTM_SC, &scflags);
@@ -131,7 +131,7 @@ static int ftm_quaddec_get_prescaler(struct counter_device *counter,
 static int ftm_quaddec_set_prescaler(struct counter_device *counter,
 				     struct counter_count *count, u32 cnt_mode)
 {
-	struct ftm_quaddec *ftm = counter->priv;
+	struct ftm_quaddec *ftm = counter_priv(counter);
 
 	mutex_lock(&ftm->ftm_quaddec_mutex);
 
@@ -162,7 +162,7 @@ static int ftm_quaddec_count_read(struct counter_device *counter,
 				  struct counter_count *count,
 				  u64 *val)
 {
-	struct ftm_quaddec *const ftm = counter->priv;
+	struct ftm_quaddec *const ftm = counter_priv(counter);
 	uint32_t cntval;
 
 	ftm_read(ftm, FTM_CNT, &cntval);
@@ -176,7 +176,7 @@ static int ftm_quaddec_count_write(struct counter_device *counter,
 				   struct counter_count *count,
 				   const u64 val)
 {
-	struct ftm_quaddec *const ftm = counter->priv;
+	struct ftm_quaddec *const ftm = counter_priv(counter);
 
 	if (val != 0) {
 		dev_warn(&ftm->pdev->dev, "Can only accept '0' as new counter value\n");
-- 
2.33.0


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

* [PATCH v2 10/23] counter: ti-eqep: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (9 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 18:07   ` Jonathan Cameron
  2021-12-29  7:45   ` William Breathitt Gray
  -1 siblings, 2 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, David Lechner

This is a straight forward conversion to the new counter_priv() wrapper.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/ti-eqep.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
index 09817c953f9a..abeda966e7be 100644
--- a/drivers/counter/ti-eqep.c
+++ b/drivers/counter/ti-eqep.c
@@ -90,7 +90,7 @@ struct ti_eqep_cnt {
 static int ti_eqep_count_read(struct counter_device *counter,
 			      struct counter_count *count, u64 *val)
 {
-	struct ti_eqep_cnt *priv = counter->priv;
+	struct ti_eqep_cnt *priv = counter_priv(counter);
 	u32 cnt;
 
 	regmap_read(priv->regmap32, QPOSCNT, &cnt);
@@ -102,7 +102,7 @@ static int ti_eqep_count_read(struct counter_device *counter,
 static int ti_eqep_count_write(struct counter_device *counter,
 			       struct counter_count *count, u64 val)
 {
-	struct ti_eqep_cnt *priv = counter->priv;
+	struct ti_eqep_cnt *priv = counter_priv(counter);
 	u32 max;
 
 	regmap_read(priv->regmap32, QPOSMAX, &max);
@@ -116,7 +116,7 @@ static int ti_eqep_function_read(struct counter_device *counter,
 				 struct counter_count *count,
 				 enum counter_function *function)
 {
-	struct ti_eqep_cnt *priv = counter->priv;
+	struct ti_eqep_cnt *priv = counter_priv(counter);
 	u32 qdecctl;
 
 	regmap_read(priv->regmap16, QDECCTL, &qdecctl);
@@ -143,7 +143,7 @@ static int ti_eqep_function_write(struct counter_device *counter,
 				  struct counter_count *count,
 				  enum counter_function function)
 {
-	struct ti_eqep_cnt *priv = counter->priv;
+	struct ti_eqep_cnt *priv = counter_priv(counter);
 	enum ti_eqep_count_func qsrc;
 
 	switch (function) {
@@ -173,7 +173,7 @@ static int ti_eqep_action_read(struct counter_device *counter,
 			       struct counter_synapse *synapse,
 			       enum counter_synapse_action *action)
 {
-	struct ti_eqep_cnt *priv = counter->priv;
+	struct ti_eqep_cnt *priv = counter_priv(counter);
 	enum counter_function function;
 	u32 qdecctl;
 	int err;
@@ -245,7 +245,7 @@ static int ti_eqep_position_ceiling_read(struct counter_device *counter,
 					 struct counter_count *count,
 					 u64 *ceiling)
 {
-	struct ti_eqep_cnt *priv = counter->priv;
+	struct ti_eqep_cnt *priv = counter_priv(counter);
 	u32 qposmax;
 
 	regmap_read(priv->regmap32, QPOSMAX, &qposmax);
@@ -259,7 +259,7 @@ static int ti_eqep_position_ceiling_write(struct counter_device *counter,
 					  struct counter_count *count,
 					  u64 ceiling)
 {
-	struct ti_eqep_cnt *priv = counter->priv;
+	struct ti_eqep_cnt *priv = counter_priv(counter);
 
 	if (ceiling != (u32)ceiling)
 		return -ERANGE;
@@ -272,7 +272,7 @@ static int ti_eqep_position_ceiling_write(struct counter_device *counter,
 static int ti_eqep_position_enable_read(struct counter_device *counter,
 					struct counter_count *count, u8 *enable)
 {
-	struct ti_eqep_cnt *priv = counter->priv;
+	struct ti_eqep_cnt *priv = counter_priv(counter);
 	u32 qepctl;
 
 	regmap_read(priv->regmap16, QEPCTL, &qepctl);
@@ -285,7 +285,7 @@ static int ti_eqep_position_enable_read(struct counter_device *counter,
 static int ti_eqep_position_enable_write(struct counter_device *counter,
 					 struct counter_count *count, u8 enable)
 {
-	struct ti_eqep_cnt *priv = counter->priv;
+	struct ti_eqep_cnt *priv = counter_priv(counter);
 
 	regmap_write_bits(priv->regmap16, QEPCTL, QEPCTL_PHEN, enable ? -1 : 0);
 
-- 
2.33.0


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

* [PATCH v2 11/23] counter: stm32-lptimer-cnt: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` Uwe Kleine-König
@ 2021-12-27  9:45   ` Uwe Kleine-König
  -1 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel

This is a straight forward conversion to the new counter_priv() wrapper.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/stm32-lptimer-cnt.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
index 5168833b1fdf..9cf00e929cc0 100644
--- a/drivers/counter/stm32-lptimer-cnt.c
+++ b/drivers/counter/stm32-lptimer-cnt.c
@@ -141,7 +141,7 @@ static const enum counter_synapse_action stm32_lptim_cnt_synapse_actions[] = {
 static int stm32_lptim_cnt_read(struct counter_device *counter,
 				struct counter_count *count, u64 *val)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 	u32 cnt;
 	int ret;
 
@@ -158,7 +158,7 @@ static int stm32_lptim_cnt_function_read(struct counter_device *counter,
 					 struct counter_count *count,
 					 enum counter_function *function)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 
 	if (!priv->quadrature_mode) {
 		*function = COUNTER_FUNCTION_INCREASE;
@@ -177,7 +177,7 @@ static int stm32_lptim_cnt_function_write(struct counter_device *counter,
 					  struct counter_count *count,
 					  enum counter_function function)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 
 	if (stm32_lptim_is_enabled(priv))
 		return -EBUSY;
@@ -200,7 +200,7 @@ static int stm32_lptim_cnt_enable_read(struct counter_device *counter,
 				       struct counter_count *count,
 				       u8 *enable)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 	int ret;
 
 	ret = stm32_lptim_is_enabled(priv);
@@ -216,7 +216,7 @@ static int stm32_lptim_cnt_enable_write(struct counter_device *counter,
 					struct counter_count *count,
 					u8 enable)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 	int ret;
 
 	/* Check nobody uses the timer, or already disabled/enabled */
@@ -241,7 +241,7 @@ static int stm32_lptim_cnt_ceiling_read(struct counter_device *counter,
 					struct counter_count *count,
 					u64 *ceiling)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 
 	*ceiling = priv->ceiling;
 
@@ -252,7 +252,7 @@ static int stm32_lptim_cnt_ceiling_write(struct counter_device *counter,
 					 struct counter_count *count,
 					 u64 ceiling)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 
 	if (stm32_lptim_is_enabled(priv))
 		return -EBUSY;
@@ -277,7 +277,7 @@ static int stm32_lptim_cnt_action_read(struct counter_device *counter,
 				       struct counter_synapse *synapse,
 				       enum counter_synapse_action *action)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 	enum counter_function function;
 	int err;
 
@@ -321,7 +321,7 @@ static int stm32_lptim_cnt_action_write(struct counter_device *counter,
 					struct counter_synapse *synapse,
 					enum counter_synapse_action action)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 	enum counter_function function;
 	int err;
 
-- 
2.33.0


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

* [PATCH v2 11/23] counter: stm32-lptimer-cnt: Convert to counter_priv() wrapper
@ 2021-12-27  9:45   ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel

This is a straight forward conversion to the new counter_priv() wrapper.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/stm32-lptimer-cnt.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
index 5168833b1fdf..9cf00e929cc0 100644
--- a/drivers/counter/stm32-lptimer-cnt.c
+++ b/drivers/counter/stm32-lptimer-cnt.c
@@ -141,7 +141,7 @@ static const enum counter_synapse_action stm32_lptim_cnt_synapse_actions[] = {
 static int stm32_lptim_cnt_read(struct counter_device *counter,
 				struct counter_count *count, u64 *val)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 	u32 cnt;
 	int ret;
 
@@ -158,7 +158,7 @@ static int stm32_lptim_cnt_function_read(struct counter_device *counter,
 					 struct counter_count *count,
 					 enum counter_function *function)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 
 	if (!priv->quadrature_mode) {
 		*function = COUNTER_FUNCTION_INCREASE;
@@ -177,7 +177,7 @@ static int stm32_lptim_cnt_function_write(struct counter_device *counter,
 					  struct counter_count *count,
 					  enum counter_function function)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 
 	if (stm32_lptim_is_enabled(priv))
 		return -EBUSY;
@@ -200,7 +200,7 @@ static int stm32_lptim_cnt_enable_read(struct counter_device *counter,
 				       struct counter_count *count,
 				       u8 *enable)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 	int ret;
 
 	ret = stm32_lptim_is_enabled(priv);
@@ -216,7 +216,7 @@ static int stm32_lptim_cnt_enable_write(struct counter_device *counter,
 					struct counter_count *count,
 					u8 enable)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 	int ret;
 
 	/* Check nobody uses the timer, or already disabled/enabled */
@@ -241,7 +241,7 @@ static int stm32_lptim_cnt_ceiling_read(struct counter_device *counter,
 					struct counter_count *count,
 					u64 *ceiling)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 
 	*ceiling = priv->ceiling;
 
@@ -252,7 +252,7 @@ static int stm32_lptim_cnt_ceiling_write(struct counter_device *counter,
 					 struct counter_count *count,
 					 u64 ceiling)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 
 	if (stm32_lptim_is_enabled(priv))
 		return -EBUSY;
@@ -277,7 +277,7 @@ static int stm32_lptim_cnt_action_read(struct counter_device *counter,
 				       struct counter_synapse *synapse,
 				       enum counter_synapse_action *action)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 	enum counter_function function;
 	int err;
 
@@ -321,7 +321,7 @@ static int stm32_lptim_cnt_action_write(struct counter_device *counter,
 					struct counter_synapse *synapse,
 					enum counter_synapse_action action)
 {
-	struct stm32_lptim_cnt *const priv = counter->priv;
+	struct stm32_lptim_cnt *const priv = counter_priv(counter);
 	enum counter_function function;
 	int err;
 
-- 
2.33.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 12/23] counter: stm32-timer-cnt: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` Uwe Kleine-König
@ 2021-12-27  9:45   ` Uwe Kleine-König
  -1 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel

This is a straight forward conversion to the new counter_priv() wrapper.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/stm32-timer-cnt.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
index 0546e932db0c..4b05b198a8d8 100644
--- a/drivers/counter/stm32-timer-cnt.c
+++ b/drivers/counter/stm32-timer-cnt.c
@@ -47,7 +47,7 @@ static const enum counter_function stm32_count_functions[] = {
 static int stm32_count_read(struct counter_device *counter,
 			    struct counter_count *count, u64 *val)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 cnt;
 
 	regmap_read(priv->regmap, TIM_CNT, &cnt);
@@ -59,7 +59,7 @@ static int stm32_count_read(struct counter_device *counter,
 static int stm32_count_write(struct counter_device *counter,
 			     struct counter_count *count, const u64 val)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 ceiling;
 
 	regmap_read(priv->regmap, TIM_ARR, &ceiling);
@@ -73,7 +73,7 @@ static int stm32_count_function_read(struct counter_device *counter,
 				     struct counter_count *count,
 				     enum counter_function *function)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 smcr;
 
 	regmap_read(priv->regmap, TIM_SMCR, &smcr);
@@ -100,7 +100,7 @@ static int stm32_count_function_write(struct counter_device *counter,
 				      struct counter_count *count,
 				      enum counter_function function)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 cr1, sms;
 
 	switch (function) {
@@ -140,7 +140,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
 				      struct counter_count *count,
 				      enum counter_count_direction *direction)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 cr1;
 
 	regmap_read(priv->regmap, TIM_CR1, &cr1);
@@ -153,7 +153,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
 static int stm32_count_ceiling_read(struct counter_device *counter,
 				    struct counter_count *count, u64 *ceiling)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 arr;
 
 	regmap_read(priv->regmap, TIM_ARR, &arr);
@@ -166,7 +166,7 @@ static int stm32_count_ceiling_read(struct counter_device *counter,
 static int stm32_count_ceiling_write(struct counter_device *counter,
 				     struct counter_count *count, u64 ceiling)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 
 	if (ceiling > priv->max_arr)
 		return -ERANGE;
@@ -181,7 +181,7 @@ static int stm32_count_ceiling_write(struct counter_device *counter,
 static int stm32_count_enable_read(struct counter_device *counter,
 				   struct counter_count *count, u8 *enable)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 cr1;
 
 	regmap_read(priv->regmap, TIM_CR1, &cr1);
@@ -194,7 +194,7 @@ static int stm32_count_enable_read(struct counter_device *counter,
 static int stm32_count_enable_write(struct counter_device *counter,
 				    struct counter_count *count, u8 enable)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 cr1;
 
 	if (enable) {
-- 
2.33.0


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

* [PATCH v2 12/23] counter: stm32-timer-cnt: Convert to counter_priv() wrapper
@ 2021-12-27  9:45   ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel

This is a straight forward conversion to the new counter_priv() wrapper.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/stm32-timer-cnt.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
index 0546e932db0c..4b05b198a8d8 100644
--- a/drivers/counter/stm32-timer-cnt.c
+++ b/drivers/counter/stm32-timer-cnt.c
@@ -47,7 +47,7 @@ static const enum counter_function stm32_count_functions[] = {
 static int stm32_count_read(struct counter_device *counter,
 			    struct counter_count *count, u64 *val)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 cnt;
 
 	regmap_read(priv->regmap, TIM_CNT, &cnt);
@@ -59,7 +59,7 @@ static int stm32_count_read(struct counter_device *counter,
 static int stm32_count_write(struct counter_device *counter,
 			     struct counter_count *count, const u64 val)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 ceiling;
 
 	regmap_read(priv->regmap, TIM_ARR, &ceiling);
@@ -73,7 +73,7 @@ static int stm32_count_function_read(struct counter_device *counter,
 				     struct counter_count *count,
 				     enum counter_function *function)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 smcr;
 
 	regmap_read(priv->regmap, TIM_SMCR, &smcr);
@@ -100,7 +100,7 @@ static int stm32_count_function_write(struct counter_device *counter,
 				      struct counter_count *count,
 				      enum counter_function function)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 cr1, sms;
 
 	switch (function) {
@@ -140,7 +140,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
 				      struct counter_count *count,
 				      enum counter_count_direction *direction)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 cr1;
 
 	regmap_read(priv->regmap, TIM_CR1, &cr1);
@@ -153,7 +153,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
 static int stm32_count_ceiling_read(struct counter_device *counter,
 				    struct counter_count *count, u64 *ceiling)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 arr;
 
 	regmap_read(priv->regmap, TIM_ARR, &arr);
@@ -166,7 +166,7 @@ static int stm32_count_ceiling_read(struct counter_device *counter,
 static int stm32_count_ceiling_write(struct counter_device *counter,
 				     struct counter_count *count, u64 ceiling)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 
 	if (ceiling > priv->max_arr)
 		return -ERANGE;
@@ -181,7 +181,7 @@ static int stm32_count_ceiling_write(struct counter_device *counter,
 static int stm32_count_enable_read(struct counter_device *counter,
 				   struct counter_count *count, u8 *enable)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 cr1;
 
 	regmap_read(priv->regmap, TIM_CR1, &cr1);
@@ -194,7 +194,7 @@ static int stm32_count_enable_read(struct counter_device *counter,
 static int stm32_count_enable_write(struct counter_device *counter,
 				    struct counter_count *count, u8 enable)
 {
-	struct stm32_timer_cnt *const priv = counter->priv;
+	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 cr1;
 
 	if (enable) {
-- 
2.33.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 13/23] counter: Provide alternative counter registration functions
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (12 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-27 12:16   ` Lars-Peter Clausen
                     ` (3 more replies)
  -1 siblings, 4 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel

The current implementation gets device lifetime tracking wrong. The
problem is that allocation of struct counter_device is controlled by the
individual drivers but this structure contains a struct device that
might have to live longer than a driver is bound. As a result a command
sequence like:

	{ sleep 5; echo bang; } > /dev/counter0 &
	sleep 1;
	echo 40000000.timer:counter > /sys/bus/platform/drivers/stm32-timer-counter/unbind

can keep a reference to the struct device and unbinding results in
freeing the memory occupied by this device resulting in an oops.

This commit provides two new functions (plus some helpers):
 - counter_alloc() to allocate a struct counter_device that is
   automatically freed once the embedded struct device is released
 - counter_add() to register such a device.

Note that this commit doesn't fix any issues, all drivers have to be
converted to these new functions to correct the lifetime problems.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/counter-core.c | 149 ++++++++++++++++++++++++++++++++-
 include/linux/counter.h        |  15 ++++
 2 files changed, 163 insertions(+), 1 deletion(-)

diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
index 00c41f28c101..8261567b6272 100644
--- a/drivers/counter/counter-core.c
+++ b/drivers/counter/counter-core.c
@@ -15,6 +15,7 @@
 #include <linux/kdev_t.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/wait.h>
 
@@ -24,6 +25,11 @@
 /* Provides a unique ID for each counter device */
 static DEFINE_IDA(counter_ida);
 
+struct counter_device_allochelper {
+	struct counter_device counter;
+	unsigned long privdata[];
+};
+
 static void counter_device_release(struct device *dev)
 {
 	struct counter_device *const counter =
@@ -31,6 +37,9 @@ static void counter_device_release(struct device *dev)
 
 	counter_chrdev_remove(counter);
 	ida_free(&counter_ida, dev->id);
+
+	if (!counter->legacy_device)
+		kfree(container_of(counter, struct counter_device_allochelper, counter));
 }
 
 static struct device_type counter_device_type = {
@@ -53,7 +62,14 @@ static dev_t counter_devt;
  */
 void *counter_priv(const struct counter_device *const counter)
 {
-	return counter->priv;
+	if (counter->legacy_device) {
+		return counter->priv;
+	} else {
+		struct counter_device_allochelper *ch =
+			container_of(counter, struct counter_device_allochelper, counter);
+
+		return &ch->privdata;
+	}
 }
 EXPORT_SYMBOL_GPL(counter_priv);
 
@@ -74,6 +90,8 @@ int counter_register(struct counter_device *const counter)
 	int id;
 	int err;
 
+	counter->legacy_device = true;
+
 	/* Acquire unique ID */
 	id = ida_alloc(&counter_ida, GFP_KERNEL);
 	if (id < 0)
@@ -114,6 +132,100 @@ int counter_register(struct counter_device *const counter)
 }
 EXPORT_SYMBOL_GPL(counter_register);
 
+/**
+ * counter_alloc - allocate a counter_device
+ * @sizeof_priv: size of the driver private data
+ *
+ * This is part one of counter registration. The structure is allocated
+ * dynamically to ensure the right lifetime for the embedded struct device.
+ *
+ * If this succeeds, call counter_put() to get rid of the counter_device again.
+ */
+struct counter_device *counter_alloc(size_t sizeof_priv)
+{
+	struct counter_device_allochelper *ch;
+	struct counter_device *counter;
+	struct device *dev;
+	int id, err;
+
+	ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
+	if (!ch) {
+		err = -ENOMEM;
+		goto err_alloc_ch;
+	}
+
+	counter = &ch->counter;
+	dev = &counter->dev;
+
+	/* Acquire unique ID */
+	err = ida_alloc(&counter_ida, GFP_KERNEL);
+	if (err < 0) {
+		goto err_ida_alloc;
+	}
+	dev->id = err;
+
+	err = counter_chrdev_add(counter);
+	if (err < 0)
+		goto err_chrdev_add;
+
+	device_initialize(dev);
+	/* Configure device structure for Counter */
+	dev->type = &counter_device_type;
+	dev->bus = &counter_bus_type;
+	dev->devt = MKDEV(MAJOR(counter_devt), id);
+
+	mutex_init(&counter->ops_exist_lock);
+
+	return counter;
+
+err_chrdev_add:
+
+	ida_free(&counter_ida, dev->id);
+err_ida_alloc:
+
+	kfree(ch);
+err_alloc_ch:
+
+	return ERR_PTR(err);
+}
+EXPORT_SYMBOL_GPL(counter_alloc);
+
+void counter_put(struct counter_device *counter)
+{
+	put_device(&counter->dev);
+}
+
+/**
+ * counter_add - complete registration of a counter
+ * @counter: the counter to add
+ *
+ * This is part two of counter registration.
+ *
+ * If this succeeds, call counter_unregister() to get rid of the counter_device again.
+ */
+int counter_add(struct counter_device *counter)
+{
+	int err;
+	struct device *dev = &counter->dev;
+
+	get_device(&counter->dev);
+
+	if (counter->parent) {
+		dev->parent = counter->parent;
+		dev->of_node = counter->parent->of_node;
+	}
+
+	err = counter_sysfs_add(counter);
+	if (err < 0)
+		return err;
+
+	/* implies device_add(dev) */
+	err = cdev_device_add(&counter->chrdev, dev);
+
+	return err;
+}
+EXPORT_SYMBOL_GPL(counter_add);
+
 /**
  * counter_unregister - unregister Counter from the system
  * @counter:	pointer to Counter to unregister
@@ -168,6 +280,41 @@ int devm_counter_register(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_counter_register);
 
+static void devm_counter_put(void *counter)
+{
+	counter_put(counter);
+}
+
+struct counter_device *devm_counter_alloc(struct device *dev, size_t sizeof_priv)
+{
+	struct counter_device *counter;
+	int err;
+
+	counter = counter_alloc(sizeof_priv);
+	if (IS_ERR(counter))
+		return counter;
+
+	err = devm_add_action_or_reset(dev, devm_counter_put, counter);
+	if (err < 0)
+		return ERR_PTR(err);
+
+	return counter;
+}
+EXPORT_SYMBOL_GPL(devm_counter_alloc);
+
+int devm_counter_add(struct device *dev,
+		     struct counter_device *const counter)
+{
+	int err;
+
+	err = counter_add(counter);
+	if (err < 0)
+		return err;
+
+	return devm_add_action_or_reset(dev, devm_counter_release, counter);
+}
+EXPORT_SYMBOL_GPL(devm_counter_add);
+
 #define COUNTER_DEV_MAX 256
 
 static int __init counter_init(void)
diff --git a/include/linux/counter.h b/include/linux/counter.h
index 8daaa38c71d8..f1350a43cd48 100644
--- a/include/linux/counter.h
+++ b/include/linux/counter.h
@@ -327,14 +327,29 @@ struct counter_device {
 	spinlock_t events_in_lock;
 	struct mutex events_out_lock;
 	struct mutex ops_exist_lock;
+
+	/*
+	 * This can go away once all drivers are converted to
+	 * counter_alloc()/counter_add().
+	 */
+	bool legacy_device;
 };
 
 void *counter_priv(const struct counter_device *const counter);
 
 int counter_register(struct counter_device *const counter);
+
+struct counter_device *counter_alloc(size_t sizeof_priv);
+void counter_put(struct counter_device *const counter);
+int counter_add(struct counter_device *const counter);
+
 void counter_unregister(struct counter_device *const counter);
 int devm_counter_register(struct device *dev,
 			  struct counter_device *const counter);
+struct counter_device *devm_counter_alloc(struct device *dev,
+					  size_t sizeof_priv);
+int devm_counter_add(struct device *dev,
+		     struct counter_device *const counter);
 void counter_push_event(struct counter_device *const counter, const u8 event,
 			const u8 channel);
 
-- 
2.33.0


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

* [PATCH v2 14/23] counter: Update documentation for new counter registration functions
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (13 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 18:12   ` Jonathan Cameron
  -1 siblings, 1 reply; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Jonathan Corbet, linux-doc

In order to replace the counter registration API also update the
documentation to the new way.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 Documentation/driver-api/generic-counter.rst | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Documentation/driver-api/generic-counter.rst b/Documentation/driver-api/generic-counter.rst
index 1b487a331467..991b180c7b47 100644
--- a/Documentation/driver-api/generic-counter.rst
+++ b/Documentation/driver-api/generic-counter.rst
@@ -262,11 +262,11 @@ order to communicate with the device: to read and write various Signals
 and Counts, and to set and get the "action mode" and "function mode" for
 various Synapses and Counts respectively.
 
-A defined counter_device structure may be registered to the system by
-passing it to the counter_register function, and unregistered by passing
-it to the counter_unregister function. Similarly, the
-devm_counter_register function may be used if device memory-managed
-registration is desired.
+A counter_device structure is supposed to be allocated using counter_alloc()
+and may be registered to the system by passing it to the counter_add()
+function, and unregistered by passing it to the counter_unregister function.
+There are device managed variants of these functions: devm_counter_alloc() and
+devm_counter_add().
 
 The struct counter_comp structure is used to define counter extensions
 for Signals, Synapses, and Counts.
-- 
2.33.0


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

* [PATCH v2 15/23] counter: 104-quad-8: Convert to new counter registration
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (14 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-27 12:19   ` Lars-Peter Clausen
                     ` (2 more replies)
  -1 siblings, 3 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Syed Nayyar Waris

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: f1d8a071d45b ("counter: 104-quad-8: Add Generic Counter interface support")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/104-quad-8.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 6e5286cd1d4e..4315b14f239e 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -52,7 +52,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-QUAD-8 interrupt line numbers");
  */
 struct quad8 {
 	spinlock_t lock;
-	struct counter_device counter;
 	unsigned int fck_prescaler[QUAD8_NUM_COUNTERS];
 	unsigned int preset[QUAD8_NUM_COUNTERS];
 	unsigned int count_mode[QUAD8_NUM_COUNTERS];
@@ -1127,6 +1126,7 @@ static irqreturn_t quad8_irq_handler(int irq, void *private)
 
 static int quad8_probe(struct device *dev, unsigned int id)
 {
+	struct counter_device *counter;
 	struct quad8 *priv;
 	int i, j;
 	unsigned int base_offset;
@@ -1138,19 +1138,19 @@ static int quad8_probe(struct device *dev, unsigned int id)
 		return -EBUSY;
 	}
 
-	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
+	counter = devm_counter_alloc(dev, sizeof(*priv));
+	if (!counter)
 		return -ENOMEM;
+	priv = counter_priv(counter);
 
 	/* Initialize Counter device and driver data */
-	priv->counter.name = dev_name(dev);
-	priv->counter.parent = dev;
-	priv->counter.ops = &quad8_ops;
-	priv->counter.counts = quad8_counts;
-	priv->counter.num_counts = ARRAY_SIZE(quad8_counts);
-	priv->counter.signals = quad8_signals;
-	priv->counter.num_signals = ARRAY_SIZE(quad8_signals);
-	priv->counter.priv = priv;
+	counter->name = dev_name(dev);
+	counter->parent = dev;
+	counter->ops = &quad8_ops;
+	counter->counts = quad8_counts;
+	counter->num_counts = ARRAY_SIZE(quad8_counts);
+	counter->signals = quad8_signals;
+	counter->num_signals = ARRAY_SIZE(quad8_signals);
 	priv->base = base[id];
 
 	spin_lock_init(&priv->lock);
@@ -1192,11 +1192,15 @@ static int quad8_probe(struct device *dev, unsigned int id)
 	outb(QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC, base[id] + QUAD8_REG_CHAN_OP);
 
 	err = devm_request_irq(dev, irq[id], quad8_irq_handler, IRQF_SHARED,
-			       priv->counter.name, priv);
+			       counter->name, priv);
 	if (err)
 		return err;
 
-	return devm_counter_register(dev, &priv->counter);
+	err = devm_counter_add(dev, counter);
+	if (err < 0)
+		return dev_err_probe(dev, err, "Failed to add counter\n");
+
+	return 0;
 }
 
 static struct isa_driver quad8_driver = {
-- 
2.33.0


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

* [PATCH v2 16/23] counter: interrupt-cnt: Convert to new counter registration
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (15 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-27 10:59   ` Greg Kroah-Hartman
                     ` (2 more replies)
  -1 siblings, 3 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Ahmad Fatoum, Oleksij Rempel

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: a55ebd47f21f ("counter: add IRQ or GPIO based counter")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/interrupt-cnt.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c
index 4bf706ef46e2..9e99702470c2 100644
--- a/drivers/counter/interrupt-cnt.c
+++ b/drivers/counter/interrupt-cnt.c
@@ -16,7 +16,6 @@
 
 struct interrupt_cnt_priv {
 	atomic_t count;
-	struct counter_device counter;
 	struct gpio_desc *gpio;
 	int irq;
 	bool enabled;
@@ -148,12 +147,14 @@ static const struct counter_ops interrupt_cnt_ops = {
 static int interrupt_cnt_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
+	struct counter_device *counter;
 	struct interrupt_cnt_priv *priv;
 	int ret;
 
-	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
+	counter = devm_counter_alloc(dev, sizeof(*priv));
+	if (!counter)
 		return -ENOMEM;
+	priv = counter_priv(counter);
 
 	priv->irq = platform_get_irq_optional(pdev,  0);
 	if (priv->irq == -ENXIO)
@@ -184,8 +185,8 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
 	if (!priv->signals.name)
 		return -ENOMEM;
 
-	priv->counter.signals = &priv->signals;
-	priv->counter.num_signals = 1;
+	counter->signals = &priv->signals;
+	counter->num_signals = 1;
 
 	priv->synapses.actions_list = interrupt_cnt_synapse_actions;
 	priv->synapses.num_actions = ARRAY_SIZE(interrupt_cnt_synapse_actions);
@@ -199,12 +200,11 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
 	priv->cnts.ext = interrupt_cnt_ext;
 	priv->cnts.num_ext = ARRAY_SIZE(interrupt_cnt_ext);
 
-	priv->counter.priv = priv;
-	priv->counter.name = dev_name(dev);
-	priv->counter.parent = dev;
-	priv->counter.ops = &interrupt_cnt_ops;
-	priv->counter.counts = &priv->cnts;
-	priv->counter.num_counts = 1;
+	counter->name = dev_name(dev);
+	counter->parent = dev;
+	counter->ops = &interrupt_cnt_ops;
+	counter->counts = &priv->cnts;
+	counter->num_counts = 1;
 
 	irq_set_status_flags(priv->irq, IRQ_NOAUTOEN);
 	ret = devm_request_irq(dev, priv->irq, interrupt_cnt_isr,
@@ -213,7 +213,11 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	return devm_counter_register(dev, &priv->counter);
+	ret = devm_counter_add(dev, counter);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Failed to add counter\n");
+
+	return 0;
 }
 
 static const struct of_device_id interrupt_cnt_of_match[] = {
-- 
2.33.0


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

* [PATCH v2 17/23] counter: intel-qep: Convert to new counter registration
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (16 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-27 15:02   ` Jarkko Nikula
                     ` (2 more replies)
  -1 siblings, 3 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Jarkko Nikula,
	Felipe Balbi (Intel),
	Raymond Tan

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: b711f687a1c1 ("counter: Add support for Intel Quadrature Encoder Peripheral")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/intel-qep.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c
index 8f84a48508ac..47a6a9dfc9e8 100644
--- a/drivers/counter/intel-qep.c
+++ b/drivers/counter/intel-qep.c
@@ -63,7 +63,6 @@
 #define INTEL_QEP_CLK_PERIOD_NS		10
 
 struct intel_qep {
-	struct counter_device counter;
 	struct mutex lock;
 	struct device *dev;
 	void __iomem *regs;
@@ -392,14 +391,16 @@ static struct counter_count intel_qep_counter_count[] = {
 
 static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id)
 {
+	struct counter_device *counter;
 	struct intel_qep *qep;
 	struct device *dev = &pci->dev;
 	void __iomem *regs;
 	int ret;
 
-	qep = devm_kzalloc(dev, sizeof(*qep), GFP_KERNEL);
-	if (!qep)
+	counter = devm_counter_alloc(dev, sizeof(*qep));
+	if (!counter)
 		return -ENOMEM;
+	qep = counter_priv(counter);
 
 	ret = pcim_enable_device(pci);
 	if (ret)
@@ -422,20 +423,23 @@ static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id)
 	intel_qep_init(qep);
 	pci_set_drvdata(pci, qep);
 
-	qep->counter.name = pci_name(pci);
-	qep->counter.parent = dev;
-	qep->counter.ops = &intel_qep_counter_ops;
-	qep->counter.counts = intel_qep_counter_count;
-	qep->counter.num_counts = ARRAY_SIZE(intel_qep_counter_count);
-	qep->counter.signals = intel_qep_signals;
-	qep->counter.num_signals = ARRAY_SIZE(intel_qep_signals);
-	qep->counter.priv = qep;
+	counter->name = pci_name(pci);
+	counter->parent = dev;
+	counter->ops = &intel_qep_counter_ops;
+	counter->counts = intel_qep_counter_count;
+	counter->num_counts = ARRAY_SIZE(intel_qep_counter_count);
+	counter->signals = intel_qep_signals;
+	counter->num_signals = ARRAY_SIZE(intel_qep_signals);
 	qep->enabled = false;
 
 	pm_runtime_put(dev);
 	pm_runtime_allow(dev);
 
-	return devm_counter_register(&pci->dev, &qep->counter);
+	ret = devm_counter_add(&pci->dev, counter);
+	if (ret < 0)
+		return dev_err_probe(&pci->dev, ret, "Failed to add counter\n");
+
+	return 0;
 }
 
 static void intel_qep_remove(struct pci_dev *pci)
-- 
2.33.0


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

* [PATCH v2 18/23] counter: ftm-quaddec: Convert to new counter registration
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (17 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 18:23   ` Jonathan Cameron
  2021-12-29  8:33   ` William Breathitt Gray
  -1 siblings, 2 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Syed Nayyar Waris,
	Patrick Havelange

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/104-quad-8.c  |  7 ++++---
 drivers/counter/ftm-quaddec.c | 27 +++++++++++++--------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 4315b14f239e..680c7ba943a4 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -1084,7 +1084,8 @@ static struct counter_count quad8_counts[] = {
 
 static irqreturn_t quad8_irq_handler(int irq, void *private)
 {
-	struct quad8 *const priv = private;
+	struct counter_device *counter = private;
+	struct quad8 *const priv = counter_priv(counter);
 	const unsigned long base = priv->base;
 	unsigned long irq_status;
 	unsigned long channel;
@@ -1115,7 +1116,7 @@ static irqreturn_t quad8_irq_handler(int irq, void *private)
 			continue;
 		}
 
-		counter_push_event(&priv->counter, event, channel);
+		counter_push_event(counter, event, channel);
 	}
 
 	/* Clear pending interrupts on device */
@@ -1192,7 +1193,7 @@ static int quad8_probe(struct device *dev, unsigned int id)
 	outb(QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC, base[id] + QUAD8_REG_CHAN_OP);
 
 	err = devm_request_irq(dev, irq[id], quad8_irq_handler, IRQF_SHARED,
-			       counter->name, priv);
+			       counter->name, counter);
 	if (err)
 		return err;
 
diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
index f5d92df6a611..c636183b1337 100644
--- a/drivers/counter/ftm-quaddec.c
+++ b/drivers/counter/ftm-quaddec.c
@@ -26,7 +26,6 @@
 	})
 
 struct ftm_quaddec {
-	struct counter_device counter;
 	struct platform_device *pdev;
 	void __iomem *ftm_base;
 	bool big_endian;
@@ -259,15 +258,16 @@ static struct counter_count ftm_quaddec_counts = {
 
 static int ftm_quaddec_probe(struct platform_device *pdev)
 {
+	struct counter_device *counter;
 	struct ftm_quaddec *ftm;
-
 	struct device_node *node = pdev->dev.of_node;
 	struct resource *io;
 	int ret;
 
-	ftm = devm_kzalloc(&pdev->dev, sizeof(*ftm), GFP_KERNEL);
-	if (!ftm)
+	counter = devm_counter_alloc(&pdev->dev, sizeof(*ftm));
+	if (!counter)
 		return -ENOMEM;
+	ftm = counter_priv(counter);
 
 	io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!io) {
@@ -283,14 +283,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "Failed to map memory region\n");
 		return -EINVAL;
 	}
-	ftm->counter.name = dev_name(&pdev->dev);
-	ftm->counter.parent = &pdev->dev;
-	ftm->counter.ops = &ftm_quaddec_cnt_ops;
-	ftm->counter.counts = &ftm_quaddec_counts;
-	ftm->counter.num_counts = 1;
-	ftm->counter.signals = ftm_quaddec_signals;
-	ftm->counter.num_signals = ARRAY_SIZE(ftm_quaddec_signals);
-	ftm->counter.priv = ftm;
+	counter->name = dev_name(&pdev->dev);
+	counter->parent = &pdev->dev;
+	counter->ops = &ftm_quaddec_cnt_ops;
+	counter->counts = &ftm_quaddec_counts;
+	counter->num_counts = 1;
+	counter->signals = ftm_quaddec_signals;
+	counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals);
 
 	mutex_init(&ftm->ftm_quaddec_mutex);
 
@@ -300,9 +299,9 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = devm_counter_register(&pdev->dev, &ftm->counter);
+	ret = devm_counter_add(&pdev->dev, counter);
 	if (ret)
-		return ret;
+		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
 
 	return 0;
 }
-- 
2.33.0


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

* [PATCH v2 19/23] counter: microchip-tcb-capture: Convert to new counter registration
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (18 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 18:24   ` Jonathan Cameron
  2021-12-29  8:36   ` William Breathitt Gray
  -1 siblings, 2 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Kamel Bouhara

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: 106b104137fd ("counter: Add microchip TCB capture counter")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/microchip-tcb-capture.c | 30 ++++++++++++++-----------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
index 1b56b7444668..70c1d28546be 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -24,7 +24,6 @@
 
 struct mchp_tc_data {
 	const struct atmel_tcb_config *tc_cfg;
-	struct counter_device counter;
 	struct regmap *regmap;
 	int qdec_mode;
 	int num_channels;
@@ -296,6 +295,7 @@ static int mchp_tc_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node;
 	const struct atmel_tcb_config *tcb_config;
 	const struct of_device_id *match;
+	struct counter_device *counter;
 	struct mchp_tc_data *priv;
 	char clk_name[7];
 	struct regmap *regmap;
@@ -303,9 +303,10 @@ static int mchp_tc_probe(struct platform_device *pdev)
 	int channel;
 	int ret, i;
 
-	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
+	counter = devm_counter_alloc(&pdev->dev, sizeof(*priv));
+	if (!counter)
 		return -ENOMEM;
+	priv = counter_priv(counter);
 
 	match = of_match_node(atmel_tc_of_match, np->parent);
 	tcb_config = match->data;
@@ -360,16 +361,19 @@ static int mchp_tc_probe(struct platform_device *pdev)
 
 	priv->tc_cfg = tcb_config;
 	priv->regmap = regmap;
-	priv->counter.name = dev_name(&pdev->dev);
-	priv->counter.parent = &pdev->dev;
-	priv->counter.ops = &mchp_tc_ops;
-	priv->counter.num_counts = ARRAY_SIZE(mchp_tc_counts);
-	priv->counter.counts = mchp_tc_counts;
-	priv->counter.num_signals = ARRAY_SIZE(mchp_tc_count_signals);
-	priv->counter.signals = mchp_tc_count_signals;
-	priv->counter.priv = priv;
-
-	return devm_counter_register(&pdev->dev, &priv->counter);
+	counter->name = dev_name(&pdev->dev);
+	counter->parent = &pdev->dev;
+	counter->ops = &mchp_tc_ops;
+	counter->num_counts = ARRAY_SIZE(mchp_tc_counts);
+	counter->counts = mchp_tc_counts;
+	counter->num_signals = ARRAY_SIZE(mchp_tc_count_signals);
+	counter->signals = mchp_tc_count_signals;
+
+	ret = devm_counter_add(&pdev->dev, counter);
+	if (ret < 0)
+		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
+ 
+	return 0;
 }
 
 static const struct of_device_id mchp_tc_dt_ids[] = {
-- 
2.33.0


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

* [PATCH v2 20/23] counter: stm32-timer-cnt: Convert to new counter registration
  2021-12-27  9:45 ` Uwe Kleine-König
@ 2021-12-27  9:45   ` Uwe Kleine-König
  -1 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, Benjamin Gaignard,
	linux-stm32, linux-arm-kernel

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: ad29937e206f ("counter: Add STM32 Timer quadrature encoder")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/stm32-timer-cnt.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
index 4b05b198a8d8..5779ae7c73cf 100644
--- a/drivers/counter/stm32-timer-cnt.c
+++ b/drivers/counter/stm32-timer-cnt.c
@@ -29,7 +29,6 @@ struct stm32_timer_regs {
 };
 
 struct stm32_timer_cnt {
-	struct counter_device counter;
 	struct regmap *regmap;
 	struct clk *clk;
 	u32 max_arr;
@@ -317,31 +316,38 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev)
 	struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
 	struct device *dev = &pdev->dev;
 	struct stm32_timer_cnt *priv;
+	struct counter_device *counter;
+	int ret;
 
 	if (IS_ERR_OR_NULL(ddata))
 		return -EINVAL;
 
-	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
+	counter = devm_counter_alloc(dev, sizeof(*priv));
+	if (!counter)
 		return -ENOMEM;
 
+	priv = counter_priv(counter);
+
 	priv->regmap = ddata->regmap;
 	priv->clk = ddata->clk;
 	priv->max_arr = ddata->max_arr;
 
-	priv->counter.name = dev_name(dev);
-	priv->counter.parent = dev;
-	priv->counter.ops = &stm32_timer_cnt_ops;
-	priv->counter.counts = &stm32_counts;
-	priv->counter.num_counts = 1;
-	priv->counter.signals = stm32_signals;
-	priv->counter.num_signals = ARRAY_SIZE(stm32_signals);
-	priv->counter.priv = priv;
+	counter->name = dev_name(dev);
+	counter->parent = dev;
+	counter->ops = &stm32_timer_cnt_ops;
+	counter->counts = &stm32_counts;
+	counter->num_counts = 1;
+	counter->signals = stm32_signals;
+	counter->num_signals = ARRAY_SIZE(stm32_signals);
 
 	platform_set_drvdata(pdev, priv);
 
 	/* Register Counter device */
-	return devm_counter_register(dev, &priv->counter);
+	ret = devm_counter_add(dev, counter);
+	if (ret < 0)
+		dev_err_probe(dev, ret, "Failed to add counter\n");
+
+	return ret;
 }
 
 static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev)
-- 
2.33.0


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

* [PATCH v2 20/23] counter: stm32-timer-cnt: Convert to new counter registration
@ 2021-12-27  9:45   ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, Benjamin Gaignard,
	linux-stm32, linux-arm-kernel

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: ad29937e206f ("counter: Add STM32 Timer quadrature encoder")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/stm32-timer-cnt.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
index 4b05b198a8d8..5779ae7c73cf 100644
--- a/drivers/counter/stm32-timer-cnt.c
+++ b/drivers/counter/stm32-timer-cnt.c
@@ -29,7 +29,6 @@ struct stm32_timer_regs {
 };
 
 struct stm32_timer_cnt {
-	struct counter_device counter;
 	struct regmap *regmap;
 	struct clk *clk;
 	u32 max_arr;
@@ -317,31 +316,38 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev)
 	struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
 	struct device *dev = &pdev->dev;
 	struct stm32_timer_cnt *priv;
+	struct counter_device *counter;
+	int ret;
 
 	if (IS_ERR_OR_NULL(ddata))
 		return -EINVAL;
 
-	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
+	counter = devm_counter_alloc(dev, sizeof(*priv));
+	if (!counter)
 		return -ENOMEM;
 
+	priv = counter_priv(counter);
+
 	priv->regmap = ddata->regmap;
 	priv->clk = ddata->clk;
 	priv->max_arr = ddata->max_arr;
 
-	priv->counter.name = dev_name(dev);
-	priv->counter.parent = dev;
-	priv->counter.ops = &stm32_timer_cnt_ops;
-	priv->counter.counts = &stm32_counts;
-	priv->counter.num_counts = 1;
-	priv->counter.signals = stm32_signals;
-	priv->counter.num_signals = ARRAY_SIZE(stm32_signals);
-	priv->counter.priv = priv;
+	counter->name = dev_name(dev);
+	counter->parent = dev;
+	counter->ops = &stm32_timer_cnt_ops;
+	counter->counts = &stm32_counts;
+	counter->num_counts = 1;
+	counter->signals = stm32_signals;
+	counter->num_signals = ARRAY_SIZE(stm32_signals);
 
 	platform_set_drvdata(pdev, priv);
 
 	/* Register Counter device */
-	return devm_counter_register(dev, &priv->counter);
+	ret = devm_counter_add(dev, counter);
+	if (ret < 0)
+		dev_err_probe(dev, ret, "Failed to add counter\n");
+
+	return ret;
 }
 
 static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev)
-- 
2.33.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 21/23] counter: stm32-lptimer-cnt: Convert to new counter registration
  2021-12-27  9:45 ` Uwe Kleine-König
@ 2021-12-27  9:45   ` Uwe Kleine-König
  -1 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, Benjamin Gaignard,
	linux-stm32, linux-arm-kernel

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: 597f55e3f36c ("counter: stm32-lptimer: add counter device")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/stm32-lptimer-cnt.c | 33 +++++++++++++++++------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
index 9cf00e929cc0..68031d93ce89 100644
--- a/drivers/counter/stm32-lptimer-cnt.c
+++ b/drivers/counter/stm32-lptimer-cnt.c
@@ -20,7 +20,6 @@
 #include <linux/types.h>
 
 struct stm32_lptim_cnt {
-	struct counter_device counter;
 	struct device *dev;
 	struct regmap *regmap;
 	struct clk *clk;
@@ -411,14 +410,17 @@ static struct counter_count stm32_lptim_in1_counts = {
 static int stm32_lptim_cnt_probe(struct platform_device *pdev)
 {
 	struct stm32_lptimer *ddata = dev_get_drvdata(pdev->dev.parent);
+	struct counter_device *counter;
 	struct stm32_lptim_cnt *priv;
+	int ret;
 
 	if (IS_ERR_OR_NULL(ddata))
 		return -EINVAL;
 
-	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
+	counter = devm_counter_alloc(&pdev->dev, sizeof(*priv));
+	if (!counter)
 		return -ENOMEM;
+	priv = counter_priv(counter);
 
 	priv->dev = &pdev->dev;
 	priv->regmap = ddata->regmap;
@@ -426,23 +428,26 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev)
 	priv->ceiling = STM32_LPTIM_MAX_ARR;
 
 	/* Initialize Counter device */
-	priv->counter.name = dev_name(&pdev->dev);
-	priv->counter.parent = &pdev->dev;
-	priv->counter.ops = &stm32_lptim_cnt_ops;
+	counter->name = dev_name(&pdev->dev);
+	counter->parent = &pdev->dev;
+	counter->ops = &stm32_lptim_cnt_ops;
 	if (ddata->has_encoder) {
-		priv->counter.counts = &stm32_lptim_enc_counts;
-		priv->counter.num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
+		counter->counts = &stm32_lptim_enc_counts;
+		counter->num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
 	} else {
-		priv->counter.counts = &stm32_lptim_in1_counts;
-		priv->counter.num_signals = 1;
+		counter->counts = &stm32_lptim_in1_counts;
+		counter->num_signals = 1;
 	}
-	priv->counter.num_counts = 1;
-	priv->counter.signals = stm32_lptim_cnt_signals;
-	priv->counter.priv = priv;
+	counter->num_counts = 1;
+	counter->signals = stm32_lptim_cnt_signals;
 
 	platform_set_drvdata(pdev, priv);
 
-	return devm_counter_register(&pdev->dev, &priv->counter);
+	ret = devm_counter_add(&pdev->dev, counter);
+	if (ret < 0)
+		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
+
+	return 0;
 }
 
 #ifdef CONFIG_PM_SLEEP
-- 
2.33.0


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

* [PATCH v2 21/23] counter: stm32-lptimer-cnt: Convert to new counter registration
@ 2021-12-27  9:45   ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, Benjamin Gaignard,
	linux-stm32, linux-arm-kernel

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: 597f55e3f36c ("counter: stm32-lptimer: add counter device")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/stm32-lptimer-cnt.c | 33 +++++++++++++++++------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
index 9cf00e929cc0..68031d93ce89 100644
--- a/drivers/counter/stm32-lptimer-cnt.c
+++ b/drivers/counter/stm32-lptimer-cnt.c
@@ -20,7 +20,6 @@
 #include <linux/types.h>
 
 struct stm32_lptim_cnt {
-	struct counter_device counter;
 	struct device *dev;
 	struct regmap *regmap;
 	struct clk *clk;
@@ -411,14 +410,17 @@ static struct counter_count stm32_lptim_in1_counts = {
 static int stm32_lptim_cnt_probe(struct platform_device *pdev)
 {
 	struct stm32_lptimer *ddata = dev_get_drvdata(pdev->dev.parent);
+	struct counter_device *counter;
 	struct stm32_lptim_cnt *priv;
+	int ret;
 
 	if (IS_ERR_OR_NULL(ddata))
 		return -EINVAL;
 
-	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
+	counter = devm_counter_alloc(&pdev->dev, sizeof(*priv));
+	if (!counter)
 		return -ENOMEM;
+	priv = counter_priv(counter);
 
 	priv->dev = &pdev->dev;
 	priv->regmap = ddata->regmap;
@@ -426,23 +428,26 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev)
 	priv->ceiling = STM32_LPTIM_MAX_ARR;
 
 	/* Initialize Counter device */
-	priv->counter.name = dev_name(&pdev->dev);
-	priv->counter.parent = &pdev->dev;
-	priv->counter.ops = &stm32_lptim_cnt_ops;
+	counter->name = dev_name(&pdev->dev);
+	counter->parent = &pdev->dev;
+	counter->ops = &stm32_lptim_cnt_ops;
 	if (ddata->has_encoder) {
-		priv->counter.counts = &stm32_lptim_enc_counts;
-		priv->counter.num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
+		counter->counts = &stm32_lptim_enc_counts;
+		counter->num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
 	} else {
-		priv->counter.counts = &stm32_lptim_in1_counts;
-		priv->counter.num_signals = 1;
+		counter->counts = &stm32_lptim_in1_counts;
+		counter->num_signals = 1;
 	}
-	priv->counter.num_counts = 1;
-	priv->counter.signals = stm32_lptim_cnt_signals;
-	priv->counter.priv = priv;
+	counter->num_counts = 1;
+	counter->signals = stm32_lptim_cnt_signals;
 
 	platform_set_drvdata(pdev, priv);
 
-	return devm_counter_register(&pdev->dev, &priv->counter);
+	ret = devm_counter_add(&pdev->dev, counter);
+	if (ret < 0)
+		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
+
+	return 0;
 }
 
 #ifdef CONFIG_PM_SLEEP
-- 
2.33.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 22/23] counter: ti-eqep: Convert to new counter registration
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (21 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 18:29   ` Jonathan Cameron
  2021-12-29  8:41   ` William Breathitt Gray
  -1 siblings, 2 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, David Lechner

This fixes device lifetime issues where it was possible to free a live
struct device.

Fixes: f213729f6796 ("counter: new TI eQEP driver")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/ti-eqep.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
index abeda966e7be..3b49b492d182 100644
--- a/drivers/counter/ti-eqep.c
+++ b/drivers/counter/ti-eqep.c
@@ -368,13 +368,15 @@ static const struct regmap_config ti_eqep_regmap16_config = {
 static int ti_eqep_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
+	struct counter_device *counter;
 	struct ti_eqep_cnt *priv;
 	void __iomem *base;
 	int err;
 
-	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
+	counter = devm_counter_alloc(dev, sizeof(*priv));
+	if (!counter)
 		return -ENOMEM;
+	priv = counter_priv(counter);
 
 	base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(base))
@@ -390,16 +392,15 @@ static int ti_eqep_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->regmap16))
 		return PTR_ERR(priv->regmap16);
 
-	priv->counter.name = dev_name(dev);
-	priv->counter.parent = dev;
-	priv->counter.ops = &ti_eqep_counter_ops;
-	priv->counter.counts = ti_eqep_counts;
-	priv->counter.num_counts = ARRAY_SIZE(ti_eqep_counts);
-	priv->counter.signals = ti_eqep_signals;
-	priv->counter.num_signals = ARRAY_SIZE(ti_eqep_signals);
-	priv->counter.priv = priv;
+	counter->name = dev_name(dev);
+	counter->parent = dev;
+	counter->ops = &ti_eqep_counter_ops;
+	counter->counts = ti_eqep_counts;
+	counter->num_counts = ARRAY_SIZE(ti_eqep_counts);
+	counter->signals = ti_eqep_signals;
+	counter->num_signals = ARRAY_SIZE(ti_eqep_signals);
 
-	platform_set_drvdata(pdev, priv);
+	platform_set_drvdata(pdev, counter);
 
 	/*
 	 * Need to make sure power is turned on. On AM33xx, this comes from the
@@ -409,7 +410,7 @@ static int ti_eqep_probe(struct platform_device *pdev)
 	pm_runtime_enable(dev);
 	pm_runtime_get_sync(dev);
 
-	err = counter_register(&priv->counter);
+	err = counter_add(counter);
 	if (err < 0) {
 		pm_runtime_put_sync(dev);
 		pm_runtime_disable(dev);
@@ -421,10 +422,10 @@ static int ti_eqep_probe(struct platform_device *pdev)
 
 static int ti_eqep_remove(struct platform_device *pdev)
 {
-	struct ti_eqep_cnt *priv = platform_get_drvdata(pdev);
+	struct counter_device *counter = platform_get_drvdata(pdev);
 	struct device *dev = &pdev->dev;
 
-	counter_unregister(&priv->counter);
+	counter_unregister(counter);
 	pm_runtime_put_sync(dev);
 	pm_runtime_disable(dev);
 
-- 
2.33.0


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

* [PATCH v2 23/23] counter: remove old and now unused registration API
  2021-12-27  9:45 ` Uwe Kleine-König
                   ` (22 preceding siblings ...)
  (?)
@ 2021-12-27  9:45 ` Uwe Kleine-König
  2021-12-28 18:31   ` Jonathan Cameron
  2021-12-29  8:43   ` William Breathitt Gray
  -1 siblings, 2 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27  9:45 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel

Usage of counter_register() yields issues in device lifetime tracking. All
drivers were converted to the new API, so the old one can go away.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/counter/counter-core.c | 97 ++--------------------------------
 include/linux/counter.h        | 12 -----
 2 files changed, 4 insertions(+), 105 deletions(-)

diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
index 8261567b6272..3f7dc5718423 100644
--- a/drivers/counter/counter-core.c
+++ b/drivers/counter/counter-core.c
@@ -38,8 +38,7 @@ static void counter_device_release(struct device *dev)
 	counter_chrdev_remove(counter);
 	ida_free(&counter_ida, dev->id);
 
-	if (!counter->legacy_device)
-		kfree(container_of(counter, struct counter_device_allochelper, counter));
+	kfree(container_of(counter, struct counter_device_allochelper, counter));
 }
 
 static struct device_type counter_device_type = {
@@ -62,76 +61,13 @@ static dev_t counter_devt;
  */
 void *counter_priv(const struct counter_device *const counter)
 {
-	if (counter->legacy_device) {
-		return counter->priv;
-	} else {
-		struct counter_device_allochelper *ch =
-			container_of(counter, struct counter_device_allochelper, counter);
+	struct counter_device_allochelper *ch =
+		container_of(counter, struct counter_device_allochelper, counter);
 
-		return &ch->privdata;
-	}
+	return &ch->privdata;
 }
 EXPORT_SYMBOL_GPL(counter_priv);
 
-/**
- * counter_register - register Counter to the system
- * @counter:	pointer to Counter to register
- *
- * This function registers a Counter to the system. A sysfs "counter" directory
- * will be created and populated with sysfs attributes correlating with the
- * Counter Signals, Synapses, and Counts respectively.
- *
- * RETURNS:
- * 0 on success, negative error number on failure.
- */
-int counter_register(struct counter_device *const counter)
-{
-	struct device *const dev = &counter->dev;
-	int id;
-	int err;
-
-	counter->legacy_device = true;
-
-	/* Acquire unique ID */
-	id = ida_alloc(&counter_ida, GFP_KERNEL);
-	if (id < 0)
-		return id;
-
-	mutex_init(&counter->ops_exist_lock);
-
-	/* Configure device structure for Counter */
-	dev->id = id;
-	dev->type = &counter_device_type;
-	dev->bus = &counter_bus_type;
-	dev->devt = MKDEV(MAJOR(counter_devt), id);
-	if (counter->parent) {
-		dev->parent = counter->parent;
-		dev->of_node = counter->parent->of_node;
-	}
-	device_initialize(dev);
-
-	err = counter_sysfs_add(counter);
-	if (err < 0)
-		goto err_free_id;
-
-	err = counter_chrdev_add(counter);
-	if (err < 0)
-		goto err_free_id;
-
-	err = cdev_device_add(&counter->chrdev, dev);
-	if (err < 0)
-		goto err_remove_chrdev;
-
-	return 0;
-
-err_remove_chrdev:
-	counter_chrdev_remove(counter);
-err_free_id:
-	put_device(dev);
-	return err;
-}
-EXPORT_SYMBOL_GPL(counter_register);
-
 /**
  * counter_alloc - allocate a counter_device
  * @sizeof_priv: size of the driver private data
@@ -255,31 +191,6 @@ static void devm_counter_release(void *counter)
 	counter_unregister(counter);
 }
 
-/**
- * devm_counter_register - Resource-managed counter_register
- * @dev:	device to allocate counter_device for
- * @counter:	pointer to Counter to register
- *
- * Managed counter_register. The Counter registered with this function is
- * automatically unregistered on driver detach. This function calls
- * counter_register internally. Refer to that function for more information.
- *
- * RETURNS:
- * 0 on success, negative error number on failure.
- */
-int devm_counter_register(struct device *dev,
-			  struct counter_device *const counter)
-{
-	int err;
-
-	err = counter_register(counter);
-	if (err < 0)
-		return err;
-
-	return devm_add_action_or_reset(dev, devm_counter_release, counter);
-}
-EXPORT_SYMBOL_GPL(devm_counter_register);
-
 static void devm_counter_put(void *counter)
 {
 	counter_put(counter);
diff --git a/include/linux/counter.h b/include/linux/counter.h
index f1350a43cd48..9afa0f1e9cea 100644
--- a/include/linux/counter.h
+++ b/include/linux/counter.h
@@ -314,8 +314,6 @@ struct counter_device {
 	struct counter_comp *ext;
 	size_t num_ext;
 
-	void *priv;
-
 	struct device dev;
 	struct cdev chrdev;
 	struct list_head events_list;
@@ -327,25 +325,15 @@ struct counter_device {
 	spinlock_t events_in_lock;
 	struct mutex events_out_lock;
 	struct mutex ops_exist_lock;
-
-	/*
-	 * This can go away once all drivers are converted to
-	 * counter_alloc()/counter_add().
-	 */
-	bool legacy_device;
 };
 
 void *counter_priv(const struct counter_device *const counter);
 
-int counter_register(struct counter_device *const counter);
-
 struct counter_device *counter_alloc(size_t sizeof_priv);
 void counter_put(struct counter_device *const counter);
 int counter_add(struct counter_device *const counter);
 
 void counter_unregister(struct counter_device *const counter);
-int devm_counter_register(struct device *dev,
-			  struct counter_device *const counter);
 struct counter_device *devm_counter_alloc(struct device *dev,
 					  size_t sizeof_priv);
 int devm_counter_add(struct device *dev,
-- 
2.33.0


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

* Re: [PATCH v2 16/23] counter: interrupt-cnt: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 16/23] counter: interrupt-cnt: " Uwe Kleine-König
@ 2021-12-27 10:59   ` Greg Kroah-Hartman
  2021-12-27 11:21     ` Lars-Peter Clausen
  2021-12-28 18:18   ` Jonathan Cameron
  2021-12-29  8:27   ` William Breathitt Gray
  2 siblings, 1 reply; 125+ messages in thread
From: Greg Kroah-Hartman @ 2021-12-27 10:59 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, linux-kernel, Ahmad Fatoum,
	Oleksij Rempel

On Mon, Dec 27, 2021 at 10:45:19AM +0100, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: a55ebd47f21f ("counter: add IRQ or GPIO based counter")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/counter/interrupt-cnt.c | 28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c
> index 4bf706ef46e2..9e99702470c2 100644
> --- a/drivers/counter/interrupt-cnt.c
> +++ b/drivers/counter/interrupt-cnt.c
> @@ -16,7 +16,6 @@
>  
>  struct interrupt_cnt_priv {
>  	atomic_t count;
> -	struct counter_device counter;
>  	struct gpio_desc *gpio;
>  	int irq;
>  	bool enabled;
> @@ -148,12 +147,14 @@ static const struct counter_ops interrupt_cnt_ops = {
>  static int interrupt_cnt_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> +	struct counter_device *counter;
>  	struct interrupt_cnt_priv *priv;
>  	int ret;
>  
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(dev, sizeof(*priv));

I just picked one of these patches at random, nothing specific about
this driver...

You can not have a 'struct device' in memory allocated by devm_*()
functions for the obvious reason that now that memory is being
controlled by a reference count that is OUTSIDE of the structure itself.

So while your goal might be good here, this is not the correct solution
at all, sorry.

thanks,

greg k-h

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

* Re: [PATCH v2 04/23] counter: Provide a wrapper to access device private data
  2021-12-27  9:45 ` [PATCH v2 04/23] counter: Provide a wrapper to access device private data Uwe Kleine-König
@ 2021-12-27 11:02   ` Greg Kroah-Hartman
  2021-12-27 11:34     ` Lars-Peter Clausen
  2021-12-28 18:01   ` Jonathan Cameron
  2021-12-29  6:47   ` William Breathitt Gray
  2 siblings, 1 reply; 125+ messages in thread
From: Greg Kroah-Hartman @ 2021-12-27 11:02 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, linux-kernel

On Mon, Dec 27, 2021 at 10:45:07AM +0100, Uwe Kleine-König wrote:
> For now this just wraps accessing struct counter_device::priv. However
> this is about to change and converting drivers to this helper
> individually makes fixing device lifetime issues result in easier to
> review patches.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/counter/counter-core.c | 12 ++++++++++++
>  include/linux/counter.h        |  2 ++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> index f053a43c6c04..00c41f28c101 100644
> --- a/drivers/counter/counter-core.c
> +++ b/drivers/counter/counter-core.c
> @@ -45,6 +45,18 @@ static struct bus_type counter_bus_type = {
>  
>  static dev_t counter_devt;
>  
> +/**
> + * counter_priv - access counter device private data
> + * @counter: counter device
> + *
> + * Get the counter device private data
> + */
> +void *counter_priv(const struct counter_device *const counter)
> +{
> +	return counter->priv;
> +}
> +EXPORT_SYMBOL_GPL(counter_priv);

Shouldn't this be usin gdev_get_drvdata() and using the private data
pointer that is already on the struct device structure itself?  The void
*priv; should be dropped from struct counter_device entirely.

Oh ick, I just now looked at 'struct counter_device', there are other
reference counting issues in there (hint, struct cdev has a reference
count...)  But that's independent of this patch series...

thanks,

greg k-h

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

* Re: [PATCH v2 16/23] counter: interrupt-cnt: Convert to new counter registration
  2021-12-27 10:59   ` Greg Kroah-Hartman
@ 2021-12-27 11:21     ` Lars-Peter Clausen
  2021-12-27 11:34       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 125+ messages in thread
From: Lars-Peter Clausen @ 2021-12-27 11:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Uwe Kleine-König
  Cc: William Breathitt Gray, kernel, Jonathan Cameron, linux-iio,
	linux-kernel, Ahmad Fatoum, Oleksij Rempel

On 12/27/21 11:59 AM, Greg Kroah-Hartman wrote:
> On Mon, Dec 27, 2021 at 10:45:19AM +0100, Uwe Kleine-König wrote:
>> This fixes device lifetime issues where it was possible to free a live
>> struct device.
>>
>> Fixes: a55ebd47f21f ("counter: add IRQ or GPIO based counter")
>> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>> ---
>>   drivers/counter/interrupt-cnt.c | 28 ++++++++++++++++------------
>>   1 file changed, 16 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c
>> index 4bf706ef46e2..9e99702470c2 100644
>> --- a/drivers/counter/interrupt-cnt.c
>> +++ b/drivers/counter/interrupt-cnt.c
>> @@ -16,7 +16,6 @@
>>   
>>   struct interrupt_cnt_priv {
>>   	atomic_t count;
>> -	struct counter_device counter;
>>   	struct gpio_desc *gpio;
>>   	int irq;
>>   	bool enabled;
>> @@ -148,12 +147,14 @@ static const struct counter_ops interrupt_cnt_ops = {
>>   static int interrupt_cnt_probe(struct platform_device *pdev)
>>   {
>>   	struct device *dev = &pdev->dev;
>> +	struct counter_device *counter;
>>   	struct interrupt_cnt_priv *priv;
>>   	int ret;
>>   
>> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>> -	if (!priv)
>> +	counter = devm_counter_alloc(dev, sizeof(*priv));
> I just picked one of these patches at random, nothing specific about
> this driver...
>
> You can not have a 'struct device' in memory allocated by devm_*()
> functions for the obvious reason that now that memory is being
> controlled by a reference count that is OUTSIDE of the structure itself.
>
> So while your goal might be good here, this is not the correct solution
> at all, sorry.

Before this patch the memory for the struct device was devm_kzalloc'ed. 
Which as you point out is a bug.

After this patch the memory is reference counted and will be freed when 
the last reference is dropped, in the release callback of the struct device.

The alloc function is still a devm_ function, but on 'free' it will only 
drop the reference to the struct device that it holds. This is a very 
common pattern that is used by basically any driver subsystem in the kernel.

This is the correct solution to the problem.


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

* Re: [PATCH v2 16/23] counter: interrupt-cnt: Convert to new counter registration
  2021-12-27 11:21     ` Lars-Peter Clausen
@ 2021-12-27 11:34       ` Greg Kroah-Hartman
  2021-12-27 11:44         ` Lars-Peter Clausen
  2021-12-27 21:09         ` Uwe Kleine-König
  0 siblings, 2 replies; 125+ messages in thread
From: Greg Kroah-Hartman @ 2021-12-27 11:34 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Uwe Kleine-König, William Breathitt Gray, kernel,
	Jonathan Cameron, linux-iio, linux-kernel, Ahmad Fatoum,
	Oleksij Rempel

On Mon, Dec 27, 2021 at 12:21:14PM +0100, Lars-Peter Clausen wrote:
> On 12/27/21 11:59 AM, Greg Kroah-Hartman wrote:
> > On Mon, Dec 27, 2021 at 10:45:19AM +0100, Uwe Kleine-König wrote:
> > > This fixes device lifetime issues where it was possible to free a live
> > > struct device.
> > > 
> > > Fixes: a55ebd47f21f ("counter: add IRQ or GPIO based counter")
> > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > ---
> > >   drivers/counter/interrupt-cnt.c | 28 ++++++++++++++++------------
> > >   1 file changed, 16 insertions(+), 12 deletions(-)
> > > 
> > > diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c
> > > index 4bf706ef46e2..9e99702470c2 100644
> > > --- a/drivers/counter/interrupt-cnt.c
> > > +++ b/drivers/counter/interrupt-cnt.c
> > > @@ -16,7 +16,6 @@
> > >   struct interrupt_cnt_priv {
> > >   	atomic_t count;
> > > -	struct counter_device counter;
> > >   	struct gpio_desc *gpio;
> > >   	int irq;
> > >   	bool enabled;
> > > @@ -148,12 +147,14 @@ static const struct counter_ops interrupt_cnt_ops = {
> > >   static int interrupt_cnt_probe(struct platform_device *pdev)
> > >   {
> > >   	struct device *dev = &pdev->dev;
> > > +	struct counter_device *counter;
> > >   	struct interrupt_cnt_priv *priv;
> > >   	int ret;
> > > -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> > > -	if (!priv)
> > > +	counter = devm_counter_alloc(dev, sizeof(*priv));
> > I just picked one of these patches at random, nothing specific about
> > this driver...
> > 
> > You can not have a 'struct device' in memory allocated by devm_*()
> > functions for the obvious reason that now that memory is being
> > controlled by a reference count that is OUTSIDE of the structure itself.
> > 
> > So while your goal might be good here, this is not the correct solution
> > at all, sorry.
> 
> Before this patch the memory for the struct device was devm_kzalloc'ed.
> Which as you point out is a bug.
> 
> After this patch the memory is reference counted and will be freed when the
> last reference is dropped, in the release callback of the struct device.
> 
> The alloc function is still a devm_ function, but on 'free' it will only
> drop the reference to the struct device that it holds. This is a very common
> pattern that is used by basically any driver subsystem in the kernel.

Then it is not a real devm_() call, let's not call it that please as it
is obviously very confusing :)

Just call it counter_alloc(), or , counter_create(), or something a bit
more in line with the rest of all driver subsystems.

thanks,

greg k-h

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

* Re: [PATCH v2 04/23] counter: Provide a wrapper to access device private data
  2021-12-27 11:02   ` Greg Kroah-Hartman
@ 2021-12-27 11:34     ` Lars-Peter Clausen
  2021-12-27 11:52       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 125+ messages in thread
From: Lars-Peter Clausen @ 2021-12-27 11:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Uwe Kleine-König
  Cc: William Breathitt Gray, kernel, Jonathan Cameron, linux-iio,
	linux-kernel

On 12/27/21 12:02 PM, Greg Kroah-Hartman wrote:
> On Mon, Dec 27, 2021 at 10:45:07AM +0100, Uwe Kleine-König wrote:
>> For now this just wraps accessing struct counter_device::priv. However
>> this is about to change and converting drivers to this helper
>> individually makes fixing device lifetime issues result in easier to
>> review patches.
>>
>> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>> ---
>>   drivers/counter/counter-core.c | 12 ++++++++++++
>>   include/linux/counter.h        |  2 ++
>>   2 files changed, 14 insertions(+)
>>
>> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
>> index f053a43c6c04..00c41f28c101 100644
>> --- a/drivers/counter/counter-core.c
>> +++ b/drivers/counter/counter-core.c
>> @@ -45,6 +45,18 @@ static struct bus_type counter_bus_type = {
>>   
>>   static dev_t counter_devt;
>>   
>> +/**
>> + * counter_priv - access counter device private data
>> + * @counter: counter device
>> + *
>> + * Get the counter device private data
>> + */
>> +void *counter_priv(const struct counter_device *const counter)
>> +{
>> +	return counter->priv;
>> +}
>> +EXPORT_SYMBOL_GPL(counter_priv);
> Shouldn't this be usin gdev_get_drvdata() and using the private data
> pointer that is already on the struct device structure itself?  The void
> *priv; should be dropped from struct counter_device entirely.
>
> Oh ick, I just now looked at 'struct counter_device', there are other
> reference counting issues in there (hint, struct cdev has a reference
> count...)  But that's independent of this patch series...
This is not a problem. The struct cdev holds a reference to the struct 
dev. This allows them to use the same allocation. As long as there is a 
reference to the cdev there will be a reference to the dev and the 
memory will be kept alive.

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

* Re: [PATCH v2 16/23] counter: interrupt-cnt: Convert to new counter registration
  2021-12-27 11:34       ` Greg Kroah-Hartman
@ 2021-12-27 11:44         ` Lars-Peter Clausen
  2021-12-27 21:09         ` Uwe Kleine-König
  1 sibling, 0 replies; 125+ messages in thread
From: Lars-Peter Clausen @ 2021-12-27 11:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Uwe Kleine-König, William Breathitt Gray, kernel,
	Jonathan Cameron, linux-iio, linux-kernel, Ahmad Fatoum,
	Oleksij Rempel

On 12/27/21 12:34 PM, Greg Kroah-Hartman wrote:
> On Mon, Dec 27, 2021 at 12:21:14PM +0100, Lars-Peter Clausen wrote:
>> On 12/27/21 11:59 AM, Greg Kroah-Hartman wrote:
>>> On Mon, Dec 27, 2021 at 10:45:19AM +0100, Uwe Kleine-König wrote:
>>>> This fixes device lifetime issues where it was possible to free a live
>>>> struct device.
>>>>
>>>> Fixes: a55ebd47f21f ("counter: add IRQ or GPIO based counter")
>>>> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>>>> ---
>>>>    drivers/counter/interrupt-cnt.c | 28 ++++++++++++++++------------
>>>>    1 file changed, 16 insertions(+), 12 deletions(-)
>>>>
>>>> diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c
>>>> index 4bf706ef46e2..9e99702470c2 100644
>>>> --- a/drivers/counter/interrupt-cnt.c
>>>> +++ b/drivers/counter/interrupt-cnt.c
>>>> @@ -16,7 +16,6 @@
>>>>    struct interrupt_cnt_priv {
>>>>    	atomic_t count;
>>>> -	struct counter_device counter;
>>>>    	struct gpio_desc *gpio;
>>>>    	int irq;
>>>>    	bool enabled;
>>>> @@ -148,12 +147,14 @@ static const struct counter_ops interrupt_cnt_ops = {
>>>>    static int interrupt_cnt_probe(struct platform_device *pdev)
>>>>    {
>>>>    	struct device *dev = &pdev->dev;
>>>> +	struct counter_device *counter;
>>>>    	struct interrupt_cnt_priv *priv;
>>>>    	int ret;
>>>> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>>>> -	if (!priv)
>>>> +	counter = devm_counter_alloc(dev, sizeof(*priv));
>>> I just picked one of these patches at random, nothing specific about
>>> this driver...
>>>
>>> You can not have a 'struct device' in memory allocated by devm_*()
>>> functions for the obvious reason that now that memory is being
>>> controlled by a reference count that is OUTSIDE of the structure itself.
>>>
>>> So while your goal might be good here, this is not the correct solution
>>> at all, sorry.
>> Before this patch the memory for the struct device was devm_kzalloc'ed.
>> Which as you point out is a bug.
>>
>> After this patch the memory is reference counted and will be freed when the
>> last reference is dropped, in the release callback of the struct device.
>>
>> The alloc function is still a devm_ function, but on 'free' it will only
>> drop the reference to the struct device that it holds. This is a very common
>> pattern that is used by basically any driver subsystem in the kernel.
> Then it is not a real devm_() call, let's not call it that please as it
> is obviously very confusing :)
>
> Just call it counter_alloc(), or , counter_create(), or something a bit
> more in line with the rest of all driver subsystems.

But all the other driver subsystems call this kind of function devm_... :)

Usually for everything you call in probe() you need a corresponding 
action in remove(). With the devm_... function is remove action will be 
automatically called.


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

* Re: [PATCH v2 04/23] counter: Provide a wrapper to access device private data
  2021-12-27 11:34     ` Lars-Peter Clausen
@ 2021-12-27 11:52       ` Greg Kroah-Hartman
  2021-12-27 12:28         ` Lars-Peter Clausen
  0 siblings, 1 reply; 125+ messages in thread
From: Greg Kroah-Hartman @ 2021-12-27 11:52 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Uwe Kleine-König, William Breathitt Gray, kernel,
	Jonathan Cameron, linux-iio, linux-kernel

On Mon, Dec 27, 2021 at 12:34:28PM +0100, Lars-Peter Clausen wrote:
> On 12/27/21 12:02 PM, Greg Kroah-Hartman wrote:
> > On Mon, Dec 27, 2021 at 10:45:07AM +0100, Uwe Kleine-König wrote:
> > > For now this just wraps accessing struct counter_device::priv. However
> > > this is about to change and converting drivers to this helper
> > > individually makes fixing device lifetime issues result in easier to
> > > review patches.
> > > 
> > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > ---
> > >   drivers/counter/counter-core.c | 12 ++++++++++++
> > >   include/linux/counter.h        |  2 ++
> > >   2 files changed, 14 insertions(+)
> > > 
> > > diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> > > index f053a43c6c04..00c41f28c101 100644
> > > --- a/drivers/counter/counter-core.c
> > > +++ b/drivers/counter/counter-core.c
> > > @@ -45,6 +45,18 @@ static struct bus_type counter_bus_type = {
> > >   static dev_t counter_devt;
> > > +/**
> > > + * counter_priv - access counter device private data
> > > + * @counter: counter device
> > > + *
> > > + * Get the counter device private data
> > > + */
> > > +void *counter_priv(const struct counter_device *const counter)
> > > +{
> > > +	return counter->priv;
> > > +}
> > > +EXPORT_SYMBOL_GPL(counter_priv);
> > Shouldn't this be usin gdev_get_drvdata() and using the private data
> > pointer that is already on the struct device structure itself?  The void
> > *priv; should be dropped from struct counter_device entirely.
> > 
> > Oh ick, I just now looked at 'struct counter_device', there are other
> > reference counting issues in there (hint, struct cdev has a reference
> > count...)  But that's independent of this patch series...
> This is not a problem. The struct cdev holds a reference to the struct dev.
> This allows them to use the same allocation. As long as there is a reference
> to the cdev there will be a reference to the dev and the memory will be kept
> alive.

Ick, a cdev shouldn't be doing stuff like that, but I see how people
like to use it that way :(

Ok, it's fine for now, but yet-another-reaason why the cdev api is a
mess in places...

thanks,

greg k-h

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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
  2021-12-27  9:45 ` [PATCH v2 13/23] counter: Provide alternative counter registration functions Uwe Kleine-König
@ 2021-12-27 12:16   ` Lars-Peter Clausen
  2021-12-28 11:22     ` Uwe Kleine-König
  2021-12-27 12:18     ` kernel test robot
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 125+ messages in thread
From: Lars-Peter Clausen @ 2021-12-27 12:16 UTC (permalink / raw)
  To: Uwe Kleine-König, William Breathitt Gray
  Cc: kernel, Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel

On 12/27/21 10:45 AM, Uwe Kleine-König wrote:
> The current implementation gets device lifetime tracking wrong. The
> problem is that allocation of struct counter_device is controlled by the
> individual drivers but this structure contains a struct device that
> might have to live longer than a driver is bound. As a result a command
> sequence like:
>
> 	{ sleep 5; echo bang; } > /dev/counter0 &
> 	sleep 1;
> 	echo 40000000.timer:counter > /sys/bus/platform/drivers/stm32-timer-counter/unbind
>
> can keep a reference to the struct device and unbinding results in
> freeing the memory occupied by this device resulting in an oops.
>
> This commit provides two new functions (plus some helpers):
>   - counter_alloc() to allocate a struct counter_device that is
>     automatically freed once the embedded struct device is released
>   - counter_add() to register such a device.
>
> Note that this commit doesn't fix any issues, all drivers have to be
> converted to these new functions to correct the lifetime problems.
Nice work!


> [...]
> @@ -24,6 +25,11 @@
>   /* Provides a unique ID for each counter device */
>   static DEFINE_IDA(counter_ida);
>   
> +struct counter_device_allochelper {
> +	struct counter_device counter;
> +	unsigned long privdata[];

The normal k*alloc functions guarantee that the allocation is cacheline 
aligned. Without that for example the ____cacheline_aligned attribute 
will not work correctly. And while it is unlikely that a counter driver 
will need for example DMA memory I think it is still good practice to 
guarantee this here to avoid bad surprises. There are two ways of doing 
this.

Make privdata ____cacheline_aligned like in the memstick framework[1]. 
The downside is that this will reserve padding for the allocation, even 
if no private data is allocated.

The alternative is to do something similar to IIO[2] which only 
allocates the padding if there actually is any private data requested. 
The disadvantage of that is that the code is a bit more cumbersome. And 
most drivers will want to have some private data anyway so it might not 
be worth it.

[1] 
https://elixir.bootlin.com/linux/v5.16-rc7/source/include/linux/memstick.h#L292
[2] 
https://elixir.bootlin.com/linux/v5.16-rc7/source/drivers/iio/industrialio-core.c#L1638

> [...]
> +struct counter_device *counter_alloc(size_t sizeof_priv)
I'd add a parent parameter here since with the devm_ variant we have to 
pass it anyway and this allows to slightly reduce the boilerplate code 
in the driver where the parent field of the counter has to be initialized.
> +{
> +	struct counter_device_allochelper *ch;
> +	struct counter_device *counter;
> +	struct device *dev;
> +	int id, err;
> +
> +	ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
> +	if (!ch) {
> +		err = -ENOMEM;
> +		goto err_alloc_ch;
> +	}
> +
> +	counter = &ch->counter;
> +	dev = &counter->dev;
> +
> +	/* Acquire unique ID */
> +	err = ida_alloc(&counter_ida, GFP_KERNEL);
> +	if (err < 0) {
> +		goto err_ida_alloc;
> +	}
There is a inconsistency whether braces are used for single statement 
`if`s in this patch.
> +	dev->id = err;
> +
> +	err = counter_chrdev_add(counter);
> +	if (err < 0)
> +		goto err_chrdev_add;
> +
> +	device_initialize(dev);
> +	/* Configure device structure for Counter */
> +	dev->type = &counter_device_type;
> +	dev->bus = &counter_bus_type;
> +	dev->devt = MKDEV(MAJOR(counter_devt), id);
> +
> +	mutex_init(&counter->ops_exist_lock);
> +
> +	return counter;
> +
> +err_chrdev_add:
> +
> +	ida_free(&counter_ida, dev->id);
> +err_ida_alloc:
> +
> +	kfree(ch);
> +err_alloc_ch:
> +
> +	return ERR_PTR(err);
> +}
> +EXPORT_SYMBOL_GPL(counter_alloc);
> +
> +void counter_put(struct counter_device *counter)
> +{
> +	put_device(&counter->dev);
> +}
> +
> +/**
> + * counter_add - complete registration of a counter
> + * @counter: the counter to add
> + *
> + * This is part two of counter registration.
> + *
> + * If this succeeds, call counter_unregister() to get rid of the counter_device again.
> + */
> +int counter_add(struct counter_device *counter)
> +{
> +	int err;
> +	struct device *dev = &counter->dev;
> +
> +	get_device(&counter->dev);

This get_device() is not needed. device_add() will also add a reference, 
so you increment the reference count by 2 when calling counter_add().

It is only needed to balance the put_device() in counter_unregister(). 
I'd add a `counter->legacy_device` around that put_device() and then 
remove it in the last patch.

The extra get_device() here is also leaked on the error paths, so 
removing it will allow to keep the errors paths as they are.

> +
> +	if (counter->parent) {
> +		dev->parent = counter->parent;
> +		dev->of_node = counter->parent->of_node;
> +	}
> +
> +	err = counter_sysfs_add(counter);
> +	if (err < 0)
> +		return err;
> +
> +	/* implies device_add(dev) */
> +	err = cdev_device_add(&counter->chrdev, dev);
> +
> +	return err;
return cdev_device_add(...).
> +struct counter_device *devm_counter_alloc(struct device *dev, size_t sizeof_priv)
API Documentation?
> +{
> +	struct counter_device *counter;
> +	int err;
> +
> +	counter = counter_alloc(sizeof_priv);
> +	if (IS_ERR(counter))
> +		return counter;
> +
> +	err = devm_add_action_or_reset(dev, devm_counter_put, counter);
> +	if (err < 0)
> +		return ERR_PTR(err);
> +
> +	return counter;
> +}
> +EXPORT_SYMBOL_GPL(devm_counter_alloc);
> +
> +int devm_counter_add(struct device *dev,
> +		     struct counter_device *const counter)
> +{
API Documentation?
> +	int err;
> +
> +	err = counter_add(counter);
> +	if (err < 0)
> +		return err;
> +
> +	return devm_add_action_or_reset(dev, devm_counter_release, counter);
> +}
> +EXPORT_SYMBOL_GPL(devm_counter_add);
> +
>   #define COUNTER_DEV_MAX 256
>   


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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
  2021-12-27  9:45 ` [PATCH v2 13/23] counter: Provide alternative counter registration functions Uwe Kleine-König
@ 2021-12-27 12:18     ` kernel test robot
  2021-12-27 12:18     ` kernel test robot
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 125+ messages in thread
From: kernel test robot @ 2021-12-27 12:18 UTC (permalink / raw)
  To: Uwe Kleine-König, William Breathitt Gray
  Cc: llvm, kbuild-all, Lars-Peter Clausen, kernel, Jonathan Cameron,
	linux-iio, Greg Kroah-Hartman, linux-kernel

Hi "Uwe,

I love your patch! Perhaps something to improve:

[auto build test WARNING on a7904a538933c525096ca2ccde1e60d0ee62c08e]

url:    https://github.com/0day-ci/linux/commits/Uwe-Kleine-K-nig/counter-cleanups-and-device-lifetime-fixes/20211227-174815
base:   a7904a538933c525096ca2ccde1e60d0ee62c08e
config: i386-randconfig-r006-20211227 (https://download.01.org/0day-ci/archive/20211227/202112272054.WsrEZBF1-lkp@intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 511726c64d3b6cca66f7c54d457d586aa3129f67)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/250e0e3d91caea9f7c61652a7a9a8c006b2464be
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Uwe-Kleine-K-nig/counter-cleanups-and-device-lifetime-fixes/20211227-174815
        git checkout 250e0e3d91caea9f7c61652a7a9a8c006b2464be
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/counter/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/counter/counter-core.c:175:41: warning: variable 'id' is uninitialized when used here [-Wuninitialized]
           dev->devt = MKDEV(MAJOR(counter_devt), id);
                                                  ^~
   include/linux/kdev_t.h:12:46: note: expanded from macro 'MKDEV'
   #define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
                                                   ^~
   drivers/counter/counter-core.c:149:8: note: initialize the variable 'id' to silence this warning
           int id, err;
                 ^
                  = 0
   1 warning generated.


vim +/id +175 drivers/counter/counter-core.c

   134	
   135	/**
   136	 * counter_alloc - allocate a counter_device
   137	 * @sizeof_priv: size of the driver private data
   138	 *
   139	 * This is part one of counter registration. The structure is allocated
   140	 * dynamically to ensure the right lifetime for the embedded struct device.
   141	 *
   142	 * If this succeeds, call counter_put() to get rid of the counter_device again.
   143	 */
   144	struct counter_device *counter_alloc(size_t sizeof_priv)
   145	{
   146		struct counter_device_allochelper *ch;
   147		struct counter_device *counter;
   148		struct device *dev;
   149		int id, err;
   150	
   151		ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
   152		if (!ch) {
   153			err = -ENOMEM;
   154			goto err_alloc_ch;
   155		}
   156	
   157		counter = &ch->counter;
   158		dev = &counter->dev;
   159	
   160		/* Acquire unique ID */
   161		err = ida_alloc(&counter_ida, GFP_KERNEL);
   162		if (err < 0) {
   163			goto err_ida_alloc;
   164		}
   165		dev->id = err;
   166	
   167		err = counter_chrdev_add(counter);
   168		if (err < 0)
   169			goto err_chrdev_add;
   170	
   171		device_initialize(dev);
   172		/* Configure device structure for Counter */
   173		dev->type = &counter_device_type;
   174		dev->bus = &counter_bus_type;
 > 175		dev->devt = MKDEV(MAJOR(counter_devt), id);
   176	
   177		mutex_init(&counter->ops_exist_lock);
   178	
   179		return counter;
   180	
   181	err_chrdev_add:
   182	
   183		ida_free(&counter_ida, dev->id);
   184	err_ida_alloc:
   185	
   186		kfree(ch);
   187	err_alloc_ch:
   188	
   189		return ERR_PTR(err);
   190	}
   191	EXPORT_SYMBOL_GPL(counter_alloc);
   192	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
@ 2021-12-27 12:18     ` kernel test robot
  0 siblings, 0 replies; 125+ messages in thread
From: kernel test robot @ 2021-12-27 12:18 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3939 bytes --]

Hi "Uwe,

I love your patch! Perhaps something to improve:

[auto build test WARNING on a7904a538933c525096ca2ccde1e60d0ee62c08e]

url:    https://github.com/0day-ci/linux/commits/Uwe-Kleine-K-nig/counter-cleanups-and-device-lifetime-fixes/20211227-174815
base:   a7904a538933c525096ca2ccde1e60d0ee62c08e
config: i386-randconfig-r006-20211227 (https://download.01.org/0day-ci/archive/20211227/202112272054.WsrEZBF1-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 511726c64d3b6cca66f7c54d457d586aa3129f67)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/250e0e3d91caea9f7c61652a7a9a8c006b2464be
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Uwe-Kleine-K-nig/counter-cleanups-and-device-lifetime-fixes/20211227-174815
        git checkout 250e0e3d91caea9f7c61652a7a9a8c006b2464be
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/counter/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/counter/counter-core.c:175:41: warning: variable 'id' is uninitialized when used here [-Wuninitialized]
           dev->devt = MKDEV(MAJOR(counter_devt), id);
                                                  ^~
   include/linux/kdev_t.h:12:46: note: expanded from macro 'MKDEV'
   #define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
                                                   ^~
   drivers/counter/counter-core.c:149:8: note: initialize the variable 'id' to silence this warning
           int id, err;
                 ^
                  = 0
   1 warning generated.


vim +/id +175 drivers/counter/counter-core.c

   134	
   135	/**
   136	 * counter_alloc - allocate a counter_device
   137	 * @sizeof_priv: size of the driver private data
   138	 *
   139	 * This is part one of counter registration. The structure is allocated
   140	 * dynamically to ensure the right lifetime for the embedded struct device.
   141	 *
   142	 * If this succeeds, call counter_put() to get rid of the counter_device again.
   143	 */
   144	struct counter_device *counter_alloc(size_t sizeof_priv)
   145	{
   146		struct counter_device_allochelper *ch;
   147		struct counter_device *counter;
   148		struct device *dev;
   149		int id, err;
   150	
   151		ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
   152		if (!ch) {
   153			err = -ENOMEM;
   154			goto err_alloc_ch;
   155		}
   156	
   157		counter = &ch->counter;
   158		dev = &counter->dev;
   159	
   160		/* Acquire unique ID */
   161		err = ida_alloc(&counter_ida, GFP_KERNEL);
   162		if (err < 0) {
   163			goto err_ida_alloc;
   164		}
   165		dev->id = err;
   166	
   167		err = counter_chrdev_add(counter);
   168		if (err < 0)
   169			goto err_chrdev_add;
   170	
   171		device_initialize(dev);
   172		/* Configure device structure for Counter */
   173		dev->type = &counter_device_type;
   174		dev->bus = &counter_bus_type;
 > 175		dev->devt = MKDEV(MAJOR(counter_devt), id);
   176	
   177		mutex_init(&counter->ops_exist_lock);
   178	
   179		return counter;
   180	
   181	err_chrdev_add:
   182	
   183		ida_free(&counter_ida, dev->id);
   184	err_ida_alloc:
   185	
   186		kfree(ch);
   187	err_alloc_ch:
   188	
   189		return ERR_PTR(err);
   190	}
   191	EXPORT_SYMBOL_GPL(counter_alloc);
   192	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

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

* Re: [PATCH v2 15/23] counter: 104-quad-8: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 15/23] counter: 104-quad-8: Convert to new counter registration Uwe Kleine-König
@ 2021-12-27 12:19   ` Lars-Peter Clausen
  2021-12-28 11:06     ` Uwe Kleine-König
  2021-12-28 18:17   ` Jonathan Cameron
  2021-12-29  8:24   ` William Breathitt Gray
  2 siblings, 1 reply; 125+ messages in thread
From: Lars-Peter Clausen @ 2021-12-27 12:19 UTC (permalink / raw)
  To: Uwe Kleine-König, William Breathitt Gray
  Cc: kernel, Jonathan Cameron, linux-iio, Greg Kroah-Hartman,
	linux-kernel, Syed Nayyar Waris

On 12/27/21 10:45 AM, Uwe Kleine-König wrote:
> [...]
>   
> -	return devm_counter_register(dev, &priv->counter);
> +	err = devm_counter_add(dev, counter);
> +	if (err < 0)
> +		return dev_err_probe(dev, err, "Failed to add counter\n");
I wonder if we should put that dev_err_probe into the devm_counter_add 
since every driver wants to have it anyway.
> +
> +	return 0;
>   }
>   
>   static struct isa_driver quad8_driver = {



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

* Re: [PATCH v2 00/23] counter: cleanups and device lifetime fixes
  2021-12-27  9:45 ` Uwe Kleine-König
@ 2021-12-27 12:25   ` Lars-Peter Clausen
  -1 siblings, 0 replies; 125+ messages in thread
From: Lars-Peter Clausen @ 2021-12-27 12:25 UTC (permalink / raw)
  To: Uwe Kleine-König, William Breathitt Gray
  Cc: kernel, Jonathan Cameron, linux-iio, Greg Kroah-Hartman,
	linux-kernel, Patrick Havelange, Kamel Bouhara, linux-arm-kernel,
	Syed Nayyar Waris, Oleksij Rempel, Jarkko Nikula, David Lechner,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Jonathan Corbet, linux-doc, Ahmad Fatoum, Felipe Balbi (Intel),
	Raymond Tan, Benjamin Gaignard

On 12/27/21 10:45 AM, Uwe Kleine-König wrote:
> [...]
>
>   - I wonder why counter is a bus and not a class device type. There is
>     no driver that would ever bind a counter device, is there? So
>     /sys/bus/counter/driver is always empty.
>
There used to be a time when GKH said that we do not want new driver 
classes. And all new subsystems should use bus since bus is a superset 
of class. This restriction has been eased since then.

But it was around when the IIO subsystem was merged and since the 
counter subsystem originated from the IIO subsystem I assume it just 
copied this.


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

* Re: [PATCH v2 00/23] counter: cleanups and device lifetime fixes
@ 2021-12-27 12:25   ` Lars-Peter Clausen
  0 siblings, 0 replies; 125+ messages in thread
From: Lars-Peter Clausen @ 2021-12-27 12:25 UTC (permalink / raw)
  To: Uwe Kleine-König, William Breathitt Gray
  Cc: kernel, Jonathan Cameron, linux-iio, Greg Kroah-Hartman,
	linux-kernel, Patrick Havelange, Kamel Bouhara, linux-arm-kernel,
	Syed Nayyar Waris, Oleksij Rempel, Jarkko Nikula, David Lechner,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Jonathan Corbet, linux-doc, Ahmad Fatoum, Felipe Balbi (Intel),
	Raymond Tan, Benjamin Gaignard

On 12/27/21 10:45 AM, Uwe Kleine-König wrote:
> [...]
>
>   - I wonder why counter is a bus and not a class device type. There is
>     no driver that would ever bind a counter device, is there? So
>     /sys/bus/counter/driver is always empty.
>
There used to be a time when GKH said that we do not want new driver 
classes. And all new subsystems should use bus since bus is a superset 
of class. This restriction has been eased since then.

But it was around when the IIO subsystem was merged and since the 
counter subsystem originated from the IIO subsystem I assume it just 
copied this.


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 04/23] counter: Provide a wrapper to access device private data
  2021-12-27 11:52       ` Greg Kroah-Hartman
@ 2021-12-27 12:28         ` Lars-Peter Clausen
  0 siblings, 0 replies; 125+ messages in thread
From: Lars-Peter Clausen @ 2021-12-27 12:28 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Uwe Kleine-König, William Breathitt Gray, kernel,
	Jonathan Cameron, linux-iio, linux-kernel

On 12/27/21 12:52 PM, Greg Kroah-Hartman wrote:
> On Mon, Dec 27, 2021 at 12:34:28PM +0100, Lars-Peter Clausen wrote:
>> On 12/27/21 12:02 PM, Greg Kroah-Hartman wrote:
>>> On Mon, Dec 27, 2021 at 10:45:07AM +0100, Uwe Kleine-König wrote:
>>>> For now this just wraps accessing struct counter_device::priv. However
>>>> this is about to change and converting drivers to this helper
>>>> individually makes fixing device lifetime issues result in easier to
>>>> review patches.
>>>>
>>>> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>>>> ---
>>>>    drivers/counter/counter-core.c | 12 ++++++++++++
>>>>    include/linux/counter.h        |  2 ++
>>>>    2 files changed, 14 insertions(+)
>>>>
>>>> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
>>>> index f053a43c6c04..00c41f28c101 100644
>>>> --- a/drivers/counter/counter-core.c
>>>> +++ b/drivers/counter/counter-core.c
>>>> @@ -45,6 +45,18 @@ static struct bus_type counter_bus_type = {
>>>>    static dev_t counter_devt;
>>>> +/**
>>>> + * counter_priv - access counter device private data
>>>> + * @counter: counter device
>>>> + *
>>>> + * Get the counter device private data
>>>> + */
>>>> +void *counter_priv(const struct counter_device *const counter)
>>>> +{
>>>> +	return counter->priv;
>>>> +}
>>>> +EXPORT_SYMBOL_GPL(counter_priv);
>>> Shouldn't this be usin gdev_get_drvdata() and using the private data
>>> pointer that is already on the struct device structure itself?  The void
>>> *priv; should be dropped from struct counter_device entirely.
>>>
>>> Oh ick, I just now looked at 'struct counter_device', there are other
>>> reference counting issues in there (hint, struct cdev has a reference
>>> count...)  But that's independent of this patch series...
>> This is not a problem. The struct cdev holds a reference to the struct dev.
>> This allows them to use the same allocation. As long as there is a reference
>> to the cdev there will be a reference to the dev and the memory will be kept
>> alive.
> Ick, a cdev shouldn't be doing stuff like that, but I see how people
> like to use it that way :(
>
Can you explain why cdev shouldn't be doing that? This commit has some 
backstory why this is done 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=233ed09d7fdacf592ee91e6c97ce5f4364fbe7c0



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

* Re: [PATCH v2 17/23] counter: intel-qep: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 17/23] counter: intel-qep: " Uwe Kleine-König
@ 2021-12-27 15:02   ` Jarkko Nikula
  2021-12-28 10:56     ` Uwe Kleine-König
  2021-12-28 18:20   ` Jonathan Cameron
  2021-12-29  8:29   ` William Breathitt Gray
  2 siblings, 1 reply; 125+ messages in thread
From: Jarkko Nikula @ 2021-12-27 15:02 UTC (permalink / raw)
  To: Uwe Kleine-König, William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Felipe Balbi (Intel),
	Raymond Tan

On 12/27/21 11:45, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: b711f687a1c1 ("counter: Add support for Intel Quadrature Encoder Peripheral")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>   drivers/counter/intel-qep.c | 28 ++++++++++++++++------------
>   1 file changed, 16 insertions(+), 12 deletions(-)
> 
Should the Fixes tag rather be b6c50affda59 ("counter: Add character 
device interface") instead of when each drivers were introduced? I mean 
was it possible to hit the issue before /dev/counter was introduced?

Jarkko

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

* Re: [PATCH v2 16/23] counter: interrupt-cnt: Convert to new counter registration
  2021-12-27 11:34       ` Greg Kroah-Hartman
  2021-12-27 11:44         ` Lars-Peter Clausen
@ 2021-12-27 21:09         ` Uwe Kleine-König
  1 sibling, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-27 21:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Lars-Peter Clausen, Ahmad Fatoum, linux-iio, linux-kernel,
	William Breathitt Gray, kernel, Jonathan Cameron, Oleksij Rempel

[-- Attachment #1: Type: text/plain, Size: 3321 bytes --]

On Mon, Dec 27, 2021 at 12:34:25PM +0100, Greg Kroah-Hartman wrote:
> On Mon, Dec 27, 2021 at 12:21:14PM +0100, Lars-Peter Clausen wrote:
> > On 12/27/21 11:59 AM, Greg Kroah-Hartman wrote:
> > > On Mon, Dec 27, 2021 at 10:45:19AM +0100, Uwe Kleine-König wrote:
> > > > This fixes device lifetime issues where it was possible to free a live
> > > > struct device.
> > > > 
> > > > Fixes: a55ebd47f21f ("counter: add IRQ or GPIO based counter")
> > > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > > ---
> > > >   drivers/counter/interrupt-cnt.c | 28 ++++++++++++++++------------
> > > >   1 file changed, 16 insertions(+), 12 deletions(-)
> > > > 
> > > > diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c
> > > > index 4bf706ef46e2..9e99702470c2 100644
> > > > --- a/drivers/counter/interrupt-cnt.c
> > > > +++ b/drivers/counter/interrupt-cnt.c
> > > > @@ -16,7 +16,6 @@
> > > >   struct interrupt_cnt_priv {
> > > >   	atomic_t count;
> > > > -	struct counter_device counter;
> > > >   	struct gpio_desc *gpio;
> > > >   	int irq;
> > > >   	bool enabled;
> > > > @@ -148,12 +147,14 @@ static const struct counter_ops interrupt_cnt_ops = {
> > > >   static int interrupt_cnt_probe(struct platform_device *pdev)
> > > >   {
> > > >   	struct device *dev = &pdev->dev;
> > > > +	struct counter_device *counter;
> > > >   	struct interrupt_cnt_priv *priv;
> > > >   	int ret;
> > > > -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> > > > -	if (!priv)
> > > > +	counter = devm_counter_alloc(dev, sizeof(*priv));
> > > I just picked one of these patches at random, nothing specific about
> > > this driver...
> > > 
> > > You can not have a 'struct device' in memory allocated by devm_*()
> > > functions for the obvious reason that now that memory is being
> > > controlled by a reference count that is OUTSIDE of the structure itself.
> > > 
> > > So while your goal might be good here, this is not the correct solution
> > > at all, sorry.
> > 
> > Before this patch the memory for the struct device was devm_kzalloc'ed.
> > Which as you point out is a bug.
> > 
> > After this patch the memory is reference counted and will be freed when the
> > last reference is dropped, in the release callback of the struct device.

@Lars, thanks for arguing for my case.
 
> > The alloc function is still a devm_ function, but on 'free' it will only
> > drop the reference to the struct device that it holds. This is a very common
> > pattern that is used by basically any driver subsystem in the kernel.
> 
> Then it is not a real devm_() call, let's not call it that please as it
> is obviously very confusing :)

It's only confusing if you consider the m in devm to stand for "malloc",
but it's for "managed". I agree to Lars that it's a sane approach.

> Just call it counter_alloc(), or , counter_create(), or something a bit
> more in line with the rest of all driver subsystems.

There is a counter_alloc() and in contrast to devm_counter_alloc() the
caller has to care about dropping the reference to it by hand.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 17/23] counter: intel-qep: Convert to new counter registration
  2021-12-27 15:02   ` Jarkko Nikula
@ 2021-12-28 10:56     ` Uwe Kleine-König
  2021-12-29 12:42       ` Jarkko Nikula
  0 siblings, 1 reply; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-28 10:56 UTC (permalink / raw)
  To: Jarkko Nikula
  Cc: William Breathitt Gray, Felipe Balbi (Intel),
	Lars-Peter Clausen, Raymond Tan, linux-iio, Greg Kroah-Hartman,
	linux-kernel, kernel, Jonathan Cameron

[-- Attachment #1: Type: text/plain, Size: 1524 bytes --]

On Mon, Dec 27, 2021 at 05:02:39PM +0200, Jarkko Nikula wrote:
> On 12/27/21 11:45, Uwe Kleine-König wrote:
> > This fixes device lifetime issues where it was possible to free a live
> > struct device.
> > 
> > Fixes: b711f687a1c1 ("counter: Add support for Intel Quadrature Encoder Peripheral")
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > ---
> >   drivers/counter/intel-qep.c | 28 ++++++++++++++++------------
> >   1 file changed, 16 insertions(+), 12 deletions(-)
> > 
> Should the Fixes tag rather be b6c50affda59 ("counter: Add character device
> interface") instead of when each drivers were introduced? I mean was it
> possible to hit the issue before /dev/counter was introduced?

I'm not sure if there is an issue before this, but it was already wrong
before for sure. Maybe it's possible to hold a reference somehow via
sysfs?

The thought that made me tag the individual driver commits was: With the
approach used to fix the issue all drivers need to be modified and an
unconverted driver doesn't benefit from the availability of
counter_alloc() / counter_add() if it isn't used. So all trees that
include b711f687a1c1 but not "counter: intel-qep: Convert to new counter
registration" are broken (more or less exploitable). So I think the
added Fixes line is the right choice.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 15/23] counter: 104-quad-8: Convert to new counter registration
  2021-12-27 12:19   ` Lars-Peter Clausen
@ 2021-12-28 11:06     ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-28 11:06 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: William Breathitt Gray, linux-iio, Greg Kroah-Hartman,
	linux-kernel, kernel, Jonathan Cameron, Syed Nayyar Waris

[-- Attachment #1: Type: text/plain, Size: 1472 bytes --]

On Mon, Dec 27, 2021 at 01:19:25PM +0100, Lars-Peter Clausen wrote:
> On 12/27/21 10:45 AM, Uwe Kleine-König wrote:
> > [...]
> > -	return devm_counter_register(dev, &priv->counter);
> > +	err = devm_counter_add(dev, counter);
> > +	if (err < 0)
> > +		return dev_err_probe(dev, err, "Failed to add counter\n");
> I wonder if we should put that dev_err_probe into the devm_counter_add since
> every driver wants to have it anyway.

Personally I'm not a big fan of API functions that emit an error
message. Usually the consumer knows best if a certain failing function
call is worth an error message. Look at platform_get_irq() that some
time ago got a dev_err call. The result was to introduce a
silent variant (platform_get_irq_optional()) because emitting an error
message isn't the right thing in all cases.

Also the API function probably won't call
device_set_deferred_probe_reason() and so the consumer has to care for
that anyhow (or not which makes -EPROBE_DEFER problems harder to debug).

Furthermore the consumer can emit in some cases a better error message
than the core. (Well, this doesn't apply here, but in the example of
platform_get_irq() the driver knows the irq's purpose and can call it
"TX irq" in the error message which the irq core cannot.)

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
  2021-12-27 12:16   ` Lars-Peter Clausen
@ 2021-12-28 11:22     ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-28 11:22 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: William Breathitt Gray, linux-iio, Greg Kroah-Hartman,
	linux-kernel, kernel, Jonathan Cameron

[-- Attachment #1: Type: text/plain, Size: 4839 bytes --]

Hello,

On Mon, Dec 27, 2021 at 01:16:56PM +0100, Lars-Peter Clausen wrote:
> On 12/27/21 10:45 AM, Uwe Kleine-König wrote:
> > The current implementation gets device lifetime tracking wrong. The
> > problem is that allocation of struct counter_device is controlled by the
> > individual drivers but this structure contains a struct device that
> > might have to live longer than a driver is bound. As a result a command
> > sequence like:
> > 
> > 	{ sleep 5; echo bang; } > /dev/counter0 &
> > 	sleep 1;
> > 	echo 40000000.timer:counter > /sys/bus/platform/drivers/stm32-timer-counter/unbind
> > 
> > can keep a reference to the struct device and unbinding results in
> > freeing the memory occupied by this device resulting in an oops.
> > 
> > This commit provides two new functions (plus some helpers):
> >   - counter_alloc() to allocate a struct counter_device that is
> >     automatically freed once the embedded struct device is released
> >   - counter_add() to register such a device.
> > 
> > Note that this commit doesn't fix any issues, all drivers have to be
> > converted to these new functions to correct the lifetime problems.
> Nice work!

\o/

> > [...]
> > @@ -24,6 +25,11 @@
> >   /* Provides a unique ID for each counter device */
> >   static DEFINE_IDA(counter_ida);
> > +struct counter_device_allochelper {
> > +	struct counter_device counter;
> > +	unsigned long privdata[];
> 
> The normal k*alloc functions guarantee that the allocation is cacheline
> aligned. Without that for example the ____cacheline_aligned attribute will
> not work correctly. And while it is unlikely that a counter driver will need
> for example DMA memory I think it is still good practice to guarantee this
> here to avoid bad surprises. There are two ways of doing this.

Yeah, I thought to add more alignment once the need arises. My
preference would be to got for the ____cacheline_aligned approach.

> > [...]
> > +struct counter_device *counter_alloc(size_t sizeof_priv)
> I'd add a parent parameter here since with the devm_ variant we have to pass
> it anyway and this allows to slightly reduce the boilerplate code in the
> driver where the parent field of the counter has to be initialized.

I don't feel strong here, can do that.

> > +{
> > +	struct counter_device_allochelper *ch;
> > +	struct counter_device *counter;
> > +	struct device *dev;
> > +	int id, err;
> > +
> > +	ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
> > +	if (!ch) {
> > +		err = -ENOMEM;
> > +		goto err_alloc_ch;
> > +	}
> > +
> > +	counter = &ch->counter;
> > +	dev = &counter->dev;
> > +
> > +	/* Acquire unique ID */
> > +	err = ida_alloc(&counter_ida, GFP_KERNEL);
> > +	if (err < 0) {
> > +		goto err_ida_alloc;
> > +	}
> There is a inconsistency whether braces are used for single statement `if`s
> in this patch.

Oh, indeed.

> > +	dev->id = err;
> > +
> > +	err = counter_chrdev_add(counter);
> > +	if (err < 0)
> > +		goto err_chrdev_add;
> > +
> > +	device_initialize(dev);
> > +	/* Configure device structure for Counter */
> > +	dev->type = &counter_device_type;
> > +	dev->bus = &counter_bus_type;
> > +	dev->devt = MKDEV(MAJOR(counter_devt), id);
> > +
> > +	mutex_init(&counter->ops_exist_lock);
> > +
> > +	return counter;
> > +
> > +err_chrdev_add:
> > +
> > +	ida_free(&counter_ida, dev->id);
> > +err_ida_alloc:
> > +
> > +	kfree(ch);
> > +err_alloc_ch:
> > +
> > +	return ERR_PTR(err);
> > +}
> > +EXPORT_SYMBOL_GPL(counter_alloc);
> > +
> > +void counter_put(struct counter_device *counter)
> > +{
> > +	put_device(&counter->dev);
> > +}
> > +
> > +/**
> > + * counter_add - complete registration of a counter
> > + * @counter: the counter to add
> > + *
> > + * This is part two of counter registration.
> > + *
> > + * If this succeeds, call counter_unregister() to get rid of the counter_device again.
> > + */
> > +int counter_add(struct counter_device *counter)
> > +{
> > +	int err;
> > +	struct device *dev = &counter->dev;
> > +
> > +	get_device(&counter->dev);
> 
> This get_device() is not needed. device_add() will also add a reference, so
> you increment the reference count by 2 when calling counter_add().
> 
> It is only needed to balance the put_device() in counter_unregister(). I'd
> add a `counter->legacy_device` around that put_device() and then remove it
> in the last patch.

Ah indeed. I added that to balance the call of put_device() by devm_counter_alloc()'s
release function (devm_counter_put()). But on a quick check you're
right. I will think about it a bit more and test.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 01/23] counter: Use container_of instead of drvdata to track counter_device
  2021-12-27  9:45 ` [PATCH v2 01/23] counter: Use container_of instead of drvdata to track counter_device Uwe Kleine-König
@ 2021-12-28 17:14   ` Jonathan Cameron
  2021-12-29  6:38   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 17:14 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel

On Mon, 27 Dec 2021 10:45:04 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> The counter core uses drvdata to find a struct counter_device from a
> struct device. However as the device is a member of struct counter_device,
> the lookup can be done faster (and a bit type safe) using container_of.
> 
> There are no other users of drvdata, so the call to dev_set_drvdata can
> go away, too.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
LGTM

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/counter-core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> index 5acc54539623..f053a43c6c04 100644
> --- a/drivers/counter/counter-core.c
> +++ b/drivers/counter/counter-core.c
> @@ -26,7 +26,8 @@ static DEFINE_IDA(counter_ida);
>  
>  static void counter_device_release(struct device *dev)
>  {
> -	struct counter_device *const counter = dev_get_drvdata(dev);
> +	struct counter_device *const counter =
> +		container_of(dev, struct counter_device, dev);
>  
>  	counter_chrdev_remove(counter);
>  	ida_free(&counter_ida, dev->id);
> @@ -78,7 +79,6 @@ int counter_register(struct counter_device *const counter)
>  		dev->of_node = counter->parent->of_node;
>  	}
>  	device_initialize(dev);
> -	dev_set_drvdata(dev, counter);
>  
>  	err = counter_sysfs_add(counter);
>  	if (err < 0)


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

* Re: [PATCH v2 00/23] counter: cleanups and device lifetime fixes
  2021-12-27 12:25   ` Lars-Peter Clausen
@ 2021-12-28 17:35     ` Jonathan Cameron
  -1 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 17:35 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Uwe Kleine-König, William Breathitt Gray, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Patrick Havelange, Kamel Bouhara, linux-arm-kernel,
	Syed Nayyar Waris, Oleksij Rempel, Jarkko Nikula, David Lechner,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Jonathan Corbet, linux-doc, Ahmad Fatoum, Felipe Balbi (Intel),
	Raymond Tan, Benjamin Gaignard

On Mon, 27 Dec 2021 13:25:25 +0100
Lars-Peter Clausen <lars@metafoo.de> wrote:

> On 12/27/21 10:45 AM, Uwe Kleine-König wrote:
> > [...]
> >
> >   - I wonder why counter is a bus and not a class device type. There is
> >     no driver that would ever bind a counter device, is there? So
> >     /sys/bus/counter/driver is always empty.
> >  
> There used to be a time when GKH said that we do not want new driver 
> classes. And all new subsystems should use bus since bus is a superset 
> of class. This restriction has been eased since then.
> 
> But it was around when the IIO subsystem was merged and since the 
> counter subsystem originated from the IIO subsystem I assume it just 
> copied this.
> 

Yup. Discussion about this back then with one view being there
should never have been class in the first place.

https://lore.kernel.org/lkml/4B571DA4.6070603@cam.ac.uk/

For anyone who loves the history of these things...

FWIW I think Greg suggested IIO should be a bus because we were hanging
a bunch of different types of device off a class and it was getting messy.
Kay then gave some history on class vs bus and suggested no new
subsystem should use class.

Ah well, opinions change over time!

Also interesting to see we were discussing a bridge to input all that
time ago and it's still not gone beyond various prototypes (with
exception of touch screens).

Jonathan

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

* Re: [PATCH v2 00/23] counter: cleanups and device lifetime fixes
@ 2021-12-28 17:35     ` Jonathan Cameron
  0 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 17:35 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Uwe Kleine-König, William Breathitt Gray, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Patrick Havelange, Kamel Bouhara, linux-arm-kernel,
	Syed Nayyar Waris, Oleksij Rempel, Jarkko Nikula, David Lechner,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Jonathan Corbet, linux-doc, Ahmad Fatoum, Felipe Balbi (Intel),
	Raymond Tan, Benjamin Gaignard

On Mon, 27 Dec 2021 13:25:25 +0100
Lars-Peter Clausen <lars@metafoo.de> wrote:

> On 12/27/21 10:45 AM, Uwe Kleine-König wrote:
> > [...]
> >
> >   - I wonder why counter is a bus and not a class device type. There is
> >     no driver that would ever bind a counter device, is there? So
> >     /sys/bus/counter/driver is always empty.
> >  
> There used to be a time when GKH said that we do not want new driver 
> classes. And all new subsystems should use bus since bus is a superset 
> of class. This restriction has been eased since then.
> 
> But it was around when the IIO subsystem was merged and since the 
> counter subsystem originated from the IIO subsystem I assume it just 
> copied this.
> 

Yup. Discussion about this back then with one view being there
should never have been class in the first place.

https://lore.kernel.org/lkml/4B571DA4.6070603@cam.ac.uk/

For anyone who loves the history of these things...

FWIW I think Greg suggested IIO should be a bus because we were hanging
a bunch of different types of device off a class and it was getting messy.
Kay then gave some history on class vs bus and suggested no new
subsystem should use class.

Ah well, opinions change over time!

Also interesting to see we were discussing a bridge to input all that
time ago and it's still not gone beyond various prototypes (with
exception of touch screens).

Jonathan

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 02/23] counter: ftm-quaddec: Drop unused platform_set_drvdata()
  2021-12-27  9:45 ` [PATCH v2 02/23] counter: ftm-quaddec: Drop unused platform_set_drvdata() Uwe Kleine-König
@ 2021-12-28 17:37   ` Jonathan Cameron
  2021-12-29  6:42   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 17:37 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Patrick Havelange, Syed Nayyar Waris

On Mon, 27 Dec 2021 10:45:05 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> The driver doesn't ever use platform_get_drvdata, so drop this unused
> call.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/ftm-quaddec.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> index 5ef0478709cd..9272f7b58beb 100644
> --- a/drivers/counter/ftm-quaddec.c
> +++ b/drivers/counter/ftm-quaddec.c
> @@ -269,8 +269,6 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
>  	if (!ftm)
>  		return -ENOMEM;
>  
> -	platform_set_drvdata(pdev, ftm);
> -
>  	io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	if (!io) {
>  		dev_err(&pdev->dev, "Failed to get memory region\n");


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

* Re: [PATCH v2 03/23] counter: microchip-tcb-capture: Drop unused platform_set_drvdata()
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-28 17:38     ` Jonathan Cameron
  -1 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 17:38 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Kamel Bouhara, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:06 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> The driver doesn't ever use platform_get_drvdata, so drop this unused
> call.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
FWIW sanity checked it is indeed not used that I can see.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/microchip-tcb-capture.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index 0ab1b2716784..bb69f2e0ba93 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -307,8 +307,6 @@ static int mchp_tc_probe(struct platform_device *pdev)
>  	if (!priv)
>  		return -ENOMEM;
>  
> -	platform_set_drvdata(pdev, priv);
> -
>  	match = of_match_node(atmel_tc_of_match, np->parent);
>  	tcb_config = match->data;
>  	if (!tcb_config) {


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

* Re: [PATCH v2 03/23] counter: microchip-tcb-capture: Drop unused platform_set_drvdata()
@ 2021-12-28 17:38     ` Jonathan Cameron
  0 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 17:38 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Kamel Bouhara, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:06 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> The driver doesn't ever use platform_get_drvdata, so drop this unused
> call.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
FWIW sanity checked it is indeed not used that I can see.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/microchip-tcb-capture.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index 0ab1b2716784..bb69f2e0ba93 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -307,8 +307,6 @@ static int mchp_tc_probe(struct platform_device *pdev)
>  	if (!priv)
>  		return -ENOMEM;
>  
> -	platform_set_drvdata(pdev, priv);
> -
>  	match = of_match_node(atmel_tc_of_match, np->parent);
>  	tcb_config = match->data;
>  	if (!tcb_config) {


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
  2021-12-27  9:45 ` [PATCH v2 13/23] counter: Provide alternative counter registration functions Uwe Kleine-König
  2021-12-27 12:16   ` Lars-Peter Clausen
  2021-12-27 12:18     ` kernel test robot
@ 2021-12-28 18:00   ` Jonathan Cameron
  2021-12-29 11:27     ` Uwe Kleine-König
  2021-12-29 13:49     ` Jarkko Nikula
  2021-12-29  8:13   ` William Breathitt Gray
  3 siblings, 2 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:00 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel

On Mon, 27 Dec 2021 10:45:16 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> The current implementation gets device lifetime tracking wrong. The
> problem is that allocation of struct counter_device is controlled by the
> individual drivers but this structure contains a struct device that
> might have to live longer than a driver is bound. As a result a command
> sequence like:
> 
> 	{ sleep 5; echo bang; } > /dev/counter0 &
> 	sleep 1;
> 	echo 40000000.timer:counter > /sys/bus/platform/drivers/stm32-timer-counter/unbind
> 
> can keep a reference to the struct device and unbinding results in
> freeing the memory occupied by this device resulting in an oops.
> 
> This commit provides two new functions (plus some helpers):
>  - counter_alloc() to allocate a struct counter_device that is
>    automatically freed once the embedded struct device is released
>  - counter_add() to register such a device.
> 
> Note that this commit doesn't fix any issues, all drivers have to be
> converted to these new functions to correct the lifetime problems.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
In general looks very nice to me.

Few minor things inline.
> ---
>  drivers/counter/counter-core.c | 149 ++++++++++++++++++++++++++++++++-
>  include/linux/counter.h        |  15 ++++
>  2 files changed, 163 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> index 00c41f28c101..8261567b6272 100644
> --- a/drivers/counter/counter-core.c
> +++ b/drivers/counter/counter-core.c
> @@ -15,6 +15,7 @@
>  #include <linux/kdev_t.h>
>  #include <linux/module.h>
>  #include <linux/mutex.h>
> +#include <linux/slab.h>
>  #include <linux/types.h>
>  #include <linux/wait.h>
>  
> @@ -24,6 +25,11 @@
>  /* Provides a unique ID for each counter device */
>  static DEFINE_IDA(counter_ida);
>  
> +struct counter_device_allochelper {
> +	struct counter_device counter;
> +	unsigned long privdata[];
Nice to keep this opaque. We danced around how to do this in IIO for
a while and never got to a solution we all liked.  Slight disadvantage
is this might matter in hot paths where the compiler doesn't have visibility
to know it can very cheaply access the privdata.

I guess that can be looked at if anyone ever measures it as an important
element (they probably never will!)

> +};
> +
>  static void counter_device_release(struct device *dev)
>  {
>  	struct counter_device *const counter =
> @@ -31,6 +37,9 @@ static void counter_device_release(struct device *dev)
>  
>  	counter_chrdev_remove(counter);
>  	ida_free(&counter_ida, dev->id);
> +
> +	if (!counter->legacy_device)
> +		kfree(container_of(counter, struct counter_device_allochelper, counter));
>  }
>  
>  static struct device_type counter_device_type = {
> @@ -53,7 +62,14 @@ static dev_t counter_devt;
>   */
>  void *counter_priv(const struct counter_device *const counter)
>  {
> -	return counter->priv;
> +	if (counter->legacy_device) {
> +		return counter->priv;
> +	} else {
> +		struct counter_device_allochelper *ch =
> +			container_of(counter, struct counter_device_allochelper, counter);
> +
> +		return &ch->privdata;
> +	}
>  }
>  EXPORT_SYMBOL_GPL(counter_priv);
>  
> @@ -74,6 +90,8 @@ int counter_register(struct counter_device *const counter)
>  	int id;
>  	int err;
>  
> +	counter->legacy_device = true;
> +
>  	/* Acquire unique ID */
>  	id = ida_alloc(&counter_ida, GFP_KERNEL);
>  	if (id < 0)
> @@ -114,6 +132,100 @@ int counter_register(struct counter_device *const counter)
>  }
>  EXPORT_SYMBOL_GPL(counter_register);
>  
> +/**
> + * counter_alloc - allocate a counter_device
> + * @sizeof_priv: size of the driver private data
> + *
> + * This is part one of counter registration. The structure is allocated
> + * dynamically to ensure the right lifetime for the embedded struct device.
> + *
> + * If this succeeds, call counter_put() to get rid of the counter_device again.
> + */
> +struct counter_device *counter_alloc(size_t sizeof_priv)
> +{
> +	struct counter_device_allochelper *ch;
> +	struct counter_device *counter;
> +	struct device *dev;
> +	int id, err;
> +
> +	ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
> +	if (!ch) {
> +		err = -ENOMEM;
> +		goto err_alloc_ch;
> +	}
> +
> +	counter = &ch->counter;
> +	dev = &counter->dev;
> +
> +	/* Acquire unique ID */
> +	err = ida_alloc(&counter_ida, GFP_KERNEL);
> +	if (err < 0) {
> +		goto err_ida_alloc;
> +	}
> +	dev->id = err;
> +
> +	err = counter_chrdev_add(counter);

Should think about renaming  counter_chrdev_add() given it
does init and allocation stuff but no adding.

Personal inclination here would be to keep the elements in here
in the same order as in counter_register() where it doesn't matter
in the interests of slightly easier comparison of the code.

> +	if (err < 0)
> +		goto err_chrdev_add;
> +
> +	device_initialize(dev);
> +	/* Configure device structure for Counter */
> +	dev->type = &counter_device_type;
> +	dev->bus = &counter_bus_type;
> +	dev->devt = MKDEV(MAJOR(counter_devt), id);

As 0-day pointed out id not initialized.

> +
> +	mutex_init(&counter->ops_exist_lock);
> +
> +	return counter;
> +
> +err_chrdev_add:
> +
> +	ida_free(&counter_ida, dev->id);
> +err_ida_alloc:
> +
> +	kfree(ch);
> +err_alloc_ch:
> +
> +	return ERR_PTR(err);
> +}
> +EXPORT_SYMBOL_GPL(counter_alloc);
> +
> +void counter_put(struct counter_device *counter)
> +{
> +	put_device(&counter->dev);
> +}
> +
> +/**
> + * counter_add - complete registration of a counter
> + * @counter: the counter to add
> + *
> + * This is part two of counter registration.
> + *
> + * If this succeeds, call counter_unregister() to get rid of the counter_device again.
> + */
> +int counter_add(struct counter_device *counter)
> +{
> +	int err;
> +	struct device *dev = &counter->dev;
> +
> +	get_device(&counter->dev);
> +
> +	if (counter->parent) {
> +		dev->parent = counter->parent;
> +		dev->of_node = counter->parent->of_node;
> +	}
> +
> +	err = counter_sysfs_add(counter);
> +	if (err < 0)
> +		return err;
> +
> +	/* implies device_add(dev) */
> +	err = cdev_device_add(&counter->chrdev, dev);
> +
> +	return err;

return cdev_device_add(&counter->chrdev, dev);
Lars got some of these points as well (maybe all of them but
I'm too lazy to filter them for you ;)


> +}
> +EXPORT_SYMBOL_GPL(counter_add);
> +
>  /**
>   * counter_unregister - unregister Counter from the system
>   * @counter:	pointer to Counter to unregister
> @@ -168,6 +280,41 @@ int devm_counter_register(struct device *dev,
>  }
>  EXPORT_SYMBOL_GPL(devm_counter_register);
>  
> +static void devm_counter_put(void *counter)
> +{
> +	counter_put(counter);
> +}
> +
> +struct counter_device *devm_counter_alloc(struct device *dev, size_t sizeof_priv)
> +{
> +	struct counter_device *counter;
> +	int err;
> +
> +	counter = counter_alloc(sizeof_priv);
> +	if (IS_ERR(counter))
> +		return counter;
> +
> +	err = devm_add_action_or_reset(dev, devm_counter_put, counter);
> +	if (err < 0)
> +		return ERR_PTR(err);
> +
> +	return counter;
> +}
> +EXPORT_SYMBOL_GPL(devm_counter_alloc);
> +
> +int devm_counter_add(struct device *dev,
> +		     struct counter_device *const counter)
> +{
> +	int err;
> +
> +	err = counter_add(counter);
> +	if (err < 0)
> +		return err;
> +
> +	return devm_add_action_or_reset(dev, devm_counter_release, counter);
> +}
> +EXPORT_SYMBOL_GPL(devm_counter_add);
> +
>  #define COUNTER_DEV_MAX 256
>  
>  static int __init counter_init(void)
> diff --git a/include/linux/counter.h b/include/linux/counter.h
> index 8daaa38c71d8..f1350a43cd48 100644
> --- a/include/linux/counter.h
> +++ b/include/linux/counter.h
> @@ -327,14 +327,29 @@ struct counter_device {
>  	spinlock_t events_in_lock;
>  	struct mutex events_out_lock;
>  	struct mutex ops_exist_lock;
> +
> +	/*
> +	 * This can go away once all drivers are converted to
> +	 * counter_alloc()/counter_add().
> +	 */
> +	bool legacy_device;
>  };
>  
>  void *counter_priv(const struct counter_device *const counter);
>  
>  int counter_register(struct counter_device *const counter);
> +
> +struct counter_device *counter_alloc(size_t sizeof_priv);
> +void counter_put(struct counter_device *const counter);
> +int counter_add(struct counter_device *const counter);
> +
>  void counter_unregister(struct counter_device *const counter);
>  int devm_counter_register(struct device *dev,
>  			  struct counter_device *const counter);
> +struct counter_device *devm_counter_alloc(struct device *dev,
> +					  size_t sizeof_priv);
> +int devm_counter_add(struct device *dev,
> +		     struct counter_device *const counter);
>  void counter_push_event(struct counter_device *const counter, const u8 event,
>  			const u8 channel);
>  


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

* Re: [PATCH v2 04/23] counter: Provide a wrapper to access device private data
  2021-12-27  9:45 ` [PATCH v2 04/23] counter: Provide a wrapper to access device private data Uwe Kleine-König
  2021-12-27 11:02   ` Greg Kroah-Hartman
@ 2021-12-28 18:01   ` Jonathan Cameron
  2021-12-29  6:47   ` William Breathitt Gray
  2 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:01 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel

On Mon, 27 Dec 2021 10:45:07 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> For now this just wraps accessing struct counter_device::priv. However
> this is about to change and converting drivers to this helper
> individually makes fixing device lifetime issues result in easier to
> review patches.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/counter-core.c | 12 ++++++++++++
>  include/linux/counter.h        |  2 ++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> index f053a43c6c04..00c41f28c101 100644
> --- a/drivers/counter/counter-core.c
> +++ b/drivers/counter/counter-core.c
> @@ -45,6 +45,18 @@ static struct bus_type counter_bus_type = {
>  
>  static dev_t counter_devt;
>  
> +/**
> + * counter_priv - access counter device private data
> + * @counter: counter device
> + *
> + * Get the counter device private data
> + */
> +void *counter_priv(const struct counter_device *const counter)
> +{
> +	return counter->priv;
> +}
> +EXPORT_SYMBOL_GPL(counter_priv);
> +
>  /**
>   * counter_register - register Counter to the system
>   * @counter:	pointer to Counter to register
> diff --git a/include/linux/counter.h b/include/linux/counter.h
> index b7d0a00a61cf..8daaa38c71d8 100644
> --- a/include/linux/counter.h
> +++ b/include/linux/counter.h
> @@ -329,6 +329,8 @@ struct counter_device {
>  	struct mutex ops_exist_lock;
>  };
>  
> +void *counter_priv(const struct counter_device *const counter);
> +
>  int counter_register(struct counter_device *const counter);
>  void counter_unregister(struct counter_device *const counter);
>  int devm_counter_register(struct device *dev,


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

* Re: [PATCH v2 05/23] counter: 104-quad-8: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` [PATCH v2 05/23] counter: 104-quad-8: Convert to counter_priv() wrapper Uwe Kleine-König
@ 2021-12-28 18:02   ` Jonathan Cameron
  2021-12-29 11:11     ` Uwe Kleine-König
  2021-12-29  7:27   ` William Breathitt Gray
  1 sibling, 1 reply; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:02 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Syed Nayyar Waris

On Mon, 27 Dec 2021 10:45:08 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Looks sane and I'll assume you didn't miss any!

Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/104-quad-8.c | 58 ++++++++++++++++++------------------
>  1 file changed, 29 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
> index 1cbd60aaed69..6e5286cd1d4e 100644
> --- a/drivers/counter/104-quad-8.c
> +++ b/drivers/counter/104-quad-8.c
> @@ -113,7 +113,7 @@ static int quad8_signal_read(struct counter_device *counter,
>  			     struct counter_signal *signal,
>  			     enum counter_signal_level *level)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	unsigned int state;
>  
>  	/* Only Index signal levels can be read */
> @@ -131,7 +131,7 @@ static int quad8_signal_read(struct counter_device *counter,
>  static int quad8_count_read(struct counter_device *counter,
>  			    struct counter_count *count, u64 *val)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int base_offset = priv->base + 2 * count->id;
>  	unsigned int flags;
>  	unsigned int borrow;
> @@ -163,7 +163,7 @@ static int quad8_count_read(struct counter_device *counter,
>  static int quad8_count_write(struct counter_device *counter,
>  			     struct counter_count *count, u64 val)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int base_offset = priv->base + 2 * count->id;
>  	unsigned long irqflags;
>  	int i;
> @@ -213,7 +213,7 @@ static int quad8_function_read(struct counter_device *counter,
>  			       struct counter_count *count,
>  			       enum counter_function *function)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int id = count->id;
>  	unsigned long irqflags;
>  
> @@ -243,7 +243,7 @@ static int quad8_function_write(struct counter_device *counter,
>  				struct counter_count *count,
>  				enum counter_function function)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int id = count->id;
>  	unsigned int *const quadrature_mode = priv->quadrature_mode + id;
>  	unsigned int *const scale = priv->quadrature_scale + id;
> @@ -305,7 +305,7 @@ static int quad8_direction_read(struct counter_device *counter,
>  				struct counter_count *count,
>  				enum counter_count_direction *direction)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	unsigned int ud_flag;
>  	const unsigned int flag_addr = priv->base + 2 * count->id + 1;
>  
> @@ -335,7 +335,7 @@ static int quad8_action_read(struct counter_device *counter,
>  			     struct counter_synapse *synapse,
>  			     enum counter_synapse_action *action)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	int err;
>  	enum counter_function function;
>  	const size_t signal_a_id = count->synapses[0].signal->id;
> @@ -399,7 +399,7 @@ enum {
>  
>  static int quad8_events_configure(struct counter_device *counter)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	unsigned long irq_enabled = 0;
>  	unsigned long irqflags;
>  	size_t channel;
> @@ -442,7 +442,7 @@ static int quad8_events_configure(struct counter_device *counter)
>  static int quad8_watch_validate(struct counter_device *counter,
>  				const struct counter_watch *watch)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  
>  	if (watch->channel > QUAD8_NUM_COUNTERS - 1)
>  		return -EINVAL;
> @@ -497,7 +497,7 @@ static int quad8_index_polarity_get(struct counter_device *counter,
>  				    struct counter_signal *signal,
>  				    u32 *index_polarity)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id - 16;
>  
>  	*index_polarity = priv->index_polarity[channel_id];
> @@ -509,7 +509,7 @@ static int quad8_index_polarity_set(struct counter_device *counter,
>  				    struct counter_signal *signal,
>  				    u32 index_polarity)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id - 16;
>  	const int base_offset = priv->base + 2 * channel_id + 1;
>  	unsigned long irqflags;
> @@ -538,7 +538,7 @@ static int quad8_synchronous_mode_get(struct counter_device *counter,
>  				      struct counter_signal *signal,
>  				      u32 *synchronous_mode)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id - 16;
>  
>  	*synchronous_mode = priv->synchronous_mode[channel_id];
> @@ -550,7 +550,7 @@ static int quad8_synchronous_mode_set(struct counter_device *counter,
>  				      struct counter_signal *signal,
>  				      u32 synchronous_mode)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id - 16;
>  	const int base_offset = priv->base + 2 * channel_id + 1;
>  	unsigned long irqflags;
> @@ -589,7 +589,7 @@ static int quad8_count_mode_read(struct counter_device *counter,
>  				 struct counter_count *count,
>  				 enum counter_count_mode *cnt_mode)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  
>  	/* Map 104-QUAD-8 count mode to Generic Counter count mode */
>  	switch (priv->count_mode[count->id]) {
> @@ -614,7 +614,7 @@ static int quad8_count_mode_write(struct counter_device *counter,
>  				  struct counter_count *count,
>  				  enum counter_count_mode cnt_mode)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	unsigned int count_mode;
>  	unsigned int mode_cfg;
>  	const int base_offset = priv->base + 2 * count->id + 1;
> @@ -661,7 +661,7 @@ static int quad8_count_mode_write(struct counter_device *counter,
>  static int quad8_count_enable_read(struct counter_device *counter,
>  				   struct counter_count *count, u8 *enable)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  
>  	*enable = priv->ab_enable[count->id];
>  
> @@ -671,7 +671,7 @@ static int quad8_count_enable_read(struct counter_device *counter,
>  static int quad8_count_enable_write(struct counter_device *counter,
>  				    struct counter_count *count, u8 enable)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int base_offset = priv->base + 2 * count->id;
>  	unsigned long irqflags;
>  	unsigned int ior_cfg;
> @@ -699,7 +699,7 @@ static const char *const quad8_noise_error_states[] = {
>  static int quad8_error_noise_get(struct counter_device *counter,
>  				 struct counter_count *count, u32 *noise_error)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	const int base_offset = priv->base + 2 * count->id + 1;
>  
>  	*noise_error = !!(inb(base_offset) & QUAD8_FLAG_E);
> @@ -710,7 +710,7 @@ static int quad8_error_noise_get(struct counter_device *counter,
>  static int quad8_count_preset_read(struct counter_device *counter,
>  				   struct counter_count *count, u64 *preset)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  
>  	*preset = priv->preset[count->id];
>  
> @@ -736,7 +736,7 @@ static void quad8_preset_register_set(struct quad8 *const priv, const int id,
>  static int quad8_count_preset_write(struct counter_device *counter,
>  				    struct counter_count *count, u64 preset)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	unsigned long irqflags;
>  
>  	/* Only 24-bit values are supported */
> @@ -755,7 +755,7 @@ static int quad8_count_preset_write(struct counter_device *counter,
>  static int quad8_count_ceiling_read(struct counter_device *counter,
>  				    struct counter_count *count, u64 *ceiling)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	unsigned long irqflags;
>  
>  	spin_lock_irqsave(&priv->lock, irqflags);
> @@ -780,7 +780,7 @@ static int quad8_count_ceiling_read(struct counter_device *counter,
>  static int quad8_count_ceiling_write(struct counter_device *counter,
>  				     struct counter_count *count, u64 ceiling)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	unsigned long irqflags;
>  
>  	/* Only 24-bit values are supported */
> @@ -807,7 +807,7 @@ static int quad8_count_preset_enable_read(struct counter_device *counter,
>  					  struct counter_count *count,
>  					  u8 *preset_enable)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  
>  	*preset_enable = !priv->preset_enable[count->id];
>  
> @@ -818,7 +818,7 @@ static int quad8_count_preset_enable_write(struct counter_device *counter,
>  					   struct counter_count *count,
>  					   u8 preset_enable)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int base_offset = priv->base + 2 * count->id + 1;
>  	unsigned long irqflags;
>  	unsigned int ior_cfg;
> @@ -845,7 +845,7 @@ static int quad8_signal_cable_fault_read(struct counter_device *counter,
>  					 struct counter_signal *signal,
>  					 u8 *cable_fault)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id / 2;
>  	unsigned long irqflags;
>  	bool disabled;
> @@ -875,7 +875,7 @@ static int quad8_signal_cable_fault_enable_read(struct counter_device *counter,
>  						struct counter_signal *signal,
>  						u8 *enable)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id / 2;
>  
>  	*enable = !!(priv->cable_fault_enable & BIT(channel_id));
> @@ -887,7 +887,7 @@ static int quad8_signal_cable_fault_enable_write(struct counter_device *counter,
>  						 struct counter_signal *signal,
>  						 u8 enable)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id / 2;
>  	unsigned long irqflags;
>  	unsigned int cable_fault_enable;
> @@ -913,7 +913,7 @@ static int quad8_signal_fck_prescaler_read(struct counter_device *counter,
>  					   struct counter_signal *signal,
>  					   u8 *prescaler)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  
>  	*prescaler = priv->fck_prescaler[signal->id / 2];
>  
> @@ -924,7 +924,7 @@ static int quad8_signal_fck_prescaler_write(struct counter_device *counter,
>  					    struct counter_signal *signal,
>  					    u8 prescaler)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id / 2;
>  	const int base_offset = priv->base + 2 * channel_id;
>  	unsigned long irqflags;


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

* Re: [PATCH v2 06/23] counter: interrupt-cnt: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` [PATCH v2 06/23] counter: interrupt-cnt: " Uwe Kleine-König
@ 2021-12-28 18:04   ` Jonathan Cameron
  2021-12-29  7:34   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:04 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Oleksij Rempel, Ahmad Fatoum

On Mon, 27 Dec 2021 10:45:09 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/interrupt-cnt.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c
> index 8514a87fcbee..4bf706ef46e2 100644
> --- a/drivers/counter/interrupt-cnt.c
> +++ b/drivers/counter/interrupt-cnt.c
> @@ -37,7 +37,7 @@ static irqreturn_t interrupt_cnt_isr(int irq, void *dev_id)
>  static int interrupt_cnt_enable_read(struct counter_device *counter,
>  				     struct counter_count *count, u8 *enable)
>  {
> -	struct interrupt_cnt_priv *priv = counter->priv;
> +	struct interrupt_cnt_priv *priv = counter_priv(counter);
>  
>  	*enable = priv->enabled;
>  
> @@ -47,7 +47,7 @@ static int interrupt_cnt_enable_read(struct counter_device *counter,
>  static int interrupt_cnt_enable_write(struct counter_device *counter,
>  				      struct counter_count *count, u8 enable)
>  {
> -	struct interrupt_cnt_priv *priv = counter->priv;
> +	struct interrupt_cnt_priv *priv = counter_priv(counter);
>  
>  	if (priv->enabled == enable)
>  		return 0;
> @@ -85,7 +85,7 @@ static int interrupt_cnt_action_read(struct counter_device *counter,
>  static int interrupt_cnt_read(struct counter_device *counter,
>  			      struct counter_count *count, u64 *val)
>  {
> -	struct interrupt_cnt_priv *priv = counter->priv;
> +	struct interrupt_cnt_priv *priv = counter_priv(counter);
>  
>  	*val = atomic_read(&priv->count);
>  
> @@ -95,7 +95,7 @@ static int interrupt_cnt_read(struct counter_device *counter,
>  static int interrupt_cnt_write(struct counter_device *counter,
>  			       struct counter_count *count, const u64 val)
>  {
> -	struct interrupt_cnt_priv *priv = counter->priv;
> +	struct interrupt_cnt_priv *priv = counter_priv(counter);
>  
>  	if (val != (typeof(priv->count.counter))val)
>  		return -ERANGE;
> @@ -122,7 +122,7 @@ static int interrupt_cnt_signal_read(struct counter_device *counter,
>  				     struct counter_signal *signal,
>  				     enum counter_signal_level *level)
>  {
> -	struct interrupt_cnt_priv *priv = counter->priv;
> +	struct interrupt_cnt_priv *priv = counter_priv(counter);
>  	int ret;
>  
>  	if (!priv->gpio)


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

* Re: [PATCH v2 07/23] counter: microchip-tcb-capture: Convert to counter_priv() wrapper
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-28 18:05     ` Jonathan Cameron
  -1 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:05 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Kamel Bouhara, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:10 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
(doing these individually in case your use b4 to pick up tags
as I don't think it can interpret a tag for last N patches :)


> ---
>  drivers/counter/microchip-tcb-capture.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index bb69f2e0ba93..1b56b7444668 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -72,7 +72,7 @@ static int mchp_tc_count_function_read(struct counter_device *counter,
>  				       struct counter_count *count,
>  				       enum counter_function *function)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  
>  	if (priv->qdec_mode)
>  		*function = COUNTER_FUNCTION_QUADRATURE_X4;
> @@ -86,7 +86,7 @@ static int mchp_tc_count_function_write(struct counter_device *counter,
>  					struct counter_count *count,
>  					enum counter_function function)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 bmr, cmr;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_BMR, &bmr);
> @@ -148,7 +148,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter,
>  				     struct counter_signal *signal,
>  				     enum counter_signal_level *lvl)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	bool sigstatus;
>  	u32 sr;
>  
> @@ -169,7 +169,7 @@ static int mchp_tc_count_action_read(struct counter_device *counter,
>  				     struct counter_synapse *synapse,
>  				     enum counter_synapse_action *action)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 cmr;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
> @@ -197,7 +197,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
>  				      struct counter_synapse *synapse,
>  				      enum counter_synapse_action action)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 edge = ATMEL_TC_ETRGEDG_NONE;
>  
>  	/* QDEC mode is rising edge only */
> @@ -230,7 +230,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
>  static int mchp_tc_count_read(struct counter_device *counter,
>  			      struct counter_count *count, u64 *val)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 cnt;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CV), &cnt);


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

* Re: [PATCH v2 07/23] counter: microchip-tcb-capture: Convert to counter_priv() wrapper
@ 2021-12-28 18:05     ` Jonathan Cameron
  0 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:05 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Kamel Bouhara, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:10 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
(doing these individually in case your use b4 to pick up tags
as I don't think it can interpret a tag for last N patches :)


> ---
>  drivers/counter/microchip-tcb-capture.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index bb69f2e0ba93..1b56b7444668 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -72,7 +72,7 @@ static int mchp_tc_count_function_read(struct counter_device *counter,
>  				       struct counter_count *count,
>  				       enum counter_function *function)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  
>  	if (priv->qdec_mode)
>  		*function = COUNTER_FUNCTION_QUADRATURE_X4;
> @@ -86,7 +86,7 @@ static int mchp_tc_count_function_write(struct counter_device *counter,
>  					struct counter_count *count,
>  					enum counter_function function)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 bmr, cmr;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_BMR, &bmr);
> @@ -148,7 +148,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter,
>  				     struct counter_signal *signal,
>  				     enum counter_signal_level *lvl)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	bool sigstatus;
>  	u32 sr;
>  
> @@ -169,7 +169,7 @@ static int mchp_tc_count_action_read(struct counter_device *counter,
>  				     struct counter_synapse *synapse,
>  				     enum counter_synapse_action *action)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 cmr;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
> @@ -197,7 +197,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
>  				      struct counter_synapse *synapse,
>  				      enum counter_synapse_action action)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 edge = ATMEL_TC_ETRGEDG_NONE;
>  
>  	/* QDEC mode is rising edge only */
> @@ -230,7 +230,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
>  static int mchp_tc_count_read(struct counter_device *counter,
>  			      struct counter_count *count, u64 *val)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 cnt;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CV), &cnt);


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 08/23] counter: intel-qep: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` [PATCH v2 08/23] counter: intel-qep: " Uwe Kleine-König
@ 2021-12-28 18:06   ` Jonathan Cameron
  2021-12-29  7:35   ` William Breathitt Gray
  2021-12-29 12:43   ` Jarkko Nikula
  2 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:06 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Jarkko Nikula, Felipe Balbi (Intel),
	Raymond Tan

On Mon, 27 Dec 2021 10:45:11 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/intel-qep.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c
> index 0924d16de6e2..8f84a48508ac 100644
> --- a/drivers/counter/intel-qep.c
> +++ b/drivers/counter/intel-qep.c
> @@ -109,7 +109,7 @@ static void intel_qep_init(struct intel_qep *qep)
>  static int intel_qep_count_read(struct counter_device *counter,
>  				struct counter_count *count, u64 *val)
>  {
> -	struct intel_qep *const qep = counter->priv;
> +	struct intel_qep *const qep = counter_priv(counter);
>  
>  	pm_runtime_get_sync(qep->dev);
>  	*val = intel_qep_readl(qep, INTEL_QEPCOUNT);
> @@ -176,7 +176,7 @@ static struct counter_synapse intel_qep_count_synapses[] = {
>  static int intel_qep_ceiling_read(struct counter_device *counter,
>  				  struct counter_count *count, u64 *ceiling)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  
>  	pm_runtime_get_sync(qep->dev);
>  	*ceiling = intel_qep_readl(qep, INTEL_QEPMAX);
> @@ -188,7 +188,7 @@ static int intel_qep_ceiling_read(struct counter_device *counter,
>  static int intel_qep_ceiling_write(struct counter_device *counter,
>  				   struct counter_count *count, u64 max)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	int ret = 0;
>  
>  	/* Intel QEP ceiling configuration only supports 32-bit values */
> @@ -213,7 +213,7 @@ static int intel_qep_ceiling_write(struct counter_device *counter,
>  static int intel_qep_enable_read(struct counter_device *counter,
>  				 struct counter_count *count, u8 *enable)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  
>  	*enable = qep->enabled;
>  
> @@ -223,7 +223,7 @@ static int intel_qep_enable_read(struct counter_device *counter,
>  static int intel_qep_enable_write(struct counter_device *counter,
>  				  struct counter_count *count, u8 val)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	u32 reg;
>  	bool changed;
>  
> @@ -256,7 +256,7 @@ static int intel_qep_spike_filter_ns_read(struct counter_device *counter,
>  					  struct counter_count *count,
>  					  u64 *length)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	u32 reg;
>  
>  	pm_runtime_get_sync(qep->dev);
> @@ -277,7 +277,7 @@ static int intel_qep_spike_filter_ns_write(struct counter_device *counter,
>  					   struct counter_count *count,
>  					   u64 length)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	u32 reg;
>  	bool enable;
>  	int ret = 0;
> @@ -326,7 +326,7 @@ static int intel_qep_preset_enable_read(struct counter_device *counter,
>  					struct counter_count *count,
>  					u8 *preset_enable)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	u32 reg;
>  
>  	pm_runtime_get_sync(qep->dev);
> @@ -341,7 +341,7 @@ static int intel_qep_preset_enable_read(struct counter_device *counter,
>  static int intel_qep_preset_enable_write(struct counter_device *counter,
>  					 struct counter_count *count, u8 val)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	u32 reg;
>  	int ret = 0;
>  


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

* Re: [PATCH v2 09/23] counter: ftm-quaddec: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` [PATCH v2 09/23] counter: ftm-quaddec: " Uwe Kleine-König
@ 2021-12-28 18:07   ` Jonathan Cameron
  2021-12-29  7:36   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:07 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Patrick Havelange, Syed Nayyar Waris

On Mon, 27 Dec 2021 10:45:12 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/ftm-quaddec.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> index 9272f7b58beb..f5d92df6a611 100644
> --- a/drivers/counter/ftm-quaddec.c
> +++ b/drivers/counter/ftm-quaddec.c
> @@ -118,7 +118,7 @@ static void ftm_quaddec_disable(void *ftm)
>  static int ftm_quaddec_get_prescaler(struct counter_device *counter,
>  				     struct counter_count *count, u32 *cnt_mode)
>  {
> -	struct ftm_quaddec *ftm = counter->priv;
> +	struct ftm_quaddec *ftm = counter_priv(counter);
>  	uint32_t scflags;
>  
>  	ftm_read(ftm, FTM_SC, &scflags);
> @@ -131,7 +131,7 @@ static int ftm_quaddec_get_prescaler(struct counter_device *counter,
>  static int ftm_quaddec_set_prescaler(struct counter_device *counter,
>  				     struct counter_count *count, u32 cnt_mode)
>  {
> -	struct ftm_quaddec *ftm = counter->priv;
> +	struct ftm_quaddec *ftm = counter_priv(counter);
>  
>  	mutex_lock(&ftm->ftm_quaddec_mutex);
>  
> @@ -162,7 +162,7 @@ static int ftm_quaddec_count_read(struct counter_device *counter,
>  				  struct counter_count *count,
>  				  u64 *val)
>  {
> -	struct ftm_quaddec *const ftm = counter->priv;
> +	struct ftm_quaddec *const ftm = counter_priv(counter);
>  	uint32_t cntval;
>  
>  	ftm_read(ftm, FTM_CNT, &cntval);
> @@ -176,7 +176,7 @@ static int ftm_quaddec_count_write(struct counter_device *counter,
>  				   struct counter_count *count,
>  				   const u64 val)
>  {
> -	struct ftm_quaddec *const ftm = counter->priv;
> +	struct ftm_quaddec *const ftm = counter_priv(counter);
>  
>  	if (val != 0) {
>  		dev_warn(&ftm->pdev->dev, "Can only accept '0' as new counter value\n");


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

* Re: [PATCH v2 10/23] counter: ti-eqep: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` [PATCH v2 10/23] counter: ti-eqep: " Uwe Kleine-König
@ 2021-12-28 18:07   ` Jonathan Cameron
  2021-12-29  7:45   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:07 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	David Lechner

On Mon, 27 Dec 2021 10:45:13 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/ti-eqep.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
> index 09817c953f9a..abeda966e7be 100644
> --- a/drivers/counter/ti-eqep.c
> +++ b/drivers/counter/ti-eqep.c
> @@ -90,7 +90,7 @@ struct ti_eqep_cnt {
>  static int ti_eqep_count_read(struct counter_device *counter,
>  			      struct counter_count *count, u64 *val)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	u32 cnt;
>  
>  	regmap_read(priv->regmap32, QPOSCNT, &cnt);
> @@ -102,7 +102,7 @@ static int ti_eqep_count_read(struct counter_device *counter,
>  static int ti_eqep_count_write(struct counter_device *counter,
>  			       struct counter_count *count, u64 val)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	u32 max;
>  
>  	regmap_read(priv->regmap32, QPOSMAX, &max);
> @@ -116,7 +116,7 @@ static int ti_eqep_function_read(struct counter_device *counter,
>  				 struct counter_count *count,
>  				 enum counter_function *function)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	u32 qdecctl;
>  
>  	regmap_read(priv->regmap16, QDECCTL, &qdecctl);
> @@ -143,7 +143,7 @@ static int ti_eqep_function_write(struct counter_device *counter,
>  				  struct counter_count *count,
>  				  enum counter_function function)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	enum ti_eqep_count_func qsrc;
>  
>  	switch (function) {
> @@ -173,7 +173,7 @@ static int ti_eqep_action_read(struct counter_device *counter,
>  			       struct counter_synapse *synapse,
>  			       enum counter_synapse_action *action)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	enum counter_function function;
>  	u32 qdecctl;
>  	int err;
> @@ -245,7 +245,7 @@ static int ti_eqep_position_ceiling_read(struct counter_device *counter,
>  					 struct counter_count *count,
>  					 u64 *ceiling)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	u32 qposmax;
>  
>  	regmap_read(priv->regmap32, QPOSMAX, &qposmax);
> @@ -259,7 +259,7 @@ static int ti_eqep_position_ceiling_write(struct counter_device *counter,
>  					  struct counter_count *count,
>  					  u64 ceiling)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  
>  	if (ceiling != (u32)ceiling)
>  		return -ERANGE;
> @@ -272,7 +272,7 @@ static int ti_eqep_position_ceiling_write(struct counter_device *counter,
>  static int ti_eqep_position_enable_read(struct counter_device *counter,
>  					struct counter_count *count, u8 *enable)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	u32 qepctl;
>  
>  	regmap_read(priv->regmap16, QEPCTL, &qepctl);
> @@ -285,7 +285,7 @@ static int ti_eqep_position_enable_read(struct counter_device *counter,
>  static int ti_eqep_position_enable_write(struct counter_device *counter,
>  					 struct counter_count *count, u8 enable)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  
>  	regmap_write_bits(priv->regmap16, QEPCTL, QEPCTL_PHEN, enable ? -1 : 0);
>  


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

* Re: [PATCH v2 11/23] counter: stm32-lptimer-cnt: Convert to counter_priv() wrapper
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-28 18:08     ` Jonathan Cameron
  -1 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:08 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:14 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/stm32-lptimer-cnt.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
> index 5168833b1fdf..9cf00e929cc0 100644
> --- a/drivers/counter/stm32-lptimer-cnt.c
> +++ b/drivers/counter/stm32-lptimer-cnt.c
> @@ -141,7 +141,7 @@ static const enum counter_synapse_action stm32_lptim_cnt_synapse_actions[] = {
>  static int stm32_lptim_cnt_read(struct counter_device *counter,
>  				struct counter_count *count, u64 *val)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	u32 cnt;
>  	int ret;
>  
> @@ -158,7 +158,7 @@ static int stm32_lptim_cnt_function_read(struct counter_device *counter,
>  					 struct counter_count *count,
>  					 enum counter_function *function)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (!priv->quadrature_mode) {
>  		*function = COUNTER_FUNCTION_INCREASE;
> @@ -177,7 +177,7 @@ static int stm32_lptim_cnt_function_write(struct counter_device *counter,
>  					  struct counter_count *count,
>  					  enum counter_function function)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (stm32_lptim_is_enabled(priv))
>  		return -EBUSY;
> @@ -200,7 +200,7 @@ static int stm32_lptim_cnt_enable_read(struct counter_device *counter,
>  				       struct counter_count *count,
>  				       u8 *enable)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	int ret;
>  
>  	ret = stm32_lptim_is_enabled(priv);
> @@ -216,7 +216,7 @@ static int stm32_lptim_cnt_enable_write(struct counter_device *counter,
>  					struct counter_count *count,
>  					u8 enable)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	int ret;
>  
>  	/* Check nobody uses the timer, or already disabled/enabled */
> @@ -241,7 +241,7 @@ static int stm32_lptim_cnt_ceiling_read(struct counter_device *counter,
>  					struct counter_count *count,
>  					u64 *ceiling)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	*ceiling = priv->ceiling;
>  
> @@ -252,7 +252,7 @@ static int stm32_lptim_cnt_ceiling_write(struct counter_device *counter,
>  					 struct counter_count *count,
>  					 u64 ceiling)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (stm32_lptim_is_enabled(priv))
>  		return -EBUSY;
> @@ -277,7 +277,7 @@ static int stm32_lptim_cnt_action_read(struct counter_device *counter,
>  				       struct counter_synapse *synapse,
>  				       enum counter_synapse_action *action)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	enum counter_function function;
>  	int err;
>  
> @@ -321,7 +321,7 @@ static int stm32_lptim_cnt_action_write(struct counter_device *counter,
>  					struct counter_synapse *synapse,
>  					enum counter_synapse_action action)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	enum counter_function function;
>  	int err;
>  


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

* Re: [PATCH v2 11/23] counter: stm32-lptimer-cnt: Convert to counter_priv() wrapper
@ 2021-12-28 18:08     ` Jonathan Cameron
  0 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:08 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:14 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/stm32-lptimer-cnt.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
> index 5168833b1fdf..9cf00e929cc0 100644
> --- a/drivers/counter/stm32-lptimer-cnt.c
> +++ b/drivers/counter/stm32-lptimer-cnt.c
> @@ -141,7 +141,7 @@ static const enum counter_synapse_action stm32_lptim_cnt_synapse_actions[] = {
>  static int stm32_lptim_cnt_read(struct counter_device *counter,
>  				struct counter_count *count, u64 *val)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	u32 cnt;
>  	int ret;
>  
> @@ -158,7 +158,7 @@ static int stm32_lptim_cnt_function_read(struct counter_device *counter,
>  					 struct counter_count *count,
>  					 enum counter_function *function)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (!priv->quadrature_mode) {
>  		*function = COUNTER_FUNCTION_INCREASE;
> @@ -177,7 +177,7 @@ static int stm32_lptim_cnt_function_write(struct counter_device *counter,
>  					  struct counter_count *count,
>  					  enum counter_function function)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (stm32_lptim_is_enabled(priv))
>  		return -EBUSY;
> @@ -200,7 +200,7 @@ static int stm32_lptim_cnt_enable_read(struct counter_device *counter,
>  				       struct counter_count *count,
>  				       u8 *enable)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	int ret;
>  
>  	ret = stm32_lptim_is_enabled(priv);
> @@ -216,7 +216,7 @@ static int stm32_lptim_cnt_enable_write(struct counter_device *counter,
>  					struct counter_count *count,
>  					u8 enable)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	int ret;
>  
>  	/* Check nobody uses the timer, or already disabled/enabled */
> @@ -241,7 +241,7 @@ static int stm32_lptim_cnt_ceiling_read(struct counter_device *counter,
>  					struct counter_count *count,
>  					u64 *ceiling)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	*ceiling = priv->ceiling;
>  
> @@ -252,7 +252,7 @@ static int stm32_lptim_cnt_ceiling_write(struct counter_device *counter,
>  					 struct counter_count *count,
>  					 u64 ceiling)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (stm32_lptim_is_enabled(priv))
>  		return -EBUSY;
> @@ -277,7 +277,7 @@ static int stm32_lptim_cnt_action_read(struct counter_device *counter,
>  				       struct counter_synapse *synapse,
>  				       enum counter_synapse_action *action)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	enum counter_function function;
>  	int err;
>  
> @@ -321,7 +321,7 @@ static int stm32_lptim_cnt_action_write(struct counter_device *counter,
>  					struct counter_synapse *synapse,
>  					enum counter_synapse_action action)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	enum counter_function function;
>  	int err;
>  


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 12/23] counter: stm32-timer-cnt: Convert to counter_priv() wrapper
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-28 18:08     ` Jonathan Cameron
  -1 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:08 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:15 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/stm32-timer-cnt.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
> index 0546e932db0c..4b05b198a8d8 100644
> --- a/drivers/counter/stm32-timer-cnt.c
> +++ b/drivers/counter/stm32-timer-cnt.c
> @@ -47,7 +47,7 @@ static const enum counter_function stm32_count_functions[] = {
>  static int stm32_count_read(struct counter_device *counter,
>  			    struct counter_count *count, u64 *val)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cnt;
>  
>  	regmap_read(priv->regmap, TIM_CNT, &cnt);
> @@ -59,7 +59,7 @@ static int stm32_count_read(struct counter_device *counter,
>  static int stm32_count_write(struct counter_device *counter,
>  			     struct counter_count *count, const u64 val)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 ceiling;
>  
>  	regmap_read(priv->regmap, TIM_ARR, &ceiling);
> @@ -73,7 +73,7 @@ static int stm32_count_function_read(struct counter_device *counter,
>  				     struct counter_count *count,
>  				     enum counter_function *function)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 smcr;
>  
>  	regmap_read(priv->regmap, TIM_SMCR, &smcr);
> @@ -100,7 +100,7 @@ static int stm32_count_function_write(struct counter_device *counter,
>  				      struct counter_count *count,
>  				      enum counter_function function)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1, sms;
>  
>  	switch (function) {
> @@ -140,7 +140,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
>  				      struct counter_count *count,
>  				      enum counter_count_direction *direction)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	regmap_read(priv->regmap, TIM_CR1, &cr1);
> @@ -153,7 +153,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
>  static int stm32_count_ceiling_read(struct counter_device *counter,
>  				    struct counter_count *count, u64 *ceiling)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 arr;
>  
>  	regmap_read(priv->regmap, TIM_ARR, &arr);
> @@ -166,7 +166,7 @@ static int stm32_count_ceiling_read(struct counter_device *counter,
>  static int stm32_count_ceiling_write(struct counter_device *counter,
>  				     struct counter_count *count, u64 ceiling)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  
>  	if (ceiling > priv->max_arr)
>  		return -ERANGE;
> @@ -181,7 +181,7 @@ static int stm32_count_ceiling_write(struct counter_device *counter,
>  static int stm32_count_enable_read(struct counter_device *counter,
>  				   struct counter_count *count, u8 *enable)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	regmap_read(priv->regmap, TIM_CR1, &cr1);
> @@ -194,7 +194,7 @@ static int stm32_count_enable_read(struct counter_device *counter,
>  static int stm32_count_enable_write(struct counter_device *counter,
>  				    struct counter_count *count, u8 enable)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	if (enable) {


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

* Re: [PATCH v2 12/23] counter: stm32-timer-cnt: Convert to counter_priv() wrapper
@ 2021-12-28 18:08     ` Jonathan Cameron
  0 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:08 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:15 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/stm32-timer-cnt.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
> index 0546e932db0c..4b05b198a8d8 100644
> --- a/drivers/counter/stm32-timer-cnt.c
> +++ b/drivers/counter/stm32-timer-cnt.c
> @@ -47,7 +47,7 @@ static const enum counter_function stm32_count_functions[] = {
>  static int stm32_count_read(struct counter_device *counter,
>  			    struct counter_count *count, u64 *val)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cnt;
>  
>  	regmap_read(priv->regmap, TIM_CNT, &cnt);
> @@ -59,7 +59,7 @@ static int stm32_count_read(struct counter_device *counter,
>  static int stm32_count_write(struct counter_device *counter,
>  			     struct counter_count *count, const u64 val)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 ceiling;
>  
>  	regmap_read(priv->regmap, TIM_ARR, &ceiling);
> @@ -73,7 +73,7 @@ static int stm32_count_function_read(struct counter_device *counter,
>  				     struct counter_count *count,
>  				     enum counter_function *function)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 smcr;
>  
>  	regmap_read(priv->regmap, TIM_SMCR, &smcr);
> @@ -100,7 +100,7 @@ static int stm32_count_function_write(struct counter_device *counter,
>  				      struct counter_count *count,
>  				      enum counter_function function)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1, sms;
>  
>  	switch (function) {
> @@ -140,7 +140,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
>  				      struct counter_count *count,
>  				      enum counter_count_direction *direction)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	regmap_read(priv->regmap, TIM_CR1, &cr1);
> @@ -153,7 +153,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
>  static int stm32_count_ceiling_read(struct counter_device *counter,
>  				    struct counter_count *count, u64 *ceiling)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 arr;
>  
>  	regmap_read(priv->regmap, TIM_ARR, &arr);
> @@ -166,7 +166,7 @@ static int stm32_count_ceiling_read(struct counter_device *counter,
>  static int stm32_count_ceiling_write(struct counter_device *counter,
>  				     struct counter_count *count, u64 ceiling)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  
>  	if (ceiling > priv->max_arr)
>  		return -ERANGE;
> @@ -181,7 +181,7 @@ static int stm32_count_ceiling_write(struct counter_device *counter,
>  static int stm32_count_enable_read(struct counter_device *counter,
>  				   struct counter_count *count, u8 *enable)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	regmap_read(priv->regmap, TIM_CR1, &cr1);
> @@ -194,7 +194,7 @@ static int stm32_count_enable_read(struct counter_device *counter,
>  static int stm32_count_enable_write(struct counter_device *counter,
>  				    struct counter_count *count, u8 enable)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	if (enable) {


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 14/23] counter: Update documentation for new counter registration functions
  2021-12-27  9:45 ` [PATCH v2 14/23] counter: Update documentation for new " Uwe Kleine-König
@ 2021-12-28 18:12   ` Jonathan Cameron
  2021-12-29  8:19     ` William Breathitt Gray
  0 siblings, 1 reply; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:12 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Jonathan Corbet, linux-doc

On Mon, 27 Dec 2021 10:45:17 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> In order to replace the counter registration API also update the
> documentation to the new way.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Fine either way, but a suggestion below.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  Documentation/driver-api/generic-counter.rst | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/Documentation/driver-api/generic-counter.rst b/Documentation/driver-api/generic-counter.rst
> index 1b487a331467..991b180c7b47 100644
> --- a/Documentation/driver-api/generic-counter.rst
> +++ b/Documentation/driver-api/generic-counter.rst
> @@ -262,11 +262,11 @@ order to communicate with the device: to read and write various Signals
>  and Counts, and to set and get the "action mode" and "function mode" for
>  various Synapses and Counts respectively.
>  
> -A defined counter_device structure may be registered to the system by
> -passing it to the counter_register function, and unregistered by passing
> -it to the counter_unregister function. Similarly, the
> -devm_counter_register function may be used if device memory-managed
> -registration is desired.
> +A counter_device structure is supposed to be allocated using counter_alloc()
> +and may be registered to the system by passing it to the counter_add()
> +function, and unregistered by passing it to the counter_unregister function.

I'd avoid the supposed to and the odd vague use of structure in the origin
text and just go with

A struct counter_device is allocated using counter_alloc()...


> +There are device managed variants of these functions: devm_counter_alloc() and
> +devm_counter_add().
>  
>  The struct counter_comp structure is used to define counter extensions
>  for Signals, Synapses, and Counts.


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

* Re: [PATCH v2 15/23] counter: 104-quad-8: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 15/23] counter: 104-quad-8: Convert to new counter registration Uwe Kleine-König
  2021-12-27 12:19   ` Lars-Peter Clausen
@ 2021-12-28 18:17   ` Jonathan Cameron
  2021-12-29  8:24   ` William Breathitt Gray
  2 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:17 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Syed Nayyar Waris

On Mon, 27 Dec 2021 10:45:18 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: f1d8a071d45b ("counter: 104-quad-8: Add Generic Counter interface support")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
LGTM

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/counter/104-quad-8.c | 30 +++++++++++++++++-------------
>  1 file changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
> index 6e5286cd1d4e..4315b14f239e 100644
> --- a/drivers/counter/104-quad-8.c
> +++ b/drivers/counter/104-quad-8.c
> @@ -52,7 +52,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-QUAD-8 interrupt line numbers");
>   */
>  struct quad8 {
>  	spinlock_t lock;
> -	struct counter_device counter;
>  	unsigned int fck_prescaler[QUAD8_NUM_COUNTERS];
>  	unsigned int preset[QUAD8_NUM_COUNTERS];
>  	unsigned int count_mode[QUAD8_NUM_COUNTERS];
> @@ -1127,6 +1126,7 @@ static irqreturn_t quad8_irq_handler(int irq, void *private)
>  
>  static int quad8_probe(struct device *dev, unsigned int id)
>  {
> +	struct counter_device *counter;
>  	struct quad8 *priv;
>  	int i, j;
>  	unsigned int base_offset;
> @@ -1138,19 +1138,19 @@ static int quad8_probe(struct device *dev, unsigned int id)
>  		return -EBUSY;
>  	}
>  
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	/* Initialize Counter device and driver data */
> -	priv->counter.name = dev_name(dev);
> -	priv->counter.parent = dev;
> -	priv->counter.ops = &quad8_ops;
> -	priv->counter.counts = quad8_counts;
> -	priv->counter.num_counts = ARRAY_SIZE(quad8_counts);
> -	priv->counter.signals = quad8_signals;
> -	priv->counter.num_signals = ARRAY_SIZE(quad8_signals);
> -	priv->counter.priv = priv;
> +	counter->name = dev_name(dev);
> +	counter->parent = dev;
> +	counter->ops = &quad8_ops;
> +	counter->counts = quad8_counts;
> +	counter->num_counts = ARRAY_SIZE(quad8_counts);
> +	counter->signals = quad8_signals;
> +	counter->num_signals = ARRAY_SIZE(quad8_signals);
>  	priv->base = base[id];
>  
>  	spin_lock_init(&priv->lock);
> @@ -1192,11 +1192,15 @@ static int quad8_probe(struct device *dev, unsigned int id)
>  	outb(QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC, base[id] + QUAD8_REG_CHAN_OP);
>  
>  	err = devm_request_irq(dev, irq[id], quad8_irq_handler, IRQF_SHARED,
> -			       priv->counter.name, priv);
> +			       counter->name, priv);
>  	if (err)
>  		return err;
>  
> -	return devm_counter_register(dev, &priv->counter);
> +	err = devm_counter_add(dev, counter);
> +	if (err < 0)
> +		return dev_err_probe(dev, err, "Failed to add counter\n");
> +
> +	return 0;
>  }
>  
>  static struct isa_driver quad8_driver = {


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

* Re: [PATCH v2 16/23] counter: interrupt-cnt: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 16/23] counter: interrupt-cnt: " Uwe Kleine-König
  2021-12-27 10:59   ` Greg Kroah-Hartman
@ 2021-12-28 18:18   ` Jonathan Cameron
  2021-12-29  8:27   ` William Breathitt Gray
  2 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:18 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Ahmad Fatoum, Oleksij Rempel

On Mon, 27 Dec 2021 10:45:19 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: a55ebd47f21f ("counter: add IRQ or GPIO based counter")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

LGTM
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/interrupt-cnt.c | 28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c
> index 4bf706ef46e2..9e99702470c2 100644
> --- a/drivers/counter/interrupt-cnt.c
> +++ b/drivers/counter/interrupt-cnt.c
> @@ -16,7 +16,6 @@
>  
>  struct interrupt_cnt_priv {
>  	atomic_t count;
> -	struct counter_device counter;
>  	struct gpio_desc *gpio;
>  	int irq;
>  	bool enabled;
> @@ -148,12 +147,14 @@ static const struct counter_ops interrupt_cnt_ops = {
>  static int interrupt_cnt_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> +	struct counter_device *counter;
>  	struct interrupt_cnt_priv *priv;
>  	int ret;
>  
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	priv->irq = platform_get_irq_optional(pdev,  0);
>  	if (priv->irq == -ENXIO)
> @@ -184,8 +185,8 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
>  	if (!priv->signals.name)
>  		return -ENOMEM;
>  
> -	priv->counter.signals = &priv->signals;
> -	priv->counter.num_signals = 1;
> +	counter->signals = &priv->signals;
> +	counter->num_signals = 1;
>  
>  	priv->synapses.actions_list = interrupt_cnt_synapse_actions;
>  	priv->synapses.num_actions = ARRAY_SIZE(interrupt_cnt_synapse_actions);
> @@ -199,12 +200,11 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
>  	priv->cnts.ext = interrupt_cnt_ext;
>  	priv->cnts.num_ext = ARRAY_SIZE(interrupt_cnt_ext);
>  
> -	priv->counter.priv = priv;
> -	priv->counter.name = dev_name(dev);
> -	priv->counter.parent = dev;
> -	priv->counter.ops = &interrupt_cnt_ops;
> -	priv->counter.counts = &priv->cnts;
> -	priv->counter.num_counts = 1;
> +	counter->name = dev_name(dev);
> +	counter->parent = dev;
> +	counter->ops = &interrupt_cnt_ops;
> +	counter->counts = &priv->cnts;
> +	counter->num_counts = 1;
>  
>  	irq_set_status_flags(priv->irq, IRQ_NOAUTOEN);
>  	ret = devm_request_irq(dev, priv->irq, interrupt_cnt_isr,
> @@ -213,7 +213,11 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	return devm_counter_register(dev, &priv->counter);
> +	ret = devm_counter_add(dev, counter);
> +	if (ret < 0)
> +		return dev_err_probe(dev, ret, "Failed to add counter\n");
> +
> +	return 0;
>  }
>  
>  static const struct of_device_id interrupt_cnt_of_match[] = {


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

* Re: [PATCH v2 17/23] counter: intel-qep: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 17/23] counter: intel-qep: " Uwe Kleine-König
  2021-12-27 15:02   ` Jarkko Nikula
@ 2021-12-28 18:20   ` Jonathan Cameron
  2021-12-29  8:29   ` William Breathitt Gray
  2 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:20 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Jarkko Nikula, Felipe Balbi (Intel),
	Raymond Tan

On Mon, 27 Dec 2021 10:45:20 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: b711f687a1c1 ("counter: Add support for Intel Quadrature Encoder Peripheral")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
FWIW given these are all more or less the same...

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/intel-qep.c | 28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c
> index 8f84a48508ac..47a6a9dfc9e8 100644
> --- a/drivers/counter/intel-qep.c
> +++ b/drivers/counter/intel-qep.c
> @@ -63,7 +63,6 @@
>  #define INTEL_QEP_CLK_PERIOD_NS		10
>  
>  struct intel_qep {
> -	struct counter_device counter;
>  	struct mutex lock;
>  	struct device *dev;
>  	void __iomem *regs;
> @@ -392,14 +391,16 @@ static struct counter_count intel_qep_counter_count[] = {
>  
>  static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id)
>  {
> +	struct counter_device *counter;
>  	struct intel_qep *qep;
>  	struct device *dev = &pci->dev;
>  	void __iomem *regs;
>  	int ret;
>  
> -	qep = devm_kzalloc(dev, sizeof(*qep), GFP_KERNEL);
> -	if (!qep)
> +	counter = devm_counter_alloc(dev, sizeof(*qep));
> +	if (!counter)
>  		return -ENOMEM;
> +	qep = counter_priv(counter);
>  
>  	ret = pcim_enable_device(pci);
>  	if (ret)
> @@ -422,20 +423,23 @@ static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id)
>  	intel_qep_init(qep);
>  	pci_set_drvdata(pci, qep);
>  
> -	qep->counter.name = pci_name(pci);
> -	qep->counter.parent = dev;
> -	qep->counter.ops = &intel_qep_counter_ops;
> -	qep->counter.counts = intel_qep_counter_count;
> -	qep->counter.num_counts = ARRAY_SIZE(intel_qep_counter_count);
> -	qep->counter.signals = intel_qep_signals;
> -	qep->counter.num_signals = ARRAY_SIZE(intel_qep_signals);
> -	qep->counter.priv = qep;
> +	counter->name = pci_name(pci);
> +	counter->parent = dev;
> +	counter->ops = &intel_qep_counter_ops;
> +	counter->counts = intel_qep_counter_count;
> +	counter->num_counts = ARRAY_SIZE(intel_qep_counter_count);
> +	counter->signals = intel_qep_signals;
> +	counter->num_signals = ARRAY_SIZE(intel_qep_signals);
>  	qep->enabled = false;
>  
>  	pm_runtime_put(dev);
>  	pm_runtime_allow(dev);
>  
> -	return devm_counter_register(&pci->dev, &qep->counter);
> +	ret = devm_counter_add(&pci->dev, counter);
> +	if (ret < 0)
> +		return dev_err_probe(&pci->dev, ret, "Failed to add counter\n");
> +
> +	return 0;
>  }
>  
>  static void intel_qep_remove(struct pci_dev *pci)


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

* Re: [PATCH v2 18/23] counter: ftm-quaddec: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 18/23] counter: ftm-quaddec: " Uwe Kleine-König
@ 2021-12-28 18:23   ` Jonathan Cameron
  2021-12-29  8:33   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:23 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Syed Nayyar Waris, Patrick Havelange

On Mon, 27 Dec 2021 10:45:21 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Assuming you move the 104-quad-8 stuff to the earlier patch.


> ---
>  drivers/counter/104-quad-8.c  |  7 ++++---
>  drivers/counter/ftm-quaddec.c | 27 +++++++++++++--------------
>  2 files changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
> index 4315b14f239e..680c7ba943a4 100644
> --- a/drivers/counter/104-quad-8.c
> +++ b/drivers/counter/104-quad-8.c

Block in wrong patch. I'll assume you'll fix that and ignore it beyond saying
this change is fine so keep my RB on the earlier patch once you've added this block.

> @@ -1084,7 +1084,8 @@ static struct counter_count quad8_counts[] = {
>  
>  static irqreturn_t quad8_irq_handler(int irq, void *private)
>  {
> -	struct quad8 *const priv = private;
> +	struct counter_device *counter = private;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const unsigned long base = priv->base;
>  	unsigned long irq_status;
>  	unsigned long channel;
> @@ -1115,7 +1116,7 @@ static irqreturn_t quad8_irq_handler(int irq, void *private)
>  			continue;
>  		}
>  
> -		counter_push_event(&priv->counter, event, channel);
> +		counter_push_event(counter, event, channel);
>  	}
>  
>  	/* Clear pending interrupts on device */
> @@ -1192,7 +1193,7 @@ static int quad8_probe(struct device *dev, unsigned int id)
>  	outb(QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC, base[id] + QUAD8_REG_CHAN_OP);
>  
>  	err = devm_request_irq(dev, irq[id], quad8_irq_handler, IRQF_SHARED,
> -			       counter->name, priv);
> +			       counter->name, counter);
>  	if (err)
>  		return err;
>  
> diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> index f5d92df6a611..c636183b1337 100644
> --- a/drivers/counter/ftm-quaddec.c
> +++ b/drivers/counter/ftm-quaddec.c
> @@ -26,7 +26,6 @@
>  	})
>  
>  struct ftm_quaddec {
> -	struct counter_device counter;
>  	struct platform_device *pdev;
>  	void __iomem *ftm_base;
>  	bool big_endian;
> @@ -259,15 +258,16 @@ static struct counter_count ftm_quaddec_counts = {
>  
>  static int ftm_quaddec_probe(struct platform_device *pdev)
>  {
> +	struct counter_device *counter;
>  	struct ftm_quaddec *ftm;
> -

Try to avoid white space changes in a patch like these even if they seem
trivial.  The 'noise' adds up.

>  	struct device_node *node = pdev->dev.of_node;
>  	struct resource *io;
>  	int ret;
>  
> -	ftm = devm_kzalloc(&pdev->dev, sizeof(*ftm), GFP_KERNEL);
> -	if (!ftm)
> +	counter = devm_counter_alloc(&pdev->dev, sizeof(*ftm));
> +	if (!counter)
>  		return -ENOMEM;
> +	ftm = counter_priv(counter);
>  
>  	io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	if (!io) {
> @@ -283,14 +283,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
>  		dev_err(&pdev->dev, "Failed to map memory region\n");
>  		return -EINVAL;
>  	}
> -	ftm->counter.name = dev_name(&pdev->dev);
> -	ftm->counter.parent = &pdev->dev;
> -	ftm->counter.ops = &ftm_quaddec_cnt_ops;
> -	ftm->counter.counts = &ftm_quaddec_counts;
> -	ftm->counter.num_counts = 1;
> -	ftm->counter.signals = ftm_quaddec_signals;
> -	ftm->counter.num_signals = ARRAY_SIZE(ftm_quaddec_signals);
> -	ftm->counter.priv = ftm;
> +	counter->name = dev_name(&pdev->dev);
> +	counter->parent = &pdev->dev;
> +	counter->ops = &ftm_quaddec_cnt_ops;
> +	counter->counts = &ftm_quaddec_counts;
> +	counter->num_counts = 1;
> +	counter->signals = ftm_quaddec_signals;
> +	counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals);
>  
>  	mutex_init(&ftm->ftm_quaddec_mutex);
>  
> @@ -300,9 +299,9 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	ret = devm_counter_register(&pdev->dev, &ftm->counter);
> +	ret = devm_counter_add(&pdev->dev, counter);
>  	if (ret)
> -		return ret;
> +		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
>  
>  	return 0;
>  }


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

* Re: [PATCH v2 19/23] counter: microchip-tcb-capture: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 19/23] counter: microchip-tcb-capture: " Uwe Kleine-König
@ 2021-12-28 18:24   ` Jonathan Cameron
  2021-12-29  8:36   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:24 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Kamel Bouhara

On Mon, 27 Dec 2021 10:45:22 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: 106b104137fd ("counter: Add microchip TCB capture counter")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/microchip-tcb-capture.c | 30 ++++++++++++++-----------
>  1 file changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index 1b56b7444668..70c1d28546be 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -24,7 +24,6 @@
>  
>  struct mchp_tc_data {
>  	const struct atmel_tcb_config *tc_cfg;
> -	struct counter_device counter;
>  	struct regmap *regmap;
>  	int qdec_mode;
>  	int num_channels;
> @@ -296,6 +295,7 @@ static int mchp_tc_probe(struct platform_device *pdev)
>  	struct device_node *np = pdev->dev.of_node;
>  	const struct atmel_tcb_config *tcb_config;
>  	const struct of_device_id *match;
> +	struct counter_device *counter;
>  	struct mchp_tc_data *priv;
>  	char clk_name[7];
>  	struct regmap *regmap;
> @@ -303,9 +303,10 @@ static int mchp_tc_probe(struct platform_device *pdev)
>  	int channel;
>  	int ret, i;
>  
> -	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(&pdev->dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	match = of_match_node(atmel_tc_of_match, np->parent);
>  	tcb_config = match->data;
> @@ -360,16 +361,19 @@ static int mchp_tc_probe(struct platform_device *pdev)
>  
>  	priv->tc_cfg = tcb_config;
>  	priv->regmap = regmap;
> -	priv->counter.name = dev_name(&pdev->dev);
> -	priv->counter.parent = &pdev->dev;
> -	priv->counter.ops = &mchp_tc_ops;
> -	priv->counter.num_counts = ARRAY_SIZE(mchp_tc_counts);
> -	priv->counter.counts = mchp_tc_counts;
> -	priv->counter.num_signals = ARRAY_SIZE(mchp_tc_count_signals);
> -	priv->counter.signals = mchp_tc_count_signals;
> -	priv->counter.priv = priv;
> -
> -	return devm_counter_register(&pdev->dev, &priv->counter);
> +	counter->name = dev_name(&pdev->dev);
> +	counter->parent = &pdev->dev;
> +	counter->ops = &mchp_tc_ops;
> +	counter->num_counts = ARRAY_SIZE(mchp_tc_counts);
> +	counter->counts = mchp_tc_counts;
> +	counter->num_signals = ARRAY_SIZE(mchp_tc_count_signals);
> +	counter->signals = mchp_tc_count_signals;
> +
> +	ret = devm_counter_add(&pdev->dev, counter);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
> + 
> +	return 0;
>  }
>  
>  static const struct of_device_id mchp_tc_dt_ids[] = {


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

* Re: [PATCH v2 20/23] counter: stm32-timer-cnt: Convert to new counter registration
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-28 18:25     ` Jonathan Cameron
  -1 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:25 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue,
	Benjamin Gaignard, linux-stm32, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:23 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: ad29937e206f ("counter: Add STM32 Timer quadrature encoder")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Same basic form as all the others so easy to review (hopefully :)

Jonathan

> ---
>  drivers/counter/stm32-timer-cnt.c | 30 ++++++++++++++++++------------
>  1 file changed, 18 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
> index 4b05b198a8d8..5779ae7c73cf 100644
> --- a/drivers/counter/stm32-timer-cnt.c
> +++ b/drivers/counter/stm32-timer-cnt.c
> @@ -29,7 +29,6 @@ struct stm32_timer_regs {
>  };
>  
>  struct stm32_timer_cnt {
> -	struct counter_device counter;
>  	struct regmap *regmap;
>  	struct clk *clk;
>  	u32 max_arr;
> @@ -317,31 +316,38 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev)
>  	struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
>  	struct device *dev = &pdev->dev;
>  	struct stm32_timer_cnt *priv;
> +	struct counter_device *counter;
> +	int ret;
>  
>  	if (IS_ERR_OR_NULL(ddata))
>  		return -EINVAL;
>  
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
>  
> +	priv = counter_priv(counter);
> +
>  	priv->regmap = ddata->regmap;
>  	priv->clk = ddata->clk;
>  	priv->max_arr = ddata->max_arr;
>  
> -	priv->counter.name = dev_name(dev);
> -	priv->counter.parent = dev;
> -	priv->counter.ops = &stm32_timer_cnt_ops;
> -	priv->counter.counts = &stm32_counts;
> -	priv->counter.num_counts = 1;
> -	priv->counter.signals = stm32_signals;
> -	priv->counter.num_signals = ARRAY_SIZE(stm32_signals);
> -	priv->counter.priv = priv;
> +	counter->name = dev_name(dev);
> +	counter->parent = dev;
> +	counter->ops = &stm32_timer_cnt_ops;
> +	counter->counts = &stm32_counts;
> +	counter->num_counts = 1;
> +	counter->signals = stm32_signals;
> +	counter->num_signals = ARRAY_SIZE(stm32_signals);
>  
>  	platform_set_drvdata(pdev, priv);
>  
>  	/* Register Counter device */
> -	return devm_counter_register(dev, &priv->counter);
> +	ret = devm_counter_add(dev, counter);
> +	if (ret < 0)
> +		dev_err_probe(dev, ret, "Failed to add counter\n");
> +
> +	return ret;
>  }
>  
>  static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev)


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

* Re: [PATCH v2 20/23] counter: stm32-timer-cnt: Convert to new counter registration
@ 2021-12-28 18:25     ` Jonathan Cameron
  0 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:25 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue,
	Benjamin Gaignard, linux-stm32, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:23 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: ad29937e206f ("counter: Add STM32 Timer quadrature encoder")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Same basic form as all the others so easy to review (hopefully :)

Jonathan

> ---
>  drivers/counter/stm32-timer-cnt.c | 30 ++++++++++++++++++------------
>  1 file changed, 18 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
> index 4b05b198a8d8..5779ae7c73cf 100644
> --- a/drivers/counter/stm32-timer-cnt.c
> +++ b/drivers/counter/stm32-timer-cnt.c
> @@ -29,7 +29,6 @@ struct stm32_timer_regs {
>  };
>  
>  struct stm32_timer_cnt {
> -	struct counter_device counter;
>  	struct regmap *regmap;
>  	struct clk *clk;
>  	u32 max_arr;
> @@ -317,31 +316,38 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev)
>  	struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
>  	struct device *dev = &pdev->dev;
>  	struct stm32_timer_cnt *priv;
> +	struct counter_device *counter;
> +	int ret;
>  
>  	if (IS_ERR_OR_NULL(ddata))
>  		return -EINVAL;
>  
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
>  
> +	priv = counter_priv(counter);
> +
>  	priv->regmap = ddata->regmap;
>  	priv->clk = ddata->clk;
>  	priv->max_arr = ddata->max_arr;
>  
> -	priv->counter.name = dev_name(dev);
> -	priv->counter.parent = dev;
> -	priv->counter.ops = &stm32_timer_cnt_ops;
> -	priv->counter.counts = &stm32_counts;
> -	priv->counter.num_counts = 1;
> -	priv->counter.signals = stm32_signals;
> -	priv->counter.num_signals = ARRAY_SIZE(stm32_signals);
> -	priv->counter.priv = priv;
> +	counter->name = dev_name(dev);
> +	counter->parent = dev;
> +	counter->ops = &stm32_timer_cnt_ops;
> +	counter->counts = &stm32_counts;
> +	counter->num_counts = 1;
> +	counter->signals = stm32_signals;
> +	counter->num_signals = ARRAY_SIZE(stm32_signals);
>  
>  	platform_set_drvdata(pdev, priv);
>  
>  	/* Register Counter device */
> -	return devm_counter_register(dev, &priv->counter);
> +	ret = devm_counter_add(dev, counter);
> +	if (ret < 0)
> +		dev_err_probe(dev, ret, "Failed to add counter\n");
> +
> +	return ret;
>  }
>  
>  static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev)


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 21/23] counter: stm32-lptimer-cnt: Convert to new counter registration
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-28 18:26     ` Jonathan Cameron
  -1 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:26 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue,
	Benjamin Gaignard, linux-stm32, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:24 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: 597f55e3f36c ("counter: stm32-lptimer: add counter device")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/stm32-lptimer-cnt.c | 33 +++++++++++++++++------------
>  1 file changed, 19 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
> index 9cf00e929cc0..68031d93ce89 100644
> --- a/drivers/counter/stm32-lptimer-cnt.c
> +++ b/drivers/counter/stm32-lptimer-cnt.c
> @@ -20,7 +20,6 @@
>  #include <linux/types.h>
>  
>  struct stm32_lptim_cnt {
> -	struct counter_device counter;
>  	struct device *dev;
>  	struct regmap *regmap;
>  	struct clk *clk;
> @@ -411,14 +410,17 @@ static struct counter_count stm32_lptim_in1_counts = {
>  static int stm32_lptim_cnt_probe(struct platform_device *pdev)
>  {
>  	struct stm32_lptimer *ddata = dev_get_drvdata(pdev->dev.parent);
> +	struct counter_device *counter;
>  	struct stm32_lptim_cnt *priv;
> +	int ret;
>  
>  	if (IS_ERR_OR_NULL(ddata))
>  		return -EINVAL;
>  
> -	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(&pdev->dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	priv->dev = &pdev->dev;
>  	priv->regmap = ddata->regmap;
> @@ -426,23 +428,26 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev)
>  	priv->ceiling = STM32_LPTIM_MAX_ARR;
>  
>  	/* Initialize Counter device */
> -	priv->counter.name = dev_name(&pdev->dev);
> -	priv->counter.parent = &pdev->dev;
> -	priv->counter.ops = &stm32_lptim_cnt_ops;
> +	counter->name = dev_name(&pdev->dev);
> +	counter->parent = &pdev->dev;
> +	counter->ops = &stm32_lptim_cnt_ops;
>  	if (ddata->has_encoder) {
> -		priv->counter.counts = &stm32_lptim_enc_counts;
> -		priv->counter.num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
> +		counter->counts = &stm32_lptim_enc_counts;
> +		counter->num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
>  	} else {
> -		priv->counter.counts = &stm32_lptim_in1_counts;
> -		priv->counter.num_signals = 1;
> +		counter->counts = &stm32_lptim_in1_counts;
> +		counter->num_signals = 1;
>  	}
> -	priv->counter.num_counts = 1;
> -	priv->counter.signals = stm32_lptim_cnt_signals;
> -	priv->counter.priv = priv;
> +	counter->num_counts = 1;
> +	counter->signals = stm32_lptim_cnt_signals;
>  
>  	platform_set_drvdata(pdev, priv);
>  
> -	return devm_counter_register(&pdev->dev, &priv->counter);
> +	ret = devm_counter_add(&pdev->dev, counter);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
> +
> +	return 0;
>  }
>  
>  #ifdef CONFIG_PM_SLEEP


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

* Re: [PATCH v2 21/23] counter: stm32-lptimer-cnt: Convert to new counter registration
@ 2021-12-28 18:26     ` Jonathan Cameron
  0 siblings, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:26 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue,
	Benjamin Gaignard, linux-stm32, linux-arm-kernel

On Mon, 27 Dec 2021 10:45:24 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: 597f55e3f36c ("counter: stm32-lptimer: add counter device")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/stm32-lptimer-cnt.c | 33 +++++++++++++++++------------
>  1 file changed, 19 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
> index 9cf00e929cc0..68031d93ce89 100644
> --- a/drivers/counter/stm32-lptimer-cnt.c
> +++ b/drivers/counter/stm32-lptimer-cnt.c
> @@ -20,7 +20,6 @@
>  #include <linux/types.h>
>  
>  struct stm32_lptim_cnt {
> -	struct counter_device counter;
>  	struct device *dev;
>  	struct regmap *regmap;
>  	struct clk *clk;
> @@ -411,14 +410,17 @@ static struct counter_count stm32_lptim_in1_counts = {
>  static int stm32_lptim_cnt_probe(struct platform_device *pdev)
>  {
>  	struct stm32_lptimer *ddata = dev_get_drvdata(pdev->dev.parent);
> +	struct counter_device *counter;
>  	struct stm32_lptim_cnt *priv;
> +	int ret;
>  
>  	if (IS_ERR_OR_NULL(ddata))
>  		return -EINVAL;
>  
> -	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(&pdev->dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	priv->dev = &pdev->dev;
>  	priv->regmap = ddata->regmap;
> @@ -426,23 +428,26 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev)
>  	priv->ceiling = STM32_LPTIM_MAX_ARR;
>  
>  	/* Initialize Counter device */
> -	priv->counter.name = dev_name(&pdev->dev);
> -	priv->counter.parent = &pdev->dev;
> -	priv->counter.ops = &stm32_lptim_cnt_ops;
> +	counter->name = dev_name(&pdev->dev);
> +	counter->parent = &pdev->dev;
> +	counter->ops = &stm32_lptim_cnt_ops;
>  	if (ddata->has_encoder) {
> -		priv->counter.counts = &stm32_lptim_enc_counts;
> -		priv->counter.num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
> +		counter->counts = &stm32_lptim_enc_counts;
> +		counter->num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
>  	} else {
> -		priv->counter.counts = &stm32_lptim_in1_counts;
> -		priv->counter.num_signals = 1;
> +		counter->counts = &stm32_lptim_in1_counts;
> +		counter->num_signals = 1;
>  	}
> -	priv->counter.num_counts = 1;
> -	priv->counter.signals = stm32_lptim_cnt_signals;
> -	priv->counter.priv = priv;
> +	counter->num_counts = 1;
> +	counter->signals = stm32_lptim_cnt_signals;
>  
>  	platform_set_drvdata(pdev, priv);
>  
> -	return devm_counter_register(&pdev->dev, &priv->counter);
> +	ret = devm_counter_add(&pdev->dev, counter);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
> +
> +	return 0;
>  }
>  
>  #ifdef CONFIG_PM_SLEEP


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 22/23] counter: ti-eqep: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 22/23] counter: ti-eqep: " Uwe Kleine-König
@ 2021-12-28 18:29   ` Jonathan Cameron
  2021-12-29  8:41   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:29 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	David Lechner

On Mon, 27 Dec 2021 10:45:25 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: f213729f6796 ("counter: new TI eQEP driver")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
It's nice that all these drivers are so similar...

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/counter/ti-eqep.c | 29 +++++++++++++++--------------
>  1 file changed, 15 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
> index abeda966e7be..3b49b492d182 100644
> --- a/drivers/counter/ti-eqep.c
> +++ b/drivers/counter/ti-eqep.c
> @@ -368,13 +368,15 @@ static const struct regmap_config ti_eqep_regmap16_config = {
>  static int ti_eqep_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> +	struct counter_device *counter;
>  	struct ti_eqep_cnt *priv;
>  	void __iomem *base;
>  	int err;
>  
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	base = devm_platform_ioremap_resource(pdev, 0);
>  	if (IS_ERR(base))
> @@ -390,16 +392,15 @@ static int ti_eqep_probe(struct platform_device *pdev)
>  	if (IS_ERR(priv->regmap16))
>  		return PTR_ERR(priv->regmap16);
>  
> -	priv->counter.name = dev_name(dev);
> -	priv->counter.parent = dev;
> -	priv->counter.ops = &ti_eqep_counter_ops;
> -	priv->counter.counts = ti_eqep_counts;
> -	priv->counter.num_counts = ARRAY_SIZE(ti_eqep_counts);
> -	priv->counter.signals = ti_eqep_signals;
> -	priv->counter.num_signals = ARRAY_SIZE(ti_eqep_signals);
> -	priv->counter.priv = priv;
> +	counter->name = dev_name(dev);
> +	counter->parent = dev;
> +	counter->ops = &ti_eqep_counter_ops;
> +	counter->counts = ti_eqep_counts;
> +	counter->num_counts = ARRAY_SIZE(ti_eqep_counts);
> +	counter->signals = ti_eqep_signals;
> +	counter->num_signals = ARRAY_SIZE(ti_eqep_signals);
>  
> -	platform_set_drvdata(pdev, priv);
> +	platform_set_drvdata(pdev, counter);
>  
>  	/*
>  	 * Need to make sure power is turned on. On AM33xx, this comes from the
> @@ -409,7 +410,7 @@ static int ti_eqep_probe(struct platform_device *pdev)
>  	pm_runtime_enable(dev);
>  	pm_runtime_get_sync(dev);
>  
> -	err = counter_register(&priv->counter);
> +	err = counter_add(counter);
>  	if (err < 0) {
>  		pm_runtime_put_sync(dev);
>  		pm_runtime_disable(dev);
> @@ -421,10 +422,10 @@ static int ti_eqep_probe(struct platform_device *pdev)
>  
>  static int ti_eqep_remove(struct platform_device *pdev)
>  {
> -	struct ti_eqep_cnt *priv = platform_get_drvdata(pdev);
> +	struct counter_device *counter = platform_get_drvdata(pdev);
>  	struct device *dev = &pdev->dev;
>  
> -	counter_unregister(&priv->counter);
> +	counter_unregister(counter);
>  	pm_runtime_put_sync(dev);
>  	pm_runtime_disable(dev);
>  


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

* Re: [PATCH v2 23/23] counter: remove old and now unused registration API
  2021-12-27  9:45 ` [PATCH v2 23/23] counter: remove old and now unused registration API Uwe Kleine-König
@ 2021-12-28 18:31   ` Jonathan Cameron
  2021-12-29  8:43   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: Jonathan Cameron @ 2021-12-28 18:31 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel

On Mon, 27 Dec 2021 10:45:26 +0100
Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:

> Usage of counter_register() yields issues in device lifetime tracking. All
> drivers were converted to the new API, so the old one can go away.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
LGTM and nice patch set in general.  Just those few things in the
patch introducing the new interfaces that need tidying up as far as I am
concerned.

Thanks,

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/counter/counter-core.c | 97 ++--------------------------------
>  include/linux/counter.h        | 12 -----
>  2 files changed, 4 insertions(+), 105 deletions(-)
> 
> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> index 8261567b6272..3f7dc5718423 100644
> --- a/drivers/counter/counter-core.c
> +++ b/drivers/counter/counter-core.c
> @@ -38,8 +38,7 @@ static void counter_device_release(struct device *dev)
>  	counter_chrdev_remove(counter);
>  	ida_free(&counter_ida, dev->id);
>  
> -	if (!counter->legacy_device)
> -		kfree(container_of(counter, struct counter_device_allochelper, counter));
> +	kfree(container_of(counter, struct counter_device_allochelper, counter));
>  }
>  
>  static struct device_type counter_device_type = {
> @@ -62,76 +61,13 @@ static dev_t counter_devt;
>   */
>  void *counter_priv(const struct counter_device *const counter)
>  {
> -	if (counter->legacy_device) {
> -		return counter->priv;
> -	} else {
> -		struct counter_device_allochelper *ch =
> -			container_of(counter, struct counter_device_allochelper, counter);
> +	struct counter_device_allochelper *ch =
> +		container_of(counter, struct counter_device_allochelper, counter);
>  
> -		return &ch->privdata;
> -	}
> +	return &ch->privdata;
>  }
>  EXPORT_SYMBOL_GPL(counter_priv);
>  
> -/**
> - * counter_register - register Counter to the system
> - * @counter:	pointer to Counter to register
> - *
> - * This function registers a Counter to the system. A sysfs "counter" directory
> - * will be created and populated with sysfs attributes correlating with the
> - * Counter Signals, Synapses, and Counts respectively.
> - *
> - * RETURNS:
> - * 0 on success, negative error number on failure.
> - */
> -int counter_register(struct counter_device *const counter)
> -{
> -	struct device *const dev = &counter->dev;
> -	int id;
> -	int err;
> -
> -	counter->legacy_device = true;
> -
> -	/* Acquire unique ID */
> -	id = ida_alloc(&counter_ida, GFP_KERNEL);
> -	if (id < 0)
> -		return id;
> -
> -	mutex_init(&counter->ops_exist_lock);
> -
> -	/* Configure device structure for Counter */
> -	dev->id = id;
> -	dev->type = &counter_device_type;
> -	dev->bus = &counter_bus_type;
> -	dev->devt = MKDEV(MAJOR(counter_devt), id);
> -	if (counter->parent) {
> -		dev->parent = counter->parent;
> -		dev->of_node = counter->parent->of_node;
> -	}
> -	device_initialize(dev);
> -
> -	err = counter_sysfs_add(counter);
> -	if (err < 0)
> -		goto err_free_id;
> -
> -	err = counter_chrdev_add(counter);
> -	if (err < 0)
> -		goto err_free_id;
> -
> -	err = cdev_device_add(&counter->chrdev, dev);
> -	if (err < 0)
> -		goto err_remove_chrdev;
> -
> -	return 0;
> -
> -err_remove_chrdev:
> -	counter_chrdev_remove(counter);
> -err_free_id:
> -	put_device(dev);
> -	return err;
> -}
> -EXPORT_SYMBOL_GPL(counter_register);
> -
>  /**
>   * counter_alloc - allocate a counter_device
>   * @sizeof_priv: size of the driver private data
> @@ -255,31 +191,6 @@ static void devm_counter_release(void *counter)
>  	counter_unregister(counter);
>  }
>  
> -/**
> - * devm_counter_register - Resource-managed counter_register
> - * @dev:	device to allocate counter_device for
> - * @counter:	pointer to Counter to register
> - *
> - * Managed counter_register. The Counter registered with this function is
> - * automatically unregistered on driver detach. This function calls
> - * counter_register internally. Refer to that function for more information.
> - *
> - * RETURNS:
> - * 0 on success, negative error number on failure.
> - */
> -int devm_counter_register(struct device *dev,
> -			  struct counter_device *const counter)
> -{
> -	int err;
> -
> -	err = counter_register(counter);
> -	if (err < 0)
> -		return err;
> -
> -	return devm_add_action_or_reset(dev, devm_counter_release, counter);
> -}
> -EXPORT_SYMBOL_GPL(devm_counter_register);
> -
>  static void devm_counter_put(void *counter)
>  {
>  	counter_put(counter);
> diff --git a/include/linux/counter.h b/include/linux/counter.h
> index f1350a43cd48..9afa0f1e9cea 100644
> --- a/include/linux/counter.h
> +++ b/include/linux/counter.h
> @@ -314,8 +314,6 @@ struct counter_device {
>  	struct counter_comp *ext;
>  	size_t num_ext;
>  
> -	void *priv;
> -
>  	struct device dev;
>  	struct cdev chrdev;
>  	struct list_head events_list;
> @@ -327,25 +325,15 @@ struct counter_device {
>  	spinlock_t events_in_lock;
>  	struct mutex events_out_lock;
>  	struct mutex ops_exist_lock;
> -
> -	/*
> -	 * This can go away once all drivers are converted to
> -	 * counter_alloc()/counter_add().
> -	 */
> -	bool legacy_device;
>  };
>  
>  void *counter_priv(const struct counter_device *const counter);
>  
> -int counter_register(struct counter_device *const counter);
> -
>  struct counter_device *counter_alloc(size_t sizeof_priv);
>  void counter_put(struct counter_device *const counter);
>  int counter_add(struct counter_device *const counter);
>  
>  void counter_unregister(struct counter_device *const counter);
> -int devm_counter_register(struct device *dev,
> -			  struct counter_device *const counter);
>  struct counter_device *devm_counter_alloc(struct device *dev,
>  					  size_t sizeof_priv);
>  int devm_counter_add(struct device *dev,


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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
  2021-12-27  9:45 ` [PATCH v2 13/23] counter: Provide alternative counter registration functions Uwe Kleine-König
  2021-12-27 12:16   ` Lars-Peter Clausen
@ 2022-01-06 10:53 ` Dan Carpenter
  2021-12-28 18:00   ` Jonathan Cameron
  2021-12-29  8:13   ` William Breathitt Gray
  3 siblings, 0 replies; 125+ messages in thread
From: kernel test robot @ 2021-12-28 19:45 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 6153 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20211227094526.698714-14-u.kleine-koenig@pengutronix.de>
References: <20211227094526.698714-14-u.kleine-koenig@pengutronix.de>
TO: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
TO: William Breathitt Gray <vilhelm.gray@gmail.com>
CC: "Lars-Peter Clausen" <lars@metafoo.de>
CC: kernel(a)pengutronix.de
CC: Jonathan Cameron <Jonathan.Cameron@huawei.com>
CC: linux-iio(a)vger.kernel.org
CC: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
CC: linux-kernel(a)vger.kernel.org

Hi "Uwe,

I love your patch! Perhaps something to improve:

[auto build test WARNING on a7904a538933c525096ca2ccde1e60d0ee62c08e]

url:    https://github.com/0day-ci/linux/commits/Uwe-Kleine-K-nig/counter-cleanups-and-device-lifetime-fixes/20211227-174815
base:   a7904a538933c525096ca2ccde1e60d0ee62c08e
:::::: branch date: 34 hours ago
:::::: commit date: 34 hours ago
config: i386-randconfig-m021-20211227 (https://download.01.org/0day-ci/archive/20211229/202112290340.PMwi47LV-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/counter/counter-core.c:175 counter_alloc() error: uninitialized symbol 'id'.

vim +/id +175 drivers/counter/counter-core.c

aaec1a0f76ec25 William Breathitt Gray 2021-08-27  134  
250e0e3d91caea Uwe Kleine-König       2021-12-27  135  /**
250e0e3d91caea Uwe Kleine-König       2021-12-27  136   * counter_alloc - allocate a counter_device
250e0e3d91caea Uwe Kleine-König       2021-12-27  137   * @sizeof_priv: size of the driver private data
250e0e3d91caea Uwe Kleine-König       2021-12-27  138   *
250e0e3d91caea Uwe Kleine-König       2021-12-27  139   * This is part one of counter registration. The structure is allocated
250e0e3d91caea Uwe Kleine-König       2021-12-27  140   * dynamically to ensure the right lifetime for the embedded struct device.
250e0e3d91caea Uwe Kleine-König       2021-12-27  141   *
250e0e3d91caea Uwe Kleine-König       2021-12-27  142   * If this succeeds, call counter_put() to get rid of the counter_device again.
250e0e3d91caea Uwe Kleine-König       2021-12-27  143   */
250e0e3d91caea Uwe Kleine-König       2021-12-27  144  struct counter_device *counter_alloc(size_t sizeof_priv)
250e0e3d91caea Uwe Kleine-König       2021-12-27  145  {
250e0e3d91caea Uwe Kleine-König       2021-12-27  146  	struct counter_device_allochelper *ch;
250e0e3d91caea Uwe Kleine-König       2021-12-27  147  	struct counter_device *counter;
250e0e3d91caea Uwe Kleine-König       2021-12-27  148  	struct device *dev;
250e0e3d91caea Uwe Kleine-König       2021-12-27  149  	int id, err;
250e0e3d91caea Uwe Kleine-König       2021-12-27  150  
250e0e3d91caea Uwe Kleine-König       2021-12-27  151  	ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
250e0e3d91caea Uwe Kleine-König       2021-12-27  152  	if (!ch) {
250e0e3d91caea Uwe Kleine-König       2021-12-27  153  		err = -ENOMEM;
250e0e3d91caea Uwe Kleine-König       2021-12-27  154  		goto err_alloc_ch;
250e0e3d91caea Uwe Kleine-König       2021-12-27  155  	}
250e0e3d91caea Uwe Kleine-König       2021-12-27  156  
250e0e3d91caea Uwe Kleine-König       2021-12-27  157  	counter = &ch->counter;
250e0e3d91caea Uwe Kleine-König       2021-12-27  158  	dev = &counter->dev;
250e0e3d91caea Uwe Kleine-König       2021-12-27  159  
250e0e3d91caea Uwe Kleine-König       2021-12-27  160  	/* Acquire unique ID */
250e0e3d91caea Uwe Kleine-König       2021-12-27  161  	err = ida_alloc(&counter_ida, GFP_KERNEL);
250e0e3d91caea Uwe Kleine-König       2021-12-27  162  	if (err < 0) {
250e0e3d91caea Uwe Kleine-König       2021-12-27  163  		goto err_ida_alloc;
250e0e3d91caea Uwe Kleine-König       2021-12-27  164  	}
250e0e3d91caea Uwe Kleine-König       2021-12-27  165  	dev->id = err;
250e0e3d91caea Uwe Kleine-König       2021-12-27  166  
250e0e3d91caea Uwe Kleine-König       2021-12-27  167  	err = counter_chrdev_add(counter);
250e0e3d91caea Uwe Kleine-König       2021-12-27  168  	if (err < 0)
250e0e3d91caea Uwe Kleine-König       2021-12-27  169  		goto err_chrdev_add;
250e0e3d91caea Uwe Kleine-König       2021-12-27  170  
250e0e3d91caea Uwe Kleine-König       2021-12-27  171  	device_initialize(dev);
250e0e3d91caea Uwe Kleine-König       2021-12-27  172  	/* Configure device structure for Counter */
250e0e3d91caea Uwe Kleine-König       2021-12-27  173  	dev->type = &counter_device_type;
250e0e3d91caea Uwe Kleine-König       2021-12-27  174  	dev->bus = &counter_bus_type;
250e0e3d91caea Uwe Kleine-König       2021-12-27 @175  	dev->devt = MKDEV(MAJOR(counter_devt), id);
250e0e3d91caea Uwe Kleine-König       2021-12-27  176  
250e0e3d91caea Uwe Kleine-König       2021-12-27  177  	mutex_init(&counter->ops_exist_lock);
250e0e3d91caea Uwe Kleine-König       2021-12-27  178  
250e0e3d91caea Uwe Kleine-König       2021-12-27  179  	return counter;
250e0e3d91caea Uwe Kleine-König       2021-12-27  180  
250e0e3d91caea Uwe Kleine-König       2021-12-27  181  err_chrdev_add:
250e0e3d91caea Uwe Kleine-König       2021-12-27  182  
250e0e3d91caea Uwe Kleine-König       2021-12-27  183  	ida_free(&counter_ida, dev->id);
250e0e3d91caea Uwe Kleine-König       2021-12-27  184  err_ida_alloc:
250e0e3d91caea Uwe Kleine-König       2021-12-27  185  
250e0e3d91caea Uwe Kleine-König       2021-12-27  186  	kfree(ch);
250e0e3d91caea Uwe Kleine-König       2021-12-27  187  err_alloc_ch:
250e0e3d91caea Uwe Kleine-König       2021-12-27  188  
250e0e3d91caea Uwe Kleine-König       2021-12-27  189  	return ERR_PTR(err);
250e0e3d91caea Uwe Kleine-König       2021-12-27  190  }
250e0e3d91caea Uwe Kleine-König       2021-12-27  191  EXPORT_SYMBOL_GPL(counter_alloc);
250e0e3d91caea Uwe Kleine-König       2021-12-27  192  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

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

* Re: [PATCH v2 01/23] counter: Use container_of instead of drvdata to track counter_device
  2021-12-27  9:45 ` [PATCH v2 01/23] counter: Use container_of instead of drvdata to track counter_device Uwe Kleine-König
  2021-12-28 17:14   ` Jonathan Cameron
@ 2021-12-29  6:38   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  6:38 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1483 bytes --]

On Mon, Dec 27, 2021 at 10:45:04AM +0100, Uwe Kleine-König wrote:
> The counter core uses drvdata to find a struct counter_device from a
> struct device. However as the device is a member of struct counter_device,
> the lookup can be done faster (and a bit type safe) using container_of.
> 
> There are no other users of drvdata, so the call to dev_set_drvdata can
> go away, too.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/counter-core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> index 5acc54539623..f053a43c6c04 100644
> --- a/drivers/counter/counter-core.c
> +++ b/drivers/counter/counter-core.c
> @@ -26,7 +26,8 @@ static DEFINE_IDA(counter_ida);
>  
>  static void counter_device_release(struct device *dev)
>  {
> -	struct counter_device *const counter = dev_get_drvdata(dev);
> +	struct counter_device *const counter =
> +		container_of(dev, struct counter_device, dev);
>  
>  	counter_chrdev_remove(counter);
>  	ida_free(&counter_ida, dev->id);
> @@ -78,7 +79,6 @@ int counter_register(struct counter_device *const counter)
>  		dev->of_node = counter->parent->of_node;
>  	}
>  	device_initialize(dev);
> -	dev_set_drvdata(dev, counter);
>  
>  	err = counter_sysfs_add(counter);
>  	if (err < 0)
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 02/23] counter: ftm-quaddec: Drop unused platform_set_drvdata()
  2021-12-27  9:45 ` [PATCH v2 02/23] counter: ftm-quaddec: Drop unused platform_set_drvdata() Uwe Kleine-König
  2021-12-28 17:37   ` Jonathan Cameron
@ 2021-12-29  6:42   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  6:42 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Patrick Havelange,
	Syed Nayyar Waris

[-- Attachment #1: Type: text/plain, Size: 1071 bytes --]

On Mon, Dec 27, 2021 at 10:45:05AM +0100, Uwe Kleine-König wrote:
> The driver doesn't ever use platform_get_drvdata, so drop this unused
> call.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

By the way, it should be possible to remove pdev from struct ftm_quaddec
because &ftm->pdev->dev is stored to ftm->counter.parent and can be
accessed from there if needed.

> ---
>  drivers/counter/ftm-quaddec.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> index 5ef0478709cd..9272f7b58beb 100644
> --- a/drivers/counter/ftm-quaddec.c
> +++ b/drivers/counter/ftm-quaddec.c
> @@ -269,8 +269,6 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
>  	if (!ftm)
>  		return -ENOMEM;
>  
> -	platform_set_drvdata(pdev, ftm);
> -
>  	io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	if (!io) {
>  		dev_err(&pdev->dev, "Failed to get memory region\n");
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 03/23] counter: microchip-tcb-capture: Drop unused platform_set_drvdata()
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-29  6:44     ` William Breathitt Gray
  -1 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  6:44 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Kamel Bouhara,
	linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 922 bytes --]

On Mon, Dec 27, 2021 at 10:45:06AM +0100, Uwe Kleine-König wrote:
> The driver doesn't ever use platform_get_drvdata, so drop this unused
> call.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/microchip-tcb-capture.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index 0ab1b2716784..bb69f2e0ba93 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -307,8 +307,6 @@ static int mchp_tc_probe(struct platform_device *pdev)
>  	if (!priv)
>  		return -ENOMEM;
>  
> -	platform_set_drvdata(pdev, priv);
> -
>  	match = of_match_node(atmel_tc_of_match, np->parent);
>  	tcb_config = match->data;
>  	if (!tcb_config) {
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 03/23] counter: microchip-tcb-capture: Drop unused platform_set_drvdata()
@ 2021-12-29  6:44     ` William Breathitt Gray
  0 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  6:44 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Kamel Bouhara,
	linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 922 bytes --]

On Mon, Dec 27, 2021 at 10:45:06AM +0100, Uwe Kleine-König wrote:
> The driver doesn't ever use platform_get_drvdata, so drop this unused
> call.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/microchip-tcb-capture.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index 0ab1b2716784..bb69f2e0ba93 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -307,8 +307,6 @@ static int mchp_tc_probe(struct platform_device *pdev)
>  	if (!priv)
>  		return -ENOMEM;
>  
> -	platform_set_drvdata(pdev, priv);
> -
>  	match = of_match_node(atmel_tc_of_match, np->parent);
>  	tcb_config = match->data;
>  	if (!tcb_config) {
> -- 
> 2.33.0
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 04/23] counter: Provide a wrapper to access device private data
  2021-12-27  9:45 ` [PATCH v2 04/23] counter: Provide a wrapper to access device private data Uwe Kleine-König
  2021-12-27 11:02   ` Greg Kroah-Hartman
  2021-12-28 18:01   ` Jonathan Cameron
@ 2021-12-29  6:47   ` William Breathitt Gray
  2 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  6:47 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1848 bytes --]

On Mon, Dec 27, 2021 at 10:45:07AM +0100, Uwe Kleine-König wrote:
> For now this just wraps accessing struct counter_device::priv. However
> this is about to change and converting drivers to this helper
> individually makes fixing device lifetime issues result in easier to
> review patches.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/counter-core.c | 12 ++++++++++++
>  include/linux/counter.h        |  2 ++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> index f053a43c6c04..00c41f28c101 100644
> --- a/drivers/counter/counter-core.c
> +++ b/drivers/counter/counter-core.c
> @@ -45,6 +45,18 @@ static struct bus_type counter_bus_type = {
>  
>  static dev_t counter_devt;
>  
> +/**
> + * counter_priv - access counter device private data
> + * @counter: counter device
> + *
> + * Get the counter device private data
> + */
> +void *counter_priv(const struct counter_device *const counter)
> +{
> +	return counter->priv;
> +}
> +EXPORT_SYMBOL_GPL(counter_priv);
> +
>  /**
>   * counter_register - register Counter to the system
>   * @counter:	pointer to Counter to register
> diff --git a/include/linux/counter.h b/include/linux/counter.h
> index b7d0a00a61cf..8daaa38c71d8 100644
> --- a/include/linux/counter.h
> +++ b/include/linux/counter.h
> @@ -329,6 +329,8 @@ struct counter_device {
>  	struct mutex ops_exist_lock;
>  };
>  
> +void *counter_priv(const struct counter_device *const counter);
> +
>  int counter_register(struct counter_device *const counter);
>  void counter_unregister(struct counter_device *const counter);
>  int devm_counter_register(struct device *dev,
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 05/23] counter: 104-quad-8: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` [PATCH v2 05/23] counter: 104-quad-8: Convert to counter_priv() wrapper Uwe Kleine-König
  2021-12-28 18:02   ` Jonathan Cameron
@ 2021-12-29  7:27   ` William Breathitt Gray
  2021-12-29 11:15     ` Uwe Kleine-König
  1 sibling, 1 reply; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  7:27 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Syed Nayyar Waris

[-- Attachment #1: Type: text/plain, Size: 12368 bytes --]

On Mon, Dec 27, 2021 at 10:45:08AM +0100, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

This patch results in a minor merge conflict with commit c95cc0d95702
("counter: 104-quad-8: Fix persistent enabled events bug") in linux-next
due to context changes in quad8_events_configure() and
quad8_watch_validate(). Fixing this after a rebase is trivial so I'll
give my Ack here.

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/104-quad-8.c | 58 ++++++++++++++++++------------------
>  1 file changed, 29 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
> index 1cbd60aaed69..6e5286cd1d4e 100644
> --- a/drivers/counter/104-quad-8.c
> +++ b/drivers/counter/104-quad-8.c
> @@ -113,7 +113,7 @@ static int quad8_signal_read(struct counter_device *counter,
>  			     struct counter_signal *signal,
>  			     enum counter_signal_level *level)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	unsigned int state;
>  
>  	/* Only Index signal levels can be read */
> @@ -131,7 +131,7 @@ static int quad8_signal_read(struct counter_device *counter,
>  static int quad8_count_read(struct counter_device *counter,
>  			    struct counter_count *count, u64 *val)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int base_offset = priv->base + 2 * count->id;
>  	unsigned int flags;
>  	unsigned int borrow;
> @@ -163,7 +163,7 @@ static int quad8_count_read(struct counter_device *counter,
>  static int quad8_count_write(struct counter_device *counter,
>  			     struct counter_count *count, u64 val)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int base_offset = priv->base + 2 * count->id;
>  	unsigned long irqflags;
>  	int i;
> @@ -213,7 +213,7 @@ static int quad8_function_read(struct counter_device *counter,
>  			       struct counter_count *count,
>  			       enum counter_function *function)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int id = count->id;
>  	unsigned long irqflags;
>  
> @@ -243,7 +243,7 @@ static int quad8_function_write(struct counter_device *counter,
>  				struct counter_count *count,
>  				enum counter_function function)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int id = count->id;
>  	unsigned int *const quadrature_mode = priv->quadrature_mode + id;
>  	unsigned int *const scale = priv->quadrature_scale + id;
> @@ -305,7 +305,7 @@ static int quad8_direction_read(struct counter_device *counter,
>  				struct counter_count *count,
>  				enum counter_count_direction *direction)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	unsigned int ud_flag;
>  	const unsigned int flag_addr = priv->base + 2 * count->id + 1;
>  
> @@ -335,7 +335,7 @@ static int quad8_action_read(struct counter_device *counter,
>  			     struct counter_synapse *synapse,
>  			     enum counter_synapse_action *action)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	int err;
>  	enum counter_function function;
>  	const size_t signal_a_id = count->synapses[0].signal->id;
> @@ -399,7 +399,7 @@ enum {
>  
>  static int quad8_events_configure(struct counter_device *counter)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	unsigned long irq_enabled = 0;
>  	unsigned long irqflags;
>  	size_t channel;
> @@ -442,7 +442,7 @@ static int quad8_events_configure(struct counter_device *counter)
>  static int quad8_watch_validate(struct counter_device *counter,
>  				const struct counter_watch *watch)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  
>  	if (watch->channel > QUAD8_NUM_COUNTERS - 1)
>  		return -EINVAL;
> @@ -497,7 +497,7 @@ static int quad8_index_polarity_get(struct counter_device *counter,
>  				    struct counter_signal *signal,
>  				    u32 *index_polarity)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id - 16;
>  
>  	*index_polarity = priv->index_polarity[channel_id];
> @@ -509,7 +509,7 @@ static int quad8_index_polarity_set(struct counter_device *counter,
>  				    struct counter_signal *signal,
>  				    u32 index_polarity)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id - 16;
>  	const int base_offset = priv->base + 2 * channel_id + 1;
>  	unsigned long irqflags;
> @@ -538,7 +538,7 @@ static int quad8_synchronous_mode_get(struct counter_device *counter,
>  				      struct counter_signal *signal,
>  				      u32 *synchronous_mode)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id - 16;
>  
>  	*synchronous_mode = priv->synchronous_mode[channel_id];
> @@ -550,7 +550,7 @@ static int quad8_synchronous_mode_set(struct counter_device *counter,
>  				      struct counter_signal *signal,
>  				      u32 synchronous_mode)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id - 16;
>  	const int base_offset = priv->base + 2 * channel_id + 1;
>  	unsigned long irqflags;
> @@ -589,7 +589,7 @@ static int quad8_count_mode_read(struct counter_device *counter,
>  				 struct counter_count *count,
>  				 enum counter_count_mode *cnt_mode)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  
>  	/* Map 104-QUAD-8 count mode to Generic Counter count mode */
>  	switch (priv->count_mode[count->id]) {
> @@ -614,7 +614,7 @@ static int quad8_count_mode_write(struct counter_device *counter,
>  				  struct counter_count *count,
>  				  enum counter_count_mode cnt_mode)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	unsigned int count_mode;
>  	unsigned int mode_cfg;
>  	const int base_offset = priv->base + 2 * count->id + 1;
> @@ -661,7 +661,7 @@ static int quad8_count_mode_write(struct counter_device *counter,
>  static int quad8_count_enable_read(struct counter_device *counter,
>  				   struct counter_count *count, u8 *enable)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  
>  	*enable = priv->ab_enable[count->id];
>  
> @@ -671,7 +671,7 @@ static int quad8_count_enable_read(struct counter_device *counter,
>  static int quad8_count_enable_write(struct counter_device *counter,
>  				    struct counter_count *count, u8 enable)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int base_offset = priv->base + 2 * count->id;
>  	unsigned long irqflags;
>  	unsigned int ior_cfg;
> @@ -699,7 +699,7 @@ static const char *const quad8_noise_error_states[] = {
>  static int quad8_error_noise_get(struct counter_device *counter,
>  				 struct counter_count *count, u32 *noise_error)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	const int base_offset = priv->base + 2 * count->id + 1;
>  
>  	*noise_error = !!(inb(base_offset) & QUAD8_FLAG_E);
> @@ -710,7 +710,7 @@ static int quad8_error_noise_get(struct counter_device *counter,
>  static int quad8_count_preset_read(struct counter_device *counter,
>  				   struct counter_count *count, u64 *preset)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  
>  	*preset = priv->preset[count->id];
>  
> @@ -736,7 +736,7 @@ static void quad8_preset_register_set(struct quad8 *const priv, const int id,
>  static int quad8_count_preset_write(struct counter_device *counter,
>  				    struct counter_count *count, u64 preset)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	unsigned long irqflags;
>  
>  	/* Only 24-bit values are supported */
> @@ -755,7 +755,7 @@ static int quad8_count_preset_write(struct counter_device *counter,
>  static int quad8_count_ceiling_read(struct counter_device *counter,
>  				    struct counter_count *count, u64 *ceiling)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	unsigned long irqflags;
>  
>  	spin_lock_irqsave(&priv->lock, irqflags);
> @@ -780,7 +780,7 @@ static int quad8_count_ceiling_read(struct counter_device *counter,
>  static int quad8_count_ceiling_write(struct counter_device *counter,
>  				     struct counter_count *count, u64 ceiling)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	unsigned long irqflags;
>  
>  	/* Only 24-bit values are supported */
> @@ -807,7 +807,7 @@ static int quad8_count_preset_enable_read(struct counter_device *counter,
>  					  struct counter_count *count,
>  					  u8 *preset_enable)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  
>  	*preset_enable = !priv->preset_enable[count->id];
>  
> @@ -818,7 +818,7 @@ static int quad8_count_preset_enable_write(struct counter_device *counter,
>  					   struct counter_count *count,
>  					   u8 preset_enable)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const int base_offset = priv->base + 2 * count->id + 1;
>  	unsigned long irqflags;
>  	unsigned int ior_cfg;
> @@ -845,7 +845,7 @@ static int quad8_signal_cable_fault_read(struct counter_device *counter,
>  					 struct counter_signal *signal,
>  					 u8 *cable_fault)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id / 2;
>  	unsigned long irqflags;
>  	bool disabled;
> @@ -875,7 +875,7 @@ static int quad8_signal_cable_fault_enable_read(struct counter_device *counter,
>  						struct counter_signal *signal,
>  						u8 *enable)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id / 2;
>  
>  	*enable = !!(priv->cable_fault_enable & BIT(channel_id));
> @@ -887,7 +887,7 @@ static int quad8_signal_cable_fault_enable_write(struct counter_device *counter,
>  						 struct counter_signal *signal,
>  						 u8 enable)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id / 2;
>  	unsigned long irqflags;
>  	unsigned int cable_fault_enable;
> @@ -913,7 +913,7 @@ static int quad8_signal_fck_prescaler_read(struct counter_device *counter,
>  					   struct counter_signal *signal,
>  					   u8 *prescaler)
>  {
> -	const struct quad8 *const priv = counter->priv;
> +	const struct quad8 *const priv = counter_priv(counter);
>  
>  	*prescaler = priv->fck_prescaler[signal->id / 2];
>  
> @@ -924,7 +924,7 @@ static int quad8_signal_fck_prescaler_write(struct counter_device *counter,
>  					    struct counter_signal *signal,
>  					    u8 prescaler)
>  {
> -	struct quad8 *const priv = counter->priv;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const size_t channel_id = signal->id / 2;
>  	const int base_offset = priv->base + 2 * channel_id;
>  	unsigned long irqflags;
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 06/23] counter: interrupt-cnt: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` [PATCH v2 06/23] counter: interrupt-cnt: " Uwe Kleine-König
  2021-12-28 18:04   ` Jonathan Cameron
@ 2021-12-29  7:34   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  7:34 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Oleksij Rempel, Ahmad Fatoum

[-- Attachment #1: Type: text/plain, Size: 2520 bytes --]

On Mon, Dec 27, 2021 at 10:45:09AM +0100, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/interrupt-cnt.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c
> index 8514a87fcbee..4bf706ef46e2 100644
> --- a/drivers/counter/interrupt-cnt.c
> +++ b/drivers/counter/interrupt-cnt.c
> @@ -37,7 +37,7 @@ static irqreturn_t interrupt_cnt_isr(int irq, void *dev_id)
>  static int interrupt_cnt_enable_read(struct counter_device *counter,
>  				     struct counter_count *count, u8 *enable)
>  {
> -	struct interrupt_cnt_priv *priv = counter->priv;
> +	struct interrupt_cnt_priv *priv = counter_priv(counter);
>  
>  	*enable = priv->enabled;
>  
> @@ -47,7 +47,7 @@ static int interrupt_cnt_enable_read(struct counter_device *counter,
>  static int interrupt_cnt_enable_write(struct counter_device *counter,
>  				      struct counter_count *count, u8 enable)
>  {
> -	struct interrupt_cnt_priv *priv = counter->priv;
> +	struct interrupt_cnt_priv *priv = counter_priv(counter);
>  
>  	if (priv->enabled == enable)
>  		return 0;
> @@ -85,7 +85,7 @@ static int interrupt_cnt_action_read(struct counter_device *counter,
>  static int interrupt_cnt_read(struct counter_device *counter,
>  			      struct counter_count *count, u64 *val)
>  {
> -	struct interrupt_cnt_priv *priv = counter->priv;
> +	struct interrupt_cnt_priv *priv = counter_priv(counter);
>  
>  	*val = atomic_read(&priv->count);
>  
> @@ -95,7 +95,7 @@ static int interrupt_cnt_read(struct counter_device *counter,
>  static int interrupt_cnt_write(struct counter_device *counter,
>  			       struct counter_count *count, const u64 val)
>  {
> -	struct interrupt_cnt_priv *priv = counter->priv;
> +	struct interrupt_cnt_priv *priv = counter_priv(counter);
>  
>  	if (val != (typeof(priv->count.counter))val)
>  		return -ERANGE;
> @@ -122,7 +122,7 @@ static int interrupt_cnt_signal_read(struct counter_device *counter,
>  				     struct counter_signal *signal,
>  				     enum counter_signal_level *level)
>  {
> -	struct interrupt_cnt_priv *priv = counter->priv;
> +	struct interrupt_cnt_priv *priv = counter_priv(counter);
>  	int ret;
>  
>  	if (!priv->gpio)
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 07/23] counter: microchip-tcb-capture: Convert to counter_priv() wrapper
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-29  7:35     ` William Breathitt Gray
  -1 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  7:35 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Kamel Bouhara,
	linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 2991 bytes --]

On Mon, Dec 27, 2021 at 10:45:10AM +0100, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/microchip-tcb-capture.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index bb69f2e0ba93..1b56b7444668 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -72,7 +72,7 @@ static int mchp_tc_count_function_read(struct counter_device *counter,
>  				       struct counter_count *count,
>  				       enum counter_function *function)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  
>  	if (priv->qdec_mode)
>  		*function = COUNTER_FUNCTION_QUADRATURE_X4;
> @@ -86,7 +86,7 @@ static int mchp_tc_count_function_write(struct counter_device *counter,
>  					struct counter_count *count,
>  					enum counter_function function)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 bmr, cmr;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_BMR, &bmr);
> @@ -148,7 +148,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter,
>  				     struct counter_signal *signal,
>  				     enum counter_signal_level *lvl)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	bool sigstatus;
>  	u32 sr;
>  
> @@ -169,7 +169,7 @@ static int mchp_tc_count_action_read(struct counter_device *counter,
>  				     struct counter_synapse *synapse,
>  				     enum counter_synapse_action *action)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 cmr;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
> @@ -197,7 +197,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
>  				      struct counter_synapse *synapse,
>  				      enum counter_synapse_action action)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 edge = ATMEL_TC_ETRGEDG_NONE;
>  
>  	/* QDEC mode is rising edge only */
> @@ -230,7 +230,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
>  static int mchp_tc_count_read(struct counter_device *counter,
>  			      struct counter_count *count, u64 *val)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 cnt;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CV), &cnt);
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 07/23] counter: microchip-tcb-capture: Convert to counter_priv() wrapper
@ 2021-12-29  7:35     ` William Breathitt Gray
  0 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  7:35 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Kamel Bouhara,
	linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2991 bytes --]

On Mon, Dec 27, 2021 at 10:45:10AM +0100, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/microchip-tcb-capture.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index bb69f2e0ba93..1b56b7444668 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -72,7 +72,7 @@ static int mchp_tc_count_function_read(struct counter_device *counter,
>  				       struct counter_count *count,
>  				       enum counter_function *function)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  
>  	if (priv->qdec_mode)
>  		*function = COUNTER_FUNCTION_QUADRATURE_X4;
> @@ -86,7 +86,7 @@ static int mchp_tc_count_function_write(struct counter_device *counter,
>  					struct counter_count *count,
>  					enum counter_function function)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 bmr, cmr;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_BMR, &bmr);
> @@ -148,7 +148,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter,
>  				     struct counter_signal *signal,
>  				     enum counter_signal_level *lvl)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	bool sigstatus;
>  	u32 sr;
>  
> @@ -169,7 +169,7 @@ static int mchp_tc_count_action_read(struct counter_device *counter,
>  				     struct counter_synapse *synapse,
>  				     enum counter_synapse_action *action)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 cmr;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
> @@ -197,7 +197,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
>  				      struct counter_synapse *synapse,
>  				      enum counter_synapse_action action)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 edge = ATMEL_TC_ETRGEDG_NONE;
>  
>  	/* QDEC mode is rising edge only */
> @@ -230,7 +230,7 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
>  static int mchp_tc_count_read(struct counter_device *counter,
>  			      struct counter_count *count, u64 *val)
>  {
> -	struct mchp_tc_data *const priv = counter->priv;
> +	struct mchp_tc_data *const priv = counter_priv(counter);
>  	u32 cnt;
>  
>  	regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CV), &cnt);
> -- 
> 2.33.0
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 08/23] counter: intel-qep: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` [PATCH v2 08/23] counter: intel-qep: " Uwe Kleine-König
  2021-12-28 18:06   ` Jonathan Cameron
@ 2021-12-29  7:35   ` William Breathitt Gray
  2021-12-29 12:43   ` Jarkko Nikula
  2 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  7:35 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Jarkko Nikula,
	Felipe Balbi (Intel),
	Raymond Tan

[-- Attachment #1: Type: text/plain, Size: 3815 bytes --]

On Mon, Dec 27, 2021 at 10:45:11AM +0100, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/intel-qep.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c
> index 0924d16de6e2..8f84a48508ac 100644
> --- a/drivers/counter/intel-qep.c
> +++ b/drivers/counter/intel-qep.c
> @@ -109,7 +109,7 @@ static void intel_qep_init(struct intel_qep *qep)
>  static int intel_qep_count_read(struct counter_device *counter,
>  				struct counter_count *count, u64 *val)
>  {
> -	struct intel_qep *const qep = counter->priv;
> +	struct intel_qep *const qep = counter_priv(counter);
>  
>  	pm_runtime_get_sync(qep->dev);
>  	*val = intel_qep_readl(qep, INTEL_QEPCOUNT);
> @@ -176,7 +176,7 @@ static struct counter_synapse intel_qep_count_synapses[] = {
>  static int intel_qep_ceiling_read(struct counter_device *counter,
>  				  struct counter_count *count, u64 *ceiling)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  
>  	pm_runtime_get_sync(qep->dev);
>  	*ceiling = intel_qep_readl(qep, INTEL_QEPMAX);
> @@ -188,7 +188,7 @@ static int intel_qep_ceiling_read(struct counter_device *counter,
>  static int intel_qep_ceiling_write(struct counter_device *counter,
>  				   struct counter_count *count, u64 max)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	int ret = 0;
>  
>  	/* Intel QEP ceiling configuration only supports 32-bit values */
> @@ -213,7 +213,7 @@ static int intel_qep_ceiling_write(struct counter_device *counter,
>  static int intel_qep_enable_read(struct counter_device *counter,
>  				 struct counter_count *count, u8 *enable)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  
>  	*enable = qep->enabled;
>  
> @@ -223,7 +223,7 @@ static int intel_qep_enable_read(struct counter_device *counter,
>  static int intel_qep_enable_write(struct counter_device *counter,
>  				  struct counter_count *count, u8 val)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	u32 reg;
>  	bool changed;
>  
> @@ -256,7 +256,7 @@ static int intel_qep_spike_filter_ns_read(struct counter_device *counter,
>  					  struct counter_count *count,
>  					  u64 *length)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	u32 reg;
>  
>  	pm_runtime_get_sync(qep->dev);
> @@ -277,7 +277,7 @@ static int intel_qep_spike_filter_ns_write(struct counter_device *counter,
>  					   struct counter_count *count,
>  					   u64 length)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	u32 reg;
>  	bool enable;
>  	int ret = 0;
> @@ -326,7 +326,7 @@ static int intel_qep_preset_enable_read(struct counter_device *counter,
>  					struct counter_count *count,
>  					u8 *preset_enable)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	u32 reg;
>  
>  	pm_runtime_get_sync(qep->dev);
> @@ -341,7 +341,7 @@ static int intel_qep_preset_enable_read(struct counter_device *counter,
>  static int intel_qep_preset_enable_write(struct counter_device *counter,
>  					 struct counter_count *count, u8 val)
>  {
> -	struct intel_qep *qep = counter->priv;
> +	struct intel_qep *qep = counter_priv(counter);
>  	u32 reg;
>  	int ret = 0;
>  
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 09/23] counter: ftm-quaddec: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` [PATCH v2 09/23] counter: ftm-quaddec: " Uwe Kleine-König
  2021-12-28 18:07   ` Jonathan Cameron
@ 2021-12-29  7:36   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  7:36 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Patrick Havelange,
	Syed Nayyar Waris

[-- Attachment #1: Type: text/plain, Size: 2067 bytes --]

On Mon, Dec 27, 2021 at 10:45:12AM +0100, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/ftm-quaddec.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> index 9272f7b58beb..f5d92df6a611 100644
> --- a/drivers/counter/ftm-quaddec.c
> +++ b/drivers/counter/ftm-quaddec.c
> @@ -118,7 +118,7 @@ static void ftm_quaddec_disable(void *ftm)
>  static int ftm_quaddec_get_prescaler(struct counter_device *counter,
>  				     struct counter_count *count, u32 *cnt_mode)
>  {
> -	struct ftm_quaddec *ftm = counter->priv;
> +	struct ftm_quaddec *ftm = counter_priv(counter);
>  	uint32_t scflags;
>  
>  	ftm_read(ftm, FTM_SC, &scflags);
> @@ -131,7 +131,7 @@ static int ftm_quaddec_get_prescaler(struct counter_device *counter,
>  static int ftm_quaddec_set_prescaler(struct counter_device *counter,
>  				     struct counter_count *count, u32 cnt_mode)
>  {
> -	struct ftm_quaddec *ftm = counter->priv;
> +	struct ftm_quaddec *ftm = counter_priv(counter);
>  
>  	mutex_lock(&ftm->ftm_quaddec_mutex);
>  
> @@ -162,7 +162,7 @@ static int ftm_quaddec_count_read(struct counter_device *counter,
>  				  struct counter_count *count,
>  				  u64 *val)
>  {
> -	struct ftm_quaddec *const ftm = counter->priv;
> +	struct ftm_quaddec *const ftm = counter_priv(counter);
>  	uint32_t cntval;
>  
>  	ftm_read(ftm, FTM_CNT, &cntval);
> @@ -176,7 +176,7 @@ static int ftm_quaddec_count_write(struct counter_device *counter,
>  				   struct counter_count *count,
>  				   const u64 val)
>  {
> -	struct ftm_quaddec *const ftm = counter->priv;
> +	struct ftm_quaddec *const ftm = counter_priv(counter);
>  
>  	if (val != 0) {
>  		dev_warn(&ftm->pdev->dev, "Can only accept '0' as new counter value\n");
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 10/23] counter: ti-eqep: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` [PATCH v2 10/23] counter: ti-eqep: " Uwe Kleine-König
  2021-12-28 18:07   ` Jonathan Cameron
@ 2021-12-29  7:45   ` William Breathitt Gray
  2021-12-29 11:19     ` Uwe Kleine-König
  1 sibling, 1 reply; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  7:45 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, David Lechner

[-- Attachment #1: Type: text/plain, Size: 4102 bytes --]

On Mon, Dec 27, 2021 at 10:45:13AM +0100, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

This patch conflicts with commit 60f07e74f86b ("counter: ti-eqep: Use
container_of instead of struct counter_device::priv"). Because that
commit has a similar purpose as this patchset, I'm going to skip this
patch for now and continue looking over the rest of the patches in this
series.

> ---
>  drivers/counter/ti-eqep.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
> index 09817c953f9a..abeda966e7be 100644
> --- a/drivers/counter/ti-eqep.c
> +++ b/drivers/counter/ti-eqep.c
> @@ -90,7 +90,7 @@ struct ti_eqep_cnt {
>  static int ti_eqep_count_read(struct counter_device *counter,
>  			      struct counter_count *count, u64 *val)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	u32 cnt;
>  
>  	regmap_read(priv->regmap32, QPOSCNT, &cnt);
> @@ -102,7 +102,7 @@ static int ti_eqep_count_read(struct counter_device *counter,
>  static int ti_eqep_count_write(struct counter_device *counter,
>  			       struct counter_count *count, u64 val)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	u32 max;
>  
>  	regmap_read(priv->regmap32, QPOSMAX, &max);
> @@ -116,7 +116,7 @@ static int ti_eqep_function_read(struct counter_device *counter,
>  				 struct counter_count *count,
>  				 enum counter_function *function)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	u32 qdecctl;
>  
>  	regmap_read(priv->regmap16, QDECCTL, &qdecctl);
> @@ -143,7 +143,7 @@ static int ti_eqep_function_write(struct counter_device *counter,
>  				  struct counter_count *count,
>  				  enum counter_function function)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	enum ti_eqep_count_func qsrc;
>  
>  	switch (function) {
> @@ -173,7 +173,7 @@ static int ti_eqep_action_read(struct counter_device *counter,
>  			       struct counter_synapse *synapse,
>  			       enum counter_synapse_action *action)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	enum counter_function function;
>  	u32 qdecctl;
>  	int err;
> @@ -245,7 +245,7 @@ static int ti_eqep_position_ceiling_read(struct counter_device *counter,
>  					 struct counter_count *count,
>  					 u64 *ceiling)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	u32 qposmax;
>  
>  	regmap_read(priv->regmap32, QPOSMAX, &qposmax);
> @@ -259,7 +259,7 @@ static int ti_eqep_position_ceiling_write(struct counter_device *counter,
>  					  struct counter_count *count,
>  					  u64 ceiling)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  
>  	if (ceiling != (u32)ceiling)
>  		return -ERANGE;
> @@ -272,7 +272,7 @@ static int ti_eqep_position_ceiling_write(struct counter_device *counter,
>  static int ti_eqep_position_enable_read(struct counter_device *counter,
>  					struct counter_count *count, u8 *enable)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  	u32 qepctl;
>  
>  	regmap_read(priv->regmap16, QEPCTL, &qepctl);
> @@ -285,7 +285,7 @@ static int ti_eqep_position_enable_read(struct counter_device *counter,
>  static int ti_eqep_position_enable_write(struct counter_device *counter,
>  					 struct counter_count *count, u8 enable)
>  {
> -	struct ti_eqep_cnt *priv = counter->priv;
> +	struct ti_eqep_cnt *priv = counter_priv(counter);
>  
>  	regmap_write_bits(priv->regmap16, QEPCTL, QEPCTL_PHEN, enable ? -1 : 0);
>  
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 11/23] counter: stm32-lptimer-cnt: Convert to counter_priv() wrapper
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-29  7:48     ` William Breathitt Gray
  -1 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  7:48 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 3934 bytes --]

On Mon, Dec 27, 2021 at 10:45:14AM +0100, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/stm32-lptimer-cnt.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
> index 5168833b1fdf..9cf00e929cc0 100644
> --- a/drivers/counter/stm32-lptimer-cnt.c
> +++ b/drivers/counter/stm32-lptimer-cnt.c
> @@ -141,7 +141,7 @@ static const enum counter_synapse_action stm32_lptim_cnt_synapse_actions[] = {
>  static int stm32_lptim_cnt_read(struct counter_device *counter,
>  				struct counter_count *count, u64 *val)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	u32 cnt;
>  	int ret;
>  
> @@ -158,7 +158,7 @@ static int stm32_lptim_cnt_function_read(struct counter_device *counter,
>  					 struct counter_count *count,
>  					 enum counter_function *function)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (!priv->quadrature_mode) {
>  		*function = COUNTER_FUNCTION_INCREASE;
> @@ -177,7 +177,7 @@ static int stm32_lptim_cnt_function_write(struct counter_device *counter,
>  					  struct counter_count *count,
>  					  enum counter_function function)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (stm32_lptim_is_enabled(priv))
>  		return -EBUSY;
> @@ -200,7 +200,7 @@ static int stm32_lptim_cnt_enable_read(struct counter_device *counter,
>  				       struct counter_count *count,
>  				       u8 *enable)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	int ret;
>  
>  	ret = stm32_lptim_is_enabled(priv);
> @@ -216,7 +216,7 @@ static int stm32_lptim_cnt_enable_write(struct counter_device *counter,
>  					struct counter_count *count,
>  					u8 enable)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	int ret;
>  
>  	/* Check nobody uses the timer, or already disabled/enabled */
> @@ -241,7 +241,7 @@ static int stm32_lptim_cnt_ceiling_read(struct counter_device *counter,
>  					struct counter_count *count,
>  					u64 *ceiling)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	*ceiling = priv->ceiling;
>  
> @@ -252,7 +252,7 @@ static int stm32_lptim_cnt_ceiling_write(struct counter_device *counter,
>  					 struct counter_count *count,
>  					 u64 ceiling)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (stm32_lptim_is_enabled(priv))
>  		return -EBUSY;
> @@ -277,7 +277,7 @@ static int stm32_lptim_cnt_action_read(struct counter_device *counter,
>  				       struct counter_synapse *synapse,
>  				       enum counter_synapse_action *action)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	enum counter_function function;
>  	int err;
>  
> @@ -321,7 +321,7 @@ static int stm32_lptim_cnt_action_write(struct counter_device *counter,
>  					struct counter_synapse *synapse,
>  					enum counter_synapse_action action)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	enum counter_function function;
>  	int err;
>  
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 11/23] counter: stm32-lptimer-cnt: Convert to counter_priv() wrapper
@ 2021-12-29  7:48     ` William Breathitt Gray
  0 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  7:48 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 3934 bytes --]

On Mon, Dec 27, 2021 at 10:45:14AM +0100, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/stm32-lptimer-cnt.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
> index 5168833b1fdf..9cf00e929cc0 100644
> --- a/drivers/counter/stm32-lptimer-cnt.c
> +++ b/drivers/counter/stm32-lptimer-cnt.c
> @@ -141,7 +141,7 @@ static const enum counter_synapse_action stm32_lptim_cnt_synapse_actions[] = {
>  static int stm32_lptim_cnt_read(struct counter_device *counter,
>  				struct counter_count *count, u64 *val)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	u32 cnt;
>  	int ret;
>  
> @@ -158,7 +158,7 @@ static int stm32_lptim_cnt_function_read(struct counter_device *counter,
>  					 struct counter_count *count,
>  					 enum counter_function *function)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (!priv->quadrature_mode) {
>  		*function = COUNTER_FUNCTION_INCREASE;
> @@ -177,7 +177,7 @@ static int stm32_lptim_cnt_function_write(struct counter_device *counter,
>  					  struct counter_count *count,
>  					  enum counter_function function)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (stm32_lptim_is_enabled(priv))
>  		return -EBUSY;
> @@ -200,7 +200,7 @@ static int stm32_lptim_cnt_enable_read(struct counter_device *counter,
>  				       struct counter_count *count,
>  				       u8 *enable)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	int ret;
>  
>  	ret = stm32_lptim_is_enabled(priv);
> @@ -216,7 +216,7 @@ static int stm32_lptim_cnt_enable_write(struct counter_device *counter,
>  					struct counter_count *count,
>  					u8 enable)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	int ret;
>  
>  	/* Check nobody uses the timer, or already disabled/enabled */
> @@ -241,7 +241,7 @@ static int stm32_lptim_cnt_ceiling_read(struct counter_device *counter,
>  					struct counter_count *count,
>  					u64 *ceiling)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	*ceiling = priv->ceiling;
>  
> @@ -252,7 +252,7 @@ static int stm32_lptim_cnt_ceiling_write(struct counter_device *counter,
>  					 struct counter_count *count,
>  					 u64 ceiling)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  
>  	if (stm32_lptim_is_enabled(priv))
>  		return -EBUSY;
> @@ -277,7 +277,7 @@ static int stm32_lptim_cnt_action_read(struct counter_device *counter,
>  				       struct counter_synapse *synapse,
>  				       enum counter_synapse_action *action)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	enum counter_function function;
>  	int err;
>  
> @@ -321,7 +321,7 @@ static int stm32_lptim_cnt_action_write(struct counter_device *counter,
>  					struct counter_synapse *synapse,
>  					enum counter_synapse_action action)
>  {
> -	struct stm32_lptim_cnt *const priv = counter->priv;
> +	struct stm32_lptim_cnt *const priv = counter_priv(counter);
>  	enum counter_function function;
>  	int err;
>  
> -- 
> 2.33.0
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 12/23] counter: stm32-timer-cnt: Convert to counter_priv() wrapper
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-29  7:48     ` William Breathitt Gray
  -1 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  7:48 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 4167 bytes --]

On Mon, Dec 27, 2021 at 10:45:15AM +0100, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/stm32-timer-cnt.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
> index 0546e932db0c..4b05b198a8d8 100644
> --- a/drivers/counter/stm32-timer-cnt.c
> +++ b/drivers/counter/stm32-timer-cnt.c
> @@ -47,7 +47,7 @@ static const enum counter_function stm32_count_functions[] = {
>  static int stm32_count_read(struct counter_device *counter,
>  			    struct counter_count *count, u64 *val)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cnt;
>  
>  	regmap_read(priv->regmap, TIM_CNT, &cnt);
> @@ -59,7 +59,7 @@ static int stm32_count_read(struct counter_device *counter,
>  static int stm32_count_write(struct counter_device *counter,
>  			     struct counter_count *count, const u64 val)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 ceiling;
>  
>  	regmap_read(priv->regmap, TIM_ARR, &ceiling);
> @@ -73,7 +73,7 @@ static int stm32_count_function_read(struct counter_device *counter,
>  				     struct counter_count *count,
>  				     enum counter_function *function)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 smcr;
>  
>  	regmap_read(priv->regmap, TIM_SMCR, &smcr);
> @@ -100,7 +100,7 @@ static int stm32_count_function_write(struct counter_device *counter,
>  				      struct counter_count *count,
>  				      enum counter_function function)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1, sms;
>  
>  	switch (function) {
> @@ -140,7 +140,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
>  				      struct counter_count *count,
>  				      enum counter_count_direction *direction)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	regmap_read(priv->regmap, TIM_CR1, &cr1);
> @@ -153,7 +153,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
>  static int stm32_count_ceiling_read(struct counter_device *counter,
>  				    struct counter_count *count, u64 *ceiling)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 arr;
>  
>  	regmap_read(priv->regmap, TIM_ARR, &arr);
> @@ -166,7 +166,7 @@ static int stm32_count_ceiling_read(struct counter_device *counter,
>  static int stm32_count_ceiling_write(struct counter_device *counter,
>  				     struct counter_count *count, u64 ceiling)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  
>  	if (ceiling > priv->max_arr)
>  		return -ERANGE;
> @@ -181,7 +181,7 @@ static int stm32_count_ceiling_write(struct counter_device *counter,
>  static int stm32_count_enable_read(struct counter_device *counter,
>  				   struct counter_count *count, u8 *enable)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	regmap_read(priv->regmap, TIM_CR1, &cr1);
> @@ -194,7 +194,7 @@ static int stm32_count_enable_read(struct counter_device *counter,
>  static int stm32_count_enable_write(struct counter_device *counter,
>  				    struct counter_count *count, u8 enable)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	if (enable) {
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 12/23] counter: stm32-timer-cnt: Convert to counter_priv() wrapper
@ 2021-12-29  7:48     ` William Breathitt Gray
  0 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  7:48 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Benjamin Gaignard, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 4167 bytes --]

On Mon, Dec 27, 2021 at 10:45:15AM +0100, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/stm32-timer-cnt.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
> index 0546e932db0c..4b05b198a8d8 100644
> --- a/drivers/counter/stm32-timer-cnt.c
> +++ b/drivers/counter/stm32-timer-cnt.c
> @@ -47,7 +47,7 @@ static const enum counter_function stm32_count_functions[] = {
>  static int stm32_count_read(struct counter_device *counter,
>  			    struct counter_count *count, u64 *val)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cnt;
>  
>  	regmap_read(priv->regmap, TIM_CNT, &cnt);
> @@ -59,7 +59,7 @@ static int stm32_count_read(struct counter_device *counter,
>  static int stm32_count_write(struct counter_device *counter,
>  			     struct counter_count *count, const u64 val)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 ceiling;
>  
>  	regmap_read(priv->regmap, TIM_ARR, &ceiling);
> @@ -73,7 +73,7 @@ static int stm32_count_function_read(struct counter_device *counter,
>  				     struct counter_count *count,
>  				     enum counter_function *function)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 smcr;
>  
>  	regmap_read(priv->regmap, TIM_SMCR, &smcr);
> @@ -100,7 +100,7 @@ static int stm32_count_function_write(struct counter_device *counter,
>  				      struct counter_count *count,
>  				      enum counter_function function)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1, sms;
>  
>  	switch (function) {
> @@ -140,7 +140,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
>  				      struct counter_count *count,
>  				      enum counter_count_direction *direction)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	regmap_read(priv->regmap, TIM_CR1, &cr1);
> @@ -153,7 +153,7 @@ static int stm32_count_direction_read(struct counter_device *counter,
>  static int stm32_count_ceiling_read(struct counter_device *counter,
>  				    struct counter_count *count, u64 *ceiling)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 arr;
>  
>  	regmap_read(priv->regmap, TIM_ARR, &arr);
> @@ -166,7 +166,7 @@ static int stm32_count_ceiling_read(struct counter_device *counter,
>  static int stm32_count_ceiling_write(struct counter_device *counter,
>  				     struct counter_count *count, u64 ceiling)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  
>  	if (ceiling > priv->max_arr)
>  		return -ERANGE;
> @@ -181,7 +181,7 @@ static int stm32_count_ceiling_write(struct counter_device *counter,
>  static int stm32_count_enable_read(struct counter_device *counter,
>  				   struct counter_count *count, u8 *enable)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	regmap_read(priv->regmap, TIM_CR1, &cr1);
> @@ -194,7 +194,7 @@ static int stm32_count_enable_read(struct counter_device *counter,
>  static int stm32_count_enable_write(struct counter_device *counter,
>  				    struct counter_count *count, u8 enable)
>  {
> -	struct stm32_timer_cnt *const priv = counter->priv;
> +	struct stm32_timer_cnt *const priv = counter_priv(counter);
>  	u32 cr1;
>  
>  	if (enable) {
> -- 
> 2.33.0
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
  2021-12-27  9:45 ` [PATCH v2 13/23] counter: Provide alternative counter registration functions Uwe Kleine-König
                     ` (2 preceding siblings ...)
  2021-12-28 18:00   ` Jonathan Cameron
@ 2021-12-29  8:13   ` William Breathitt Gray
  3 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:13 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 8319 bytes --]

On Mon, Dec 27, 2021 at 10:45:16AM +0100, Uwe Kleine-König wrote:
> The current implementation gets device lifetime tracking wrong. The
> problem is that allocation of struct counter_device is controlled by the
> individual drivers but this structure contains a struct device that
> might have to live longer than a driver is bound. As a result a command
> sequence like:
> 
> 	{ sleep 5; echo bang; } > /dev/counter0 &
> 	sleep 1;
> 	echo 40000000.timer:counter > /sys/bus/platform/drivers/stm32-timer-counter/unbind
> 
> can keep a reference to the struct device and unbinding results in
> freeing the memory occupied by this device resulting in an oops.
> 
> This commit provides two new functions (plus some helpers):
>  - counter_alloc() to allocate a struct counter_device that is
>    automatically freed once the embedded struct device is released
>  - counter_add() to register such a device.
> 
> Note that this commit doesn't fix any issues, all drivers have to be
> converted to these new functions to correct the lifetime problems.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

I agree with the approach taken in this patch, and I don't have much to
add after the suggestions Lars-Peter and Jonathan have already given. So
assuming those are addressed in the next version I expect to Ack this
patch as well.

> ---
>  drivers/counter/counter-core.c | 149 ++++++++++++++++++++++++++++++++-
>  include/linux/counter.h        |  15 ++++
>  2 files changed, 163 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> index 00c41f28c101..8261567b6272 100644
> --- a/drivers/counter/counter-core.c
> +++ b/drivers/counter/counter-core.c
> @@ -15,6 +15,7 @@
>  #include <linux/kdev_t.h>
>  #include <linux/module.h>
>  #include <linux/mutex.h>
> +#include <linux/slab.h>
>  #include <linux/types.h>
>  #include <linux/wait.h>
>  
> @@ -24,6 +25,11 @@
>  /* Provides a unique ID for each counter device */
>  static DEFINE_IDA(counter_ida);
>  
> +struct counter_device_allochelper {
> +	struct counter_device counter;
> +	unsigned long privdata[];
> +};
> +
>  static void counter_device_release(struct device *dev)
>  {
>  	struct counter_device *const counter =
> @@ -31,6 +37,9 @@ static void counter_device_release(struct device *dev)
>  
>  	counter_chrdev_remove(counter);
>  	ida_free(&counter_ida, dev->id);
> +
> +	if (!counter->legacy_device)
> +		kfree(container_of(counter, struct counter_device_allochelper, counter));
>  }
>  
>  static struct device_type counter_device_type = {
> @@ -53,7 +62,14 @@ static dev_t counter_devt;
>   */
>  void *counter_priv(const struct counter_device *const counter)
>  {
> -	return counter->priv;
> +	if (counter->legacy_device) {
> +		return counter->priv;
> +	} else {
> +		struct counter_device_allochelper *ch =
> +			container_of(counter, struct counter_device_allochelper, counter);
> +
> +		return &ch->privdata;
> +	}
>  }
>  EXPORT_SYMBOL_GPL(counter_priv);
>  
> @@ -74,6 +90,8 @@ int counter_register(struct counter_device *const counter)
>  	int id;
>  	int err;
>  
> +	counter->legacy_device = true;
> +
>  	/* Acquire unique ID */
>  	id = ida_alloc(&counter_ida, GFP_KERNEL);
>  	if (id < 0)
> @@ -114,6 +132,100 @@ int counter_register(struct counter_device *const counter)
>  }
>  EXPORT_SYMBOL_GPL(counter_register);
>  
> +/**
> + * counter_alloc - allocate a counter_device
> + * @sizeof_priv: size of the driver private data
> + *
> + * This is part one of counter registration. The structure is allocated
> + * dynamically to ensure the right lifetime for the embedded struct device.
> + *
> + * If this succeeds, call counter_put() to get rid of the counter_device again.
> + */
> +struct counter_device *counter_alloc(size_t sizeof_priv)
> +{
> +	struct counter_device_allochelper *ch;
> +	struct counter_device *counter;
> +	struct device *dev;
> +	int id, err;
> +
> +	ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
> +	if (!ch) {
> +		err = -ENOMEM;
> +		goto err_alloc_ch;
> +	}
> +
> +	counter = &ch->counter;
> +	dev = &counter->dev;
> +
> +	/* Acquire unique ID */
> +	err = ida_alloc(&counter_ida, GFP_KERNEL);
> +	if (err < 0) {
> +		goto err_ida_alloc;
> +	}
> +	dev->id = err;
> +
> +	err = counter_chrdev_add(counter);
> +	if (err < 0)
> +		goto err_chrdev_add;
> +
> +	device_initialize(dev);
> +	/* Configure device structure for Counter */
> +	dev->type = &counter_device_type;
> +	dev->bus = &counter_bus_type;
> +	dev->devt = MKDEV(MAJOR(counter_devt), id);
> +
> +	mutex_init(&counter->ops_exist_lock);
> +
> +	return counter;
> +
> +err_chrdev_add:
> +
> +	ida_free(&counter_ida, dev->id);
> +err_ida_alloc:
> +
> +	kfree(ch);
> +err_alloc_ch:
> +
> +	return ERR_PTR(err);
> +}
> +EXPORT_SYMBOL_GPL(counter_alloc);
> +
> +void counter_put(struct counter_device *counter)
> +{
> +	put_device(&counter->dev);
> +}
> +
> +/**
> + * counter_add - complete registration of a counter
> + * @counter: the counter to add
> + *
> + * This is part two of counter registration.
> + *
> + * If this succeeds, call counter_unregister() to get rid of the counter_device again.
> + */
> +int counter_add(struct counter_device *counter)
> +{
> +	int err;
> +	struct device *dev = &counter->dev;
> +
> +	get_device(&counter->dev);
> +
> +	if (counter->parent) {
> +		dev->parent = counter->parent;
> +		dev->of_node = counter->parent->of_node;
> +	}
> +
> +	err = counter_sysfs_add(counter);
> +	if (err < 0)
> +		return err;
> +
> +	/* implies device_add(dev) */
> +	err = cdev_device_add(&counter->chrdev, dev);
> +
> +	return err;
> +}
> +EXPORT_SYMBOL_GPL(counter_add);
> +
>  /**
>   * counter_unregister - unregister Counter from the system
>   * @counter:	pointer to Counter to unregister
> @@ -168,6 +280,41 @@ int devm_counter_register(struct device *dev,
>  }
>  EXPORT_SYMBOL_GPL(devm_counter_register);
>  
> +static void devm_counter_put(void *counter)
> +{
> +	counter_put(counter);
> +}
> +
> +struct counter_device *devm_counter_alloc(struct device *dev, size_t sizeof_priv)
> +{
> +	struct counter_device *counter;
> +	int err;
> +
> +	counter = counter_alloc(sizeof_priv);
> +	if (IS_ERR(counter))
> +		return counter;
> +
> +	err = devm_add_action_or_reset(dev, devm_counter_put, counter);
> +	if (err < 0)
> +		return ERR_PTR(err);
> +
> +	return counter;
> +}
> +EXPORT_SYMBOL_GPL(devm_counter_alloc);
> +
> +int devm_counter_add(struct device *dev,
> +		     struct counter_device *const counter)
> +{
> +	int err;
> +
> +	err = counter_add(counter);
> +	if (err < 0)
> +		return err;
> +
> +	return devm_add_action_or_reset(dev, devm_counter_release, counter);
> +}
> +EXPORT_SYMBOL_GPL(devm_counter_add);
> +
>  #define COUNTER_DEV_MAX 256
>  
>  static int __init counter_init(void)
> diff --git a/include/linux/counter.h b/include/linux/counter.h
> index 8daaa38c71d8..f1350a43cd48 100644
> --- a/include/linux/counter.h
> +++ b/include/linux/counter.h
> @@ -327,14 +327,29 @@ struct counter_device {
>  	spinlock_t events_in_lock;
>  	struct mutex events_out_lock;
>  	struct mutex ops_exist_lock;
> +
> +	/*
> +	 * This can go away once all drivers are converted to
> +	 * counter_alloc()/counter_add().
> +	 */
> +	bool legacy_device;
>  };
>  
>  void *counter_priv(const struct counter_device *const counter);
>  
>  int counter_register(struct counter_device *const counter);
> +
> +struct counter_device *counter_alloc(size_t sizeof_priv);
> +void counter_put(struct counter_device *const counter);
> +int counter_add(struct counter_device *const counter);
> +
>  void counter_unregister(struct counter_device *const counter);
>  int devm_counter_register(struct device *dev,
>  			  struct counter_device *const counter);
> +struct counter_device *devm_counter_alloc(struct device *dev,
> +					  size_t sizeof_priv);
> +int devm_counter_add(struct device *dev,
> +		     struct counter_device *const counter);
>  void counter_push_event(struct counter_device *const counter, const u8 event,
>  			const u8 channel);
>  
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 14/23] counter: Update documentation for new counter registration functions
  2021-12-28 18:12   ` Jonathan Cameron
@ 2021-12-29  8:19     ` William Breathitt Gray
  0 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Uwe Kleine-König, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Jonathan Corbet, linux-doc

[-- Attachment #1: Type: text/plain, Size: 2201 bytes --]

On Tue, Dec 28, 2021 at 06:12:22PM +0000, Jonathan Cameron wrote:
> On Mon, 27 Dec 2021 10:45:17 +0100
> Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:
> 
> > In order to replace the counter registration API also update the
> > documentation to the new way.
> > 
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Fine either way, but a suggestion below.
> 
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> > ---
> >  Documentation/driver-api/generic-counter.rst | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/Documentation/driver-api/generic-counter.rst b/Documentation/driver-api/generic-counter.rst
> > index 1b487a331467..991b180c7b47 100644
> > --- a/Documentation/driver-api/generic-counter.rst
> > +++ b/Documentation/driver-api/generic-counter.rst
> > @@ -262,11 +262,11 @@ order to communicate with the device: to read and write various Signals
> >  and Counts, and to set and get the "action mode" and "function mode" for
> >  various Synapses and Counts respectively.
> >  
> > -A defined counter_device structure may be registered to the system by
> > -passing it to the counter_register function, and unregistered by passing
> > -it to the counter_unregister function. Similarly, the
> > -devm_counter_register function may be used if device memory-managed
> > -registration is desired.
> > +A counter_device structure is supposed to be allocated using counter_alloc()
> > +and may be registered to the system by passing it to the counter_add()
> > +function, and unregistered by passing it to the counter_unregister function.
> 
> I'd avoid the supposed to and the odd vague use of structure in the origin
> text and just go with
> 
> A struct counter_device is allocated using counter_alloc()...

I like this simpler wording as well.

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> 
> 
> > +There are device managed variants of these functions: devm_counter_alloc() and
> > +devm_counter_add().
> >  
> >  The struct counter_comp structure is used to define counter extensions
> >  for Signals, Synapses, and Counts.
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 15/23] counter: 104-quad-8: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 15/23] counter: 104-quad-8: Convert to new counter registration Uwe Kleine-König
  2021-12-27 12:19   ` Lars-Peter Clausen
  2021-12-28 18:17   ` Jonathan Cameron
@ 2021-12-29  8:24   ` William Breathitt Gray
  2 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:24 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Syed Nayyar Waris

[-- Attachment #1: Type: text/plain, Size: 3016 bytes --]

On Mon, Dec 27, 2021 at 10:45:18AM +0100, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: f1d8a071d45b ("counter: 104-quad-8: Add Generic Counter interface support")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/104-quad-8.c | 30 +++++++++++++++++-------------
>  1 file changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
> index 6e5286cd1d4e..4315b14f239e 100644
> --- a/drivers/counter/104-quad-8.c
> +++ b/drivers/counter/104-quad-8.c
> @@ -52,7 +52,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-QUAD-8 interrupt line numbers");
>   */
>  struct quad8 {
>  	spinlock_t lock;
> -	struct counter_device counter;
>  	unsigned int fck_prescaler[QUAD8_NUM_COUNTERS];
>  	unsigned int preset[QUAD8_NUM_COUNTERS];
>  	unsigned int count_mode[QUAD8_NUM_COUNTERS];
> @@ -1127,6 +1126,7 @@ static irqreturn_t quad8_irq_handler(int irq, void *private)
>  
>  static int quad8_probe(struct device *dev, unsigned int id)
>  {
> +	struct counter_device *counter;
>  	struct quad8 *priv;
>  	int i, j;
>  	unsigned int base_offset;
> @@ -1138,19 +1138,19 @@ static int quad8_probe(struct device *dev, unsigned int id)
>  		return -EBUSY;
>  	}
>  
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	/* Initialize Counter device and driver data */
> -	priv->counter.name = dev_name(dev);
> -	priv->counter.parent = dev;
> -	priv->counter.ops = &quad8_ops;
> -	priv->counter.counts = quad8_counts;
> -	priv->counter.num_counts = ARRAY_SIZE(quad8_counts);
> -	priv->counter.signals = quad8_signals;
> -	priv->counter.num_signals = ARRAY_SIZE(quad8_signals);
> -	priv->counter.priv = priv;
> +	counter->name = dev_name(dev);
> +	counter->parent = dev;
> +	counter->ops = &quad8_ops;
> +	counter->counts = quad8_counts;
> +	counter->num_counts = ARRAY_SIZE(quad8_counts);
> +	counter->signals = quad8_signals;
> +	counter->num_signals = ARRAY_SIZE(quad8_signals);
>  	priv->base = base[id];
>  
>  	spin_lock_init(&priv->lock);
> @@ -1192,11 +1192,15 @@ static int quad8_probe(struct device *dev, unsigned int id)
>  	outb(QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC, base[id] + QUAD8_REG_CHAN_OP);
>  
>  	err = devm_request_irq(dev, irq[id], quad8_irq_handler, IRQF_SHARED,
> -			       priv->counter.name, priv);
> +			       counter->name, priv);
>  	if (err)
>  		return err;
>  
> -	return devm_counter_register(dev, &priv->counter);
> +	err = devm_counter_add(dev, counter);
> +	if (err < 0)
> +		return dev_err_probe(dev, err, "Failed to add counter\n");
> +
> +	return 0;
>  }
>  
>  static struct isa_driver quad8_driver = {
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 16/23] counter: interrupt-cnt: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 16/23] counter: interrupt-cnt: " Uwe Kleine-König
  2021-12-27 10:59   ` Greg Kroah-Hartman
  2021-12-28 18:18   ` Jonathan Cameron
@ 2021-12-29  8:27   ` William Breathitt Gray
  2 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:27 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Ahmad Fatoum, Oleksij Rempel

[-- Attachment #1: Type: text/plain, Size: 3026 bytes --]

On Mon, Dec 27, 2021 at 10:45:19AM +0100, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: a55ebd47f21f ("counter: add IRQ or GPIO based counter")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/interrupt-cnt.c | 28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c
> index 4bf706ef46e2..9e99702470c2 100644
> --- a/drivers/counter/interrupt-cnt.c
> +++ b/drivers/counter/interrupt-cnt.c
> @@ -16,7 +16,6 @@
>  
>  struct interrupt_cnt_priv {
>  	atomic_t count;
> -	struct counter_device counter;
>  	struct gpio_desc *gpio;
>  	int irq;
>  	bool enabled;
> @@ -148,12 +147,14 @@ static const struct counter_ops interrupt_cnt_ops = {
>  static int interrupt_cnt_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> +	struct counter_device *counter;
>  	struct interrupt_cnt_priv *priv;
>  	int ret;
>  
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	priv->irq = platform_get_irq_optional(pdev,  0);
>  	if (priv->irq == -ENXIO)
> @@ -184,8 +185,8 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
>  	if (!priv->signals.name)
>  		return -ENOMEM;
>  
> -	priv->counter.signals = &priv->signals;
> -	priv->counter.num_signals = 1;
> +	counter->signals = &priv->signals;
> +	counter->num_signals = 1;
>  
>  	priv->synapses.actions_list = interrupt_cnt_synapse_actions;
>  	priv->synapses.num_actions = ARRAY_SIZE(interrupt_cnt_synapse_actions);
> @@ -199,12 +200,11 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
>  	priv->cnts.ext = interrupt_cnt_ext;
>  	priv->cnts.num_ext = ARRAY_SIZE(interrupt_cnt_ext);
>  
> -	priv->counter.priv = priv;
> -	priv->counter.name = dev_name(dev);
> -	priv->counter.parent = dev;
> -	priv->counter.ops = &interrupt_cnt_ops;
> -	priv->counter.counts = &priv->cnts;
> -	priv->counter.num_counts = 1;
> +	counter->name = dev_name(dev);
> +	counter->parent = dev;
> +	counter->ops = &interrupt_cnt_ops;
> +	counter->counts = &priv->cnts;
> +	counter->num_counts = 1;
>  
>  	irq_set_status_flags(priv->irq, IRQ_NOAUTOEN);
>  	ret = devm_request_irq(dev, priv->irq, interrupt_cnt_isr,
> @@ -213,7 +213,11 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	return devm_counter_register(dev, &priv->counter);
> +	ret = devm_counter_add(dev, counter);
> +	if (ret < 0)
> +		return dev_err_probe(dev, ret, "Failed to add counter\n");
> +
> +	return 0;
>  }
>  
>  static const struct of_device_id interrupt_cnt_of_match[] = {
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 17/23] counter: intel-qep: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 17/23] counter: intel-qep: " Uwe Kleine-König
  2021-12-27 15:02   ` Jarkko Nikula
  2021-12-28 18:20   ` Jonathan Cameron
@ 2021-12-29  8:29   ` William Breathitt Gray
  2 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:29 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Jarkko Nikula,
	Felipe Balbi (Intel),
	Raymond Tan

[-- Attachment #1: Type: text/plain, Size: 2750 bytes --]

On Mon, Dec 27, 2021 at 10:45:20AM +0100, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: b711f687a1c1 ("counter: Add support for Intel Quadrature Encoder Peripheral")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/intel-qep.c | 28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c
> index 8f84a48508ac..47a6a9dfc9e8 100644
> --- a/drivers/counter/intel-qep.c
> +++ b/drivers/counter/intel-qep.c
> @@ -63,7 +63,6 @@
>  #define INTEL_QEP_CLK_PERIOD_NS		10
>  
>  struct intel_qep {
> -	struct counter_device counter;
>  	struct mutex lock;
>  	struct device *dev;
>  	void __iomem *regs;
> @@ -392,14 +391,16 @@ static struct counter_count intel_qep_counter_count[] = {
>  
>  static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id)
>  {
> +	struct counter_device *counter;
>  	struct intel_qep *qep;
>  	struct device *dev = &pci->dev;
>  	void __iomem *regs;
>  	int ret;
>  
> -	qep = devm_kzalloc(dev, sizeof(*qep), GFP_KERNEL);
> -	if (!qep)
> +	counter = devm_counter_alloc(dev, sizeof(*qep));
> +	if (!counter)
>  		return -ENOMEM;
> +	qep = counter_priv(counter);
>  
>  	ret = pcim_enable_device(pci);
>  	if (ret)
> @@ -422,20 +423,23 @@ static int intel_qep_probe(struct pci_dev *pci, const struct pci_device_id *id)
>  	intel_qep_init(qep);
>  	pci_set_drvdata(pci, qep);
>  
> -	qep->counter.name = pci_name(pci);
> -	qep->counter.parent = dev;
> -	qep->counter.ops = &intel_qep_counter_ops;
> -	qep->counter.counts = intel_qep_counter_count;
> -	qep->counter.num_counts = ARRAY_SIZE(intel_qep_counter_count);
> -	qep->counter.signals = intel_qep_signals;
> -	qep->counter.num_signals = ARRAY_SIZE(intel_qep_signals);
> -	qep->counter.priv = qep;
> +	counter->name = pci_name(pci);
> +	counter->parent = dev;
> +	counter->ops = &intel_qep_counter_ops;
> +	counter->counts = intel_qep_counter_count;
> +	counter->num_counts = ARRAY_SIZE(intel_qep_counter_count);
> +	counter->signals = intel_qep_signals;
> +	counter->num_signals = ARRAY_SIZE(intel_qep_signals);
>  	qep->enabled = false;
>  
>  	pm_runtime_put(dev);
>  	pm_runtime_allow(dev);
>  
> -	return devm_counter_register(&pci->dev, &qep->counter);
> +	ret = devm_counter_add(&pci->dev, counter);
> +	if (ret < 0)
> +		return dev_err_probe(&pci->dev, ret, "Failed to add counter\n");
> +
> +	return 0;
>  }
>  
>  static void intel_qep_remove(struct pci_dev *pci)
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 18/23] counter: ftm-quaddec: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 18/23] counter: ftm-quaddec: " Uwe Kleine-König
  2021-12-28 18:23   ` Jonathan Cameron
@ 2021-12-29  8:33   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:33 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Syed Nayyar Waris,
	Patrick Havelange

[-- Attachment #1: Type: text/plain, Size: 4048 bytes --]

On Mon, Dec 27, 2021 at 10:45:21AM +0100, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: a3b9a99980d9 ("counter: add FlexTimer Module Quadrature decoder counter driver")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/104-quad-8.c  |  7 ++++---
>  drivers/counter/ftm-quaddec.c | 27 +++++++++++++--------------
>  2 files changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
> index 4315b14f239e..680c7ba943a4 100644
> --- a/drivers/counter/104-quad-8.c
> +++ b/drivers/counter/104-quad-8.c
> @@ -1084,7 +1084,8 @@ static struct counter_count quad8_counts[] = {
>  
>  static irqreturn_t quad8_irq_handler(int irq, void *private)
>  {
> -	struct quad8 *const priv = private;
> +	struct counter_device *counter = private;
> +	struct quad8 *const priv = counter_priv(counter);
>  	const unsigned long base = priv->base;
>  	unsigned long irq_status;
>  	unsigned long channel;
> @@ -1115,7 +1116,7 @@ static irqreturn_t quad8_irq_handler(int irq, void *private)
>  			continue;
>  		}
>  
> -		counter_push_event(&priv->counter, event, channel);
> +		counter_push_event(counter, event, channel);
>  	}
>  
>  	/* Clear pending interrupts on device */
> @@ -1192,7 +1193,7 @@ static int quad8_probe(struct device *dev, unsigned int id)
>  	outb(QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC, base[id] + QUAD8_REG_CHAN_OP);
>  
>  	err = devm_request_irq(dev, irq[id], quad8_irq_handler, IRQF_SHARED,
> -			       counter->name, priv);
> +			       counter->name, counter);
>  	if (err)
>  		return err;
>  
> diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
> index f5d92df6a611..c636183b1337 100644
> --- a/drivers/counter/ftm-quaddec.c
> +++ b/drivers/counter/ftm-quaddec.c
> @@ -26,7 +26,6 @@
>  	})
>  
>  struct ftm_quaddec {
> -	struct counter_device counter;
>  	struct platform_device *pdev;
>  	void __iomem *ftm_base;
>  	bool big_endian;
> @@ -259,15 +258,16 @@ static struct counter_count ftm_quaddec_counts = {
>  
>  static int ftm_quaddec_probe(struct platform_device *pdev)
>  {
> +	struct counter_device *counter;
>  	struct ftm_quaddec *ftm;
> -
>  	struct device_node *node = pdev->dev.of_node;
>  	struct resource *io;
>  	int ret;
>  
> -	ftm = devm_kzalloc(&pdev->dev, sizeof(*ftm), GFP_KERNEL);
> -	if (!ftm)
> +	counter = devm_counter_alloc(&pdev->dev, sizeof(*ftm));
> +	if (!counter)
>  		return -ENOMEM;
> +	ftm = counter_priv(counter);
>  
>  	io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	if (!io) {
> @@ -283,14 +283,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
>  		dev_err(&pdev->dev, "Failed to map memory region\n");
>  		return -EINVAL;
>  	}
> -	ftm->counter.name = dev_name(&pdev->dev);
> -	ftm->counter.parent = &pdev->dev;
> -	ftm->counter.ops = &ftm_quaddec_cnt_ops;
> -	ftm->counter.counts = &ftm_quaddec_counts;
> -	ftm->counter.num_counts = 1;
> -	ftm->counter.signals = ftm_quaddec_signals;
> -	ftm->counter.num_signals = ARRAY_SIZE(ftm_quaddec_signals);
> -	ftm->counter.priv = ftm;
> +	counter->name = dev_name(&pdev->dev);
> +	counter->parent = &pdev->dev;
> +	counter->ops = &ftm_quaddec_cnt_ops;
> +	counter->counts = &ftm_quaddec_counts;
> +	counter->num_counts = 1;
> +	counter->signals = ftm_quaddec_signals;
> +	counter->num_signals = ARRAY_SIZE(ftm_quaddec_signals);
>  
>  	mutex_init(&ftm->ftm_quaddec_mutex);
>  
> @@ -300,9 +299,9 @@ static int ftm_quaddec_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	ret = devm_counter_register(&pdev->dev, &ftm->counter);
> +	ret = devm_counter_add(&pdev->dev, counter);
>  	if (ret)
> -		return ret;
> +		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
>  
>  	return 0;
>  }
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 19/23] counter: microchip-tcb-capture: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 19/23] counter: microchip-tcb-capture: " Uwe Kleine-König
  2021-12-28 18:24   ` Jonathan Cameron
@ 2021-12-29  8:36   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:36 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Kamel Bouhara

[-- Attachment #1: Type: text/plain, Size: 2883 bytes --]

On Mon, Dec 27, 2021 at 10:45:22AM +0100, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: 106b104137fd ("counter: Add microchip TCB capture counter")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/microchip-tcb-capture.c | 30 ++++++++++++++-----------
>  1 file changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index 1b56b7444668..70c1d28546be 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -24,7 +24,6 @@
>  
>  struct mchp_tc_data {
>  	const struct atmel_tcb_config *tc_cfg;
> -	struct counter_device counter;
>  	struct regmap *regmap;
>  	int qdec_mode;
>  	int num_channels;
> @@ -296,6 +295,7 @@ static int mchp_tc_probe(struct platform_device *pdev)
>  	struct device_node *np = pdev->dev.of_node;
>  	const struct atmel_tcb_config *tcb_config;
>  	const struct of_device_id *match;
> +	struct counter_device *counter;
>  	struct mchp_tc_data *priv;
>  	char clk_name[7];
>  	struct regmap *regmap;
> @@ -303,9 +303,10 @@ static int mchp_tc_probe(struct platform_device *pdev)
>  	int channel;
>  	int ret, i;
>  
> -	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(&pdev->dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	match = of_match_node(atmel_tc_of_match, np->parent);
>  	tcb_config = match->data;
> @@ -360,16 +361,19 @@ static int mchp_tc_probe(struct platform_device *pdev)
>  
>  	priv->tc_cfg = tcb_config;
>  	priv->regmap = regmap;
> -	priv->counter.name = dev_name(&pdev->dev);
> -	priv->counter.parent = &pdev->dev;
> -	priv->counter.ops = &mchp_tc_ops;
> -	priv->counter.num_counts = ARRAY_SIZE(mchp_tc_counts);
> -	priv->counter.counts = mchp_tc_counts;
> -	priv->counter.num_signals = ARRAY_SIZE(mchp_tc_count_signals);
> -	priv->counter.signals = mchp_tc_count_signals;
> -	priv->counter.priv = priv;
> -
> -	return devm_counter_register(&pdev->dev, &priv->counter);
> +	counter->name = dev_name(&pdev->dev);
> +	counter->parent = &pdev->dev;
> +	counter->ops = &mchp_tc_ops;
> +	counter->num_counts = ARRAY_SIZE(mchp_tc_counts);
> +	counter->counts = mchp_tc_counts;
> +	counter->num_signals = ARRAY_SIZE(mchp_tc_count_signals);
> +	counter->signals = mchp_tc_count_signals;
> +
> +	ret = devm_counter_add(&pdev->dev, counter);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
> + 
> +	return 0;
>  }
>  
>  static const struct of_device_id mchp_tc_dt_ids[] = {
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 20/23] counter: stm32-timer-cnt: Convert to new counter registration
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-29  8:37     ` William Breathitt Gray
  -1 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:37 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, Benjamin Gaignard,
	linux-stm32, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 2569 bytes --]

On Mon, Dec 27, 2021 at 10:45:23AM +0100, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: ad29937e206f ("counter: Add STM32 Timer quadrature encoder")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/stm32-timer-cnt.c | 30 ++++++++++++++++++------------
>  1 file changed, 18 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
> index 4b05b198a8d8..5779ae7c73cf 100644
> --- a/drivers/counter/stm32-timer-cnt.c
> +++ b/drivers/counter/stm32-timer-cnt.c
> @@ -29,7 +29,6 @@ struct stm32_timer_regs {
>  };
>  
>  struct stm32_timer_cnt {
> -	struct counter_device counter;
>  	struct regmap *regmap;
>  	struct clk *clk;
>  	u32 max_arr;
> @@ -317,31 +316,38 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev)
>  	struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
>  	struct device *dev = &pdev->dev;
>  	struct stm32_timer_cnt *priv;
> +	struct counter_device *counter;
> +	int ret;
>  
>  	if (IS_ERR_OR_NULL(ddata))
>  		return -EINVAL;
>  
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
>  
> +	priv = counter_priv(counter);
> +
>  	priv->regmap = ddata->regmap;
>  	priv->clk = ddata->clk;
>  	priv->max_arr = ddata->max_arr;
>  
> -	priv->counter.name = dev_name(dev);
> -	priv->counter.parent = dev;
> -	priv->counter.ops = &stm32_timer_cnt_ops;
> -	priv->counter.counts = &stm32_counts;
> -	priv->counter.num_counts = 1;
> -	priv->counter.signals = stm32_signals;
> -	priv->counter.num_signals = ARRAY_SIZE(stm32_signals);
> -	priv->counter.priv = priv;
> +	counter->name = dev_name(dev);
> +	counter->parent = dev;
> +	counter->ops = &stm32_timer_cnt_ops;
> +	counter->counts = &stm32_counts;
> +	counter->num_counts = 1;
> +	counter->signals = stm32_signals;
> +	counter->num_signals = ARRAY_SIZE(stm32_signals);
>  
>  	platform_set_drvdata(pdev, priv);
>  
>  	/* Register Counter device */
> -	return devm_counter_register(dev, &priv->counter);
> +	ret = devm_counter_add(dev, counter);
> +	if (ret < 0)
> +		dev_err_probe(dev, ret, "Failed to add counter\n");
> +
> +	return ret;
>  }
>  
>  static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev)
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 20/23] counter: stm32-timer-cnt: Convert to new counter registration
@ 2021-12-29  8:37     ` William Breathitt Gray
  0 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:37 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, Benjamin Gaignard,
	linux-stm32, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2569 bytes --]

On Mon, Dec 27, 2021 at 10:45:23AM +0100, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: ad29937e206f ("counter: Add STM32 Timer quadrature encoder")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/stm32-timer-cnt.c | 30 ++++++++++++++++++------------
>  1 file changed, 18 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
> index 4b05b198a8d8..5779ae7c73cf 100644
> --- a/drivers/counter/stm32-timer-cnt.c
> +++ b/drivers/counter/stm32-timer-cnt.c
> @@ -29,7 +29,6 @@ struct stm32_timer_regs {
>  };
>  
>  struct stm32_timer_cnt {
> -	struct counter_device counter;
>  	struct regmap *regmap;
>  	struct clk *clk;
>  	u32 max_arr;
> @@ -317,31 +316,38 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev)
>  	struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
>  	struct device *dev = &pdev->dev;
>  	struct stm32_timer_cnt *priv;
> +	struct counter_device *counter;
> +	int ret;
>  
>  	if (IS_ERR_OR_NULL(ddata))
>  		return -EINVAL;
>  
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
>  
> +	priv = counter_priv(counter);
> +
>  	priv->regmap = ddata->regmap;
>  	priv->clk = ddata->clk;
>  	priv->max_arr = ddata->max_arr;
>  
> -	priv->counter.name = dev_name(dev);
> -	priv->counter.parent = dev;
> -	priv->counter.ops = &stm32_timer_cnt_ops;
> -	priv->counter.counts = &stm32_counts;
> -	priv->counter.num_counts = 1;
> -	priv->counter.signals = stm32_signals;
> -	priv->counter.num_signals = ARRAY_SIZE(stm32_signals);
> -	priv->counter.priv = priv;
> +	counter->name = dev_name(dev);
> +	counter->parent = dev;
> +	counter->ops = &stm32_timer_cnt_ops;
> +	counter->counts = &stm32_counts;
> +	counter->num_counts = 1;
> +	counter->signals = stm32_signals;
> +	counter->num_signals = ARRAY_SIZE(stm32_signals);
>  
>  	platform_set_drvdata(pdev, priv);
>  
>  	/* Register Counter device */
> -	return devm_counter_register(dev, &priv->counter);
> +	ret = devm_counter_add(dev, counter);
> +	if (ret < 0)
> +		dev_err_probe(dev, ret, "Failed to add counter\n");
> +
> +	return ret;
>  }
>  
>  static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev)
> -- 
> 2.33.0
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 21/23] counter: stm32-lptimer-cnt: Convert to new counter registration
  2021-12-27  9:45   ` Uwe Kleine-König
@ 2021-12-29  8:39     ` William Breathitt Gray
  -1 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:39 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, Benjamin Gaignard,
	linux-stm32, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 3007 bytes --]

On Mon, Dec 27, 2021 at 10:45:24AM +0100, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: 597f55e3f36c ("counter: stm32-lptimer: add counter device")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/stm32-lptimer-cnt.c | 33 +++++++++++++++++------------
>  1 file changed, 19 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
> index 9cf00e929cc0..68031d93ce89 100644
> --- a/drivers/counter/stm32-lptimer-cnt.c
> +++ b/drivers/counter/stm32-lptimer-cnt.c
> @@ -20,7 +20,6 @@
>  #include <linux/types.h>
>  
>  struct stm32_lptim_cnt {
> -	struct counter_device counter;
>  	struct device *dev;
>  	struct regmap *regmap;
>  	struct clk *clk;
> @@ -411,14 +410,17 @@ static struct counter_count stm32_lptim_in1_counts = {
>  static int stm32_lptim_cnt_probe(struct platform_device *pdev)
>  {
>  	struct stm32_lptimer *ddata = dev_get_drvdata(pdev->dev.parent);
> +	struct counter_device *counter;
>  	struct stm32_lptim_cnt *priv;
> +	int ret;
>  
>  	if (IS_ERR_OR_NULL(ddata))
>  		return -EINVAL;
>  
> -	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(&pdev->dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	priv->dev = &pdev->dev;
>  	priv->regmap = ddata->regmap;
> @@ -426,23 +428,26 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev)
>  	priv->ceiling = STM32_LPTIM_MAX_ARR;
>  
>  	/* Initialize Counter device */
> -	priv->counter.name = dev_name(&pdev->dev);
> -	priv->counter.parent = &pdev->dev;
> -	priv->counter.ops = &stm32_lptim_cnt_ops;
> +	counter->name = dev_name(&pdev->dev);
> +	counter->parent = &pdev->dev;
> +	counter->ops = &stm32_lptim_cnt_ops;
>  	if (ddata->has_encoder) {
> -		priv->counter.counts = &stm32_lptim_enc_counts;
> -		priv->counter.num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
> +		counter->counts = &stm32_lptim_enc_counts;
> +		counter->num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
>  	} else {
> -		priv->counter.counts = &stm32_lptim_in1_counts;
> -		priv->counter.num_signals = 1;
> +		counter->counts = &stm32_lptim_in1_counts;
> +		counter->num_signals = 1;
>  	}
> -	priv->counter.num_counts = 1;
> -	priv->counter.signals = stm32_lptim_cnt_signals;
> -	priv->counter.priv = priv;
> +	counter->num_counts = 1;
> +	counter->signals = stm32_lptim_cnt_signals;
>  
>  	platform_set_drvdata(pdev, priv);
>  
> -	return devm_counter_register(&pdev->dev, &priv->counter);
> +	ret = devm_counter_add(&pdev->dev, counter);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
> +
> +	return 0;
>  }
>  
>  #ifdef CONFIG_PM_SLEEP
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 21/23] counter: stm32-lptimer-cnt: Convert to new counter registration
@ 2021-12-29  8:39     ` William Breathitt Gray
  0 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:39 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, Benjamin Gaignard,
	linux-stm32, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 3007 bytes --]

On Mon, Dec 27, 2021 at 10:45:24AM +0100, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: 597f55e3f36c ("counter: stm32-lptimer: add counter device")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/stm32-lptimer-cnt.c | 33 +++++++++++++++++------------
>  1 file changed, 19 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
> index 9cf00e929cc0..68031d93ce89 100644
> --- a/drivers/counter/stm32-lptimer-cnt.c
> +++ b/drivers/counter/stm32-lptimer-cnt.c
> @@ -20,7 +20,6 @@
>  #include <linux/types.h>
>  
>  struct stm32_lptim_cnt {
> -	struct counter_device counter;
>  	struct device *dev;
>  	struct regmap *regmap;
>  	struct clk *clk;
> @@ -411,14 +410,17 @@ static struct counter_count stm32_lptim_in1_counts = {
>  static int stm32_lptim_cnt_probe(struct platform_device *pdev)
>  {
>  	struct stm32_lptimer *ddata = dev_get_drvdata(pdev->dev.parent);
> +	struct counter_device *counter;
>  	struct stm32_lptim_cnt *priv;
> +	int ret;
>  
>  	if (IS_ERR_OR_NULL(ddata))
>  		return -EINVAL;
>  
> -	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(&pdev->dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	priv->dev = &pdev->dev;
>  	priv->regmap = ddata->regmap;
> @@ -426,23 +428,26 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev)
>  	priv->ceiling = STM32_LPTIM_MAX_ARR;
>  
>  	/* Initialize Counter device */
> -	priv->counter.name = dev_name(&pdev->dev);
> -	priv->counter.parent = &pdev->dev;
> -	priv->counter.ops = &stm32_lptim_cnt_ops;
> +	counter->name = dev_name(&pdev->dev);
> +	counter->parent = &pdev->dev;
> +	counter->ops = &stm32_lptim_cnt_ops;
>  	if (ddata->has_encoder) {
> -		priv->counter.counts = &stm32_lptim_enc_counts;
> -		priv->counter.num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
> +		counter->counts = &stm32_lptim_enc_counts;
> +		counter->num_signals = ARRAY_SIZE(stm32_lptim_cnt_signals);
>  	} else {
> -		priv->counter.counts = &stm32_lptim_in1_counts;
> -		priv->counter.num_signals = 1;
> +		counter->counts = &stm32_lptim_in1_counts;
> +		counter->num_signals = 1;
>  	}
> -	priv->counter.num_counts = 1;
> -	priv->counter.signals = stm32_lptim_cnt_signals;
> -	priv->counter.priv = priv;
> +	counter->num_counts = 1;
> +	counter->signals = stm32_lptim_cnt_signals;
>  
>  	platform_set_drvdata(pdev, priv);
>  
> -	return devm_counter_register(&pdev->dev, &priv->counter);
> +	ret = devm_counter_add(&pdev->dev, counter);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret, "Failed to add counter\n");
> +
> +	return 0;
>  }
>  
>  #ifdef CONFIG_PM_SLEEP
> -- 
> 2.33.0
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 22/23] counter: ti-eqep: Convert to new counter registration
  2021-12-27  9:45 ` [PATCH v2 22/23] counter: ti-eqep: " Uwe Kleine-König
  2021-12-28 18:29   ` Jonathan Cameron
@ 2021-12-29  8:41   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:41 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, David Lechner

[-- Attachment #1: Type: text/plain, Size: 3033 bytes --]

On Mon, Dec 27, 2021 at 10:45:25AM +0100, Uwe Kleine-König wrote:
> This fixes device lifetime issues where it was possible to free a live
> struct device.
> 
> Fixes: f213729f6796 ("counter: new TI eQEP driver")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/ti-eqep.c | 29 +++++++++++++++--------------
>  1 file changed, 15 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
> index abeda966e7be..3b49b492d182 100644
> --- a/drivers/counter/ti-eqep.c
> +++ b/drivers/counter/ti-eqep.c
> @@ -368,13 +368,15 @@ static const struct regmap_config ti_eqep_regmap16_config = {
>  static int ti_eqep_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> +	struct counter_device *counter;
>  	struct ti_eqep_cnt *priv;
>  	void __iomem *base;
>  	int err;
>  
> -	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv)
> +	counter = devm_counter_alloc(dev, sizeof(*priv));
> +	if (!counter)
>  		return -ENOMEM;
> +	priv = counter_priv(counter);
>  
>  	base = devm_platform_ioremap_resource(pdev, 0);
>  	if (IS_ERR(base))
> @@ -390,16 +392,15 @@ static int ti_eqep_probe(struct platform_device *pdev)
>  	if (IS_ERR(priv->regmap16))
>  		return PTR_ERR(priv->regmap16);
>  
> -	priv->counter.name = dev_name(dev);
> -	priv->counter.parent = dev;
> -	priv->counter.ops = &ti_eqep_counter_ops;
> -	priv->counter.counts = ti_eqep_counts;
> -	priv->counter.num_counts = ARRAY_SIZE(ti_eqep_counts);
> -	priv->counter.signals = ti_eqep_signals;
> -	priv->counter.num_signals = ARRAY_SIZE(ti_eqep_signals);
> -	priv->counter.priv = priv;
> +	counter->name = dev_name(dev);
> +	counter->parent = dev;
> +	counter->ops = &ti_eqep_counter_ops;
> +	counter->counts = ti_eqep_counts;
> +	counter->num_counts = ARRAY_SIZE(ti_eqep_counts);
> +	counter->signals = ti_eqep_signals;
> +	counter->num_signals = ARRAY_SIZE(ti_eqep_signals);
>  
> -	platform_set_drvdata(pdev, priv);
> +	platform_set_drvdata(pdev, counter);
>  
>  	/*
>  	 * Need to make sure power is turned on. On AM33xx, this comes from the
> @@ -409,7 +410,7 @@ static int ti_eqep_probe(struct platform_device *pdev)
>  	pm_runtime_enable(dev);
>  	pm_runtime_get_sync(dev);
>  
> -	err = counter_register(&priv->counter);
> +	err = counter_add(counter);
>  	if (err < 0) {
>  		pm_runtime_put_sync(dev);
>  		pm_runtime_disable(dev);
> @@ -421,10 +422,10 @@ static int ti_eqep_probe(struct platform_device *pdev)
>  
>  static int ti_eqep_remove(struct platform_device *pdev)
>  {
> -	struct ti_eqep_cnt *priv = platform_get_drvdata(pdev);
> +	struct counter_device *counter = platform_get_drvdata(pdev);
>  	struct device *dev = &pdev->dev;
>  
> -	counter_unregister(&priv->counter);
> +	counter_unregister(counter);
>  	pm_runtime_put_sync(dev);
>  	pm_runtime_disable(dev);
>  
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 23/23] counter: remove old and now unused registration API
  2021-12-27  9:45 ` [PATCH v2 23/23] counter: remove old and now unused registration API Uwe Kleine-König
  2021-12-28 18:31   ` Jonathan Cameron
@ 2021-12-29  8:43   ` William Breathitt Gray
  1 sibling, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:43 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 5793 bytes --]

On Mon, Dec 27, 2021 at 10:45:26AM +0100, Uwe Kleine-König wrote:
> Usage of counter_register() yields issues in device lifetime tracking. All
> drivers were converted to the new API, so the old one can go away.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>

> ---
>  drivers/counter/counter-core.c | 97 ++--------------------------------
>  include/linux/counter.h        | 12 -----
>  2 files changed, 4 insertions(+), 105 deletions(-)
> 
> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> index 8261567b6272..3f7dc5718423 100644
> --- a/drivers/counter/counter-core.c
> +++ b/drivers/counter/counter-core.c
> @@ -38,8 +38,7 @@ static void counter_device_release(struct device *dev)
>  	counter_chrdev_remove(counter);
>  	ida_free(&counter_ida, dev->id);
>  
> -	if (!counter->legacy_device)
> -		kfree(container_of(counter, struct counter_device_allochelper, counter));
> +	kfree(container_of(counter, struct counter_device_allochelper, counter));
>  }
>  
>  static struct device_type counter_device_type = {
> @@ -62,76 +61,13 @@ static dev_t counter_devt;
>   */
>  void *counter_priv(const struct counter_device *const counter)
>  {
> -	if (counter->legacy_device) {
> -		return counter->priv;
> -	} else {
> -		struct counter_device_allochelper *ch =
> -			container_of(counter, struct counter_device_allochelper, counter);
> +	struct counter_device_allochelper *ch =
> +		container_of(counter, struct counter_device_allochelper, counter);
>  
> -		return &ch->privdata;
> -	}
> +	return &ch->privdata;
>  }
>  EXPORT_SYMBOL_GPL(counter_priv);
>  
> -/**
> - * counter_register - register Counter to the system
> - * @counter:	pointer to Counter to register
> - *
> - * This function registers a Counter to the system. A sysfs "counter" directory
> - * will be created and populated with sysfs attributes correlating with the
> - * Counter Signals, Synapses, and Counts respectively.
> - *
> - * RETURNS:
> - * 0 on success, negative error number on failure.
> - */
> -int counter_register(struct counter_device *const counter)
> -{
> -	struct device *const dev = &counter->dev;
> -	int id;
> -	int err;
> -
> -	counter->legacy_device = true;
> -
> -	/* Acquire unique ID */
> -	id = ida_alloc(&counter_ida, GFP_KERNEL);
> -	if (id < 0)
> -		return id;
> -
> -	mutex_init(&counter->ops_exist_lock);
> -
> -	/* Configure device structure for Counter */
> -	dev->id = id;
> -	dev->type = &counter_device_type;
> -	dev->bus = &counter_bus_type;
> -	dev->devt = MKDEV(MAJOR(counter_devt), id);
> -	if (counter->parent) {
> -		dev->parent = counter->parent;
> -		dev->of_node = counter->parent->of_node;
> -	}
> -	device_initialize(dev);
> -
> -	err = counter_sysfs_add(counter);
> -	if (err < 0)
> -		goto err_free_id;
> -
> -	err = counter_chrdev_add(counter);
> -	if (err < 0)
> -		goto err_free_id;
> -
> -	err = cdev_device_add(&counter->chrdev, dev);
> -	if (err < 0)
> -		goto err_remove_chrdev;
> -
> -	return 0;
> -
> -err_remove_chrdev:
> -	counter_chrdev_remove(counter);
> -err_free_id:
> -	put_device(dev);
> -	return err;
> -}
> -EXPORT_SYMBOL_GPL(counter_register);
> -
>  /**
>   * counter_alloc - allocate a counter_device
>   * @sizeof_priv: size of the driver private data
> @@ -255,31 +191,6 @@ static void devm_counter_release(void *counter)
>  	counter_unregister(counter);
>  }
>  
> -/**
> - * devm_counter_register - Resource-managed counter_register
> - * @dev:	device to allocate counter_device for
> - * @counter:	pointer to Counter to register
> - *
> - * Managed counter_register. The Counter registered with this function is
> - * automatically unregistered on driver detach. This function calls
> - * counter_register internally. Refer to that function for more information.
> - *
> - * RETURNS:
> - * 0 on success, negative error number on failure.
> - */
> -int devm_counter_register(struct device *dev,
> -			  struct counter_device *const counter)
> -{
> -	int err;
> -
> -	err = counter_register(counter);
> -	if (err < 0)
> -		return err;
> -
> -	return devm_add_action_or_reset(dev, devm_counter_release, counter);
> -}
> -EXPORT_SYMBOL_GPL(devm_counter_register);
> -
>  static void devm_counter_put(void *counter)
>  {
>  	counter_put(counter);
> diff --git a/include/linux/counter.h b/include/linux/counter.h
> index f1350a43cd48..9afa0f1e9cea 100644
> --- a/include/linux/counter.h
> +++ b/include/linux/counter.h
> @@ -314,8 +314,6 @@ struct counter_device {
>  	struct counter_comp *ext;
>  	size_t num_ext;
>  
> -	void *priv;
> -
>  	struct device dev;
>  	struct cdev chrdev;
>  	struct list_head events_list;
> @@ -327,25 +325,15 @@ struct counter_device {
>  	spinlock_t events_in_lock;
>  	struct mutex events_out_lock;
>  	struct mutex ops_exist_lock;
> -
> -	/*
> -	 * This can go away once all drivers are converted to
> -	 * counter_alloc()/counter_add().
> -	 */
> -	bool legacy_device;
>  };
>  
>  void *counter_priv(const struct counter_device *const counter);
>  
> -int counter_register(struct counter_device *const counter);
> -
>  struct counter_device *counter_alloc(size_t sizeof_priv);
>  void counter_put(struct counter_device *const counter);
>  int counter_add(struct counter_device *const counter);
>  
>  void counter_unregister(struct counter_device *const counter);
> -int devm_counter_register(struct device *dev,
> -			  struct counter_device *const counter);
>  struct counter_device *devm_counter_alloc(struct device *dev,
>  					  size_t sizeof_priv);
>  int devm_counter_add(struct device *dev,
> -- 
> 2.33.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 00/23] counter: cleanups and device lifetime fixes
  2021-12-28 17:35     ` Jonathan Cameron
@ 2021-12-29  8:49       ` William Breathitt Gray
  -1 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:49 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Uwe Kleine-König, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Patrick Havelange, Kamel Bouhara, linux-arm-kernel,
	Syed Nayyar Waris, Oleksij Rempel, Jarkko Nikula, David Lechner,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Jonathan Corbet, linux-doc, Ahmad Fatoum, Felipe Balbi (Intel),
	Raymond Tan, Benjamin Gaignard

[-- Attachment #1: Type: text/plain, Size: 1835 bytes --]

On Tue, Dec 28, 2021 at 05:35:58PM +0000, Jonathan Cameron wrote:
> On Mon, 27 Dec 2021 13:25:25 +0100
> Lars-Peter Clausen <lars@metafoo.de> wrote:
> 
> > On 12/27/21 10:45 AM, Uwe Kleine-König wrote:
> > > [...]
> > >
> > >   - I wonder why counter is a bus and not a class device type. There is
> > >     no driver that would ever bind a counter device, is there? So
> > >     /sys/bus/counter/driver is always empty.
> > >  
> > There used to be a time when GKH said that we do not want new driver 
> > classes. And all new subsystems should use bus since bus is a superset 
> > of class. This restriction has been eased since then.
> > 
> > But it was around when the IIO subsystem was merged and since the 
> > counter subsystem originated from the IIO subsystem I assume it just 
> > copied this.
> > 
> 
> Yup. Discussion about this back then with one view being there
> should never have been class in the first place.
> 
> https://lore.kernel.org/lkml/4B571DA4.6070603@cam.ac.uk/
> 
> For anyone who loves the history of these things...
> 
> FWIW I think Greg suggested IIO should be a bus because we were hanging
> a bunch of different types of device off a class and it was getting messy.
> Kay then gave some history on class vs bus and suggested no new
> subsystem should use class.
> 
> Ah well, opinions change over time!
> 
> Also interesting to see we were discussing a bridge to input all that
> time ago and it's still not gone beyond various prototypes (with
> exception of touch screens).
> 
> Jonathan

Yes this is the reason: Counter subsystem just followed the structure of
the IIO subsystem originally which is how it ended up as a bus; changing
it to a class now would break userspace expectations so that is why it
remains a bus still.

William Breathitt Gray

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 00/23] counter: cleanups and device lifetime fixes
@ 2021-12-29  8:49       ` William Breathitt Gray
  0 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29  8:49 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Uwe Kleine-König, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel,
	Patrick Havelange, Kamel Bouhara, linux-arm-kernel,
	Syed Nayyar Waris, Oleksij Rempel, Jarkko Nikula, David Lechner,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, linux-stm32,
	Jonathan Corbet, linux-doc, Ahmad Fatoum, Felipe Balbi (Intel),
	Raymond Tan, Benjamin Gaignard


[-- Attachment #1.1: Type: text/plain, Size: 1835 bytes --]

On Tue, Dec 28, 2021 at 05:35:58PM +0000, Jonathan Cameron wrote:
> On Mon, 27 Dec 2021 13:25:25 +0100
> Lars-Peter Clausen <lars@metafoo.de> wrote:
> 
> > On 12/27/21 10:45 AM, Uwe Kleine-König wrote:
> > > [...]
> > >
> > >   - I wonder why counter is a bus and not a class device type. There is
> > >     no driver that would ever bind a counter device, is there? So
> > >     /sys/bus/counter/driver is always empty.
> > >  
> > There used to be a time when GKH said that we do not want new driver 
> > classes. And all new subsystems should use bus since bus is a superset 
> > of class. This restriction has been eased since then.
> > 
> > But it was around when the IIO subsystem was merged and since the 
> > counter subsystem originated from the IIO subsystem I assume it just 
> > copied this.
> > 
> 
> Yup. Discussion about this back then with one view being there
> should never have been class in the first place.
> 
> https://lore.kernel.org/lkml/4B571DA4.6070603@cam.ac.uk/
> 
> For anyone who loves the history of these things...
> 
> FWIW I think Greg suggested IIO should be a bus because we were hanging
> a bunch of different types of device off a class and it was getting messy.
> Kay then gave some history on class vs bus and suggested no new
> subsystem should use class.
> 
> Ah well, opinions change over time!
> 
> Also interesting to see we were discussing a bridge to input all that
> time ago and it's still not gone beyond various prototypes (with
> exception of touch screens).
> 
> Jonathan

Yes this is the reason: Counter subsystem just followed the structure of
the IIO subsystem originally which is how it ended up as a bus; changing
it to a class now would break userspace expectations so that is why it
remains a bus still.

William Breathitt Gray

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 05/23] counter: 104-quad-8: Convert to counter_priv() wrapper
  2021-12-28 18:02   ` Jonathan Cameron
@ 2021-12-29 11:11     ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-29 11:11 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, linux-iio, Greg Kroah-Hartman,
	William Breathitt Gray, linux-kernel, kernel, Jonathan Cameron,
	Syed Nayyar Waris

[-- Attachment #1: Type: text/plain, Size: 667 bytes --]

On Tue, Dec 28, 2021 at 06:02:24PM +0000, Jonathan Cameron wrote:
> On Mon, 27 Dec 2021 10:45:08 +0100
> Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:
> 
> > This is a straight forward conversion to the new counter_priv() wrapper.
> > 
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> Looks sane and I'll assume you didn't miss any!

I assume so, too. At least it still compiles after I dropped priv from
struct counter_device :-)

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 05/23] counter: 104-quad-8: Convert to counter_priv() wrapper
  2021-12-29  7:27   ` William Breathitt Gray
@ 2021-12-29 11:15     ` Uwe Kleine-König
  2021-12-29 22:40       ` William Breathitt Gray
  0 siblings, 1 reply; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-29 11:15 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, linux-iio, Greg Kroah-Hartman, linux-kernel,
	kernel, Jonathan Cameron, Syed Nayyar Waris

[-- Attachment #1: Type: text/plain, Size: 1204 bytes --]

Hello William,

On Wed, Dec 29, 2021 at 04:27:33PM +0900, William Breathitt Gray wrote:
> On Mon, Dec 27, 2021 at 10:45:08AM +0100, Uwe Kleine-König wrote:
> > This is a straight forward conversion to the new counter_priv() wrapper.
> > 
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> This patch results in a minor merge conflict with commit c95cc0d95702
> ("counter: 104-quad-8: Fix persistent enabled events bug") in linux-next
> due to context changes in quad8_events_configure() and
> quad8_watch_validate(). Fixing this after a rebase is trivial so I'll
> give my Ack here.

this raises the question how this patch set is to be merged. My
expectaion up to now was, that this goes via you, so the merge conflict
shouldn't be an issue? What is your expectation who will pick up this
series?

Would a PR helpful, or will the series be picked up from the mailing
list?

I'm about to prepare a v3 adding all the review tags and fixing the few
issues that were pointed out.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 10/23] counter: ti-eqep: Convert to counter_priv() wrapper
  2021-12-29  7:45   ` William Breathitt Gray
@ 2021-12-29 11:19     ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-29 11:19 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Lars-Peter Clausen, David Lechner, linux-iio, Greg Kroah-Hartman,
	linux-kernel, kernel, Jonathan Cameron

[-- Attachment #1: Type: text/plain, Size: 850 bytes --]

On Wed, Dec 29, 2021 at 04:45:21PM +0900, William Breathitt Gray wrote:
> On Mon, Dec 27, 2021 at 10:45:13AM +0100, Uwe Kleine-König wrote:
> > This is a straight forward conversion to the new counter_priv() wrapper.
> > 
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> This patch conflicts with commit 60f07e74f86b ("counter: ti-eqep: Use
> container_of instead of struct counter_device::priv"). Because that
> commit has a similar purpose as this patchset, I'm going to skip this
> patch for now and continue looking over the rest of the patches in this
> series.

Ah right. I will base v3 on top of v5.16-rc6 + 60f07e74f86b. 

Best regards
Uwe


-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
  2021-12-28 18:00   ` Jonathan Cameron
@ 2021-12-29 11:27     ` Uwe Kleine-König
  2021-12-29 12:07       ` Uwe Kleine-König
  2021-12-29 13:49     ` Jarkko Nikula
  1 sibling, 1 reply; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-29 11:27 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, linux-iio, Greg Kroah-Hartman,
	William Breathitt Gray, linux-kernel, kernel, Jonathan Cameron

[-- Attachment #1: Type: text/plain, Size: 3942 bytes --]

Hello,

On Tue, Dec 28, 2021 at 06:00:17PM +0000, Jonathan Cameron wrote:
> On Mon, 27 Dec 2021 10:45:16 +0100
> Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:
> 
> > +struct counter_device_allochelper {
> > +	struct counter_device counter;
> > +	unsigned long privdata[];
> Nice to keep this opaque. We danced around how to do this in IIO for
> a while and never got to a solution we all liked.  Slight disadvantage
> is this might matter in hot paths where the compiler doesn't have visibility
> to know it can very cheaply access the privdata.
> 
> I guess that can be looked at if anyone ever measures it as an important
> element (they probably never will!)

*nod*

> > +};
> > +
> >  static void counter_device_release(struct device *dev)
> >  {
> >  	struct counter_device *const counter =
> > @@ -31,6 +37,9 @@ static void counter_device_release(struct device *dev)
> >  
> >  	counter_chrdev_remove(counter);
> >  	ida_free(&counter_ida, dev->id);
> > +
> > +	if (!counter->legacy_device)
> > +		kfree(container_of(counter, struct counter_device_allochelper, counter));
> >  }
> >  
> >  static struct device_type counter_device_type = {
> > @@ -53,7 +62,14 @@ static dev_t counter_devt;
> >   */
> >  void *counter_priv(const struct counter_device *const counter)
> >  {
> > -	return counter->priv;
> > +	if (counter->legacy_device) {
> > +		return counter->priv;
> > +	} else {
> > +		struct counter_device_allochelper *ch =
> > +			container_of(counter, struct counter_device_allochelper, counter);
> > +
> > +		return &ch->privdata;
> > +	}
> >  }
> >  EXPORT_SYMBOL_GPL(counter_priv);
> >  
> > @@ -74,6 +90,8 @@ int counter_register(struct counter_device *const counter)
> >  	int id;
> >  	int err;
> >  
> > +	counter->legacy_device = true;
> > +
> >  	/* Acquire unique ID */
> >  	id = ida_alloc(&counter_ida, GFP_KERNEL);
> >  	if (id < 0)
> > @@ -114,6 +132,100 @@ int counter_register(struct counter_device *const counter)
> >  }
> >  EXPORT_SYMBOL_GPL(counter_register);
> >  
> > +/**
> > + * counter_alloc - allocate a counter_device
> > + * @sizeof_priv: size of the driver private data
> > + *
> > + * This is part one of counter registration. The structure is allocated
> > + * dynamically to ensure the right lifetime for the embedded struct device.
> > + *
> > + * If this succeeds, call counter_put() to get rid of the counter_device again.
> > + */
> > +struct counter_device *counter_alloc(size_t sizeof_priv)
> > +{
> > +	struct counter_device_allochelper *ch;
> > +	struct counter_device *counter;
> > +	struct device *dev;
> > +	int id, err;
> > +
> > +	ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
> > +	if (!ch) {
> > +		err = -ENOMEM;
> > +		goto err_alloc_ch;
> > +	}
> > +
> > +	counter = &ch->counter;
> > +	dev = &counter->dev;
> > +
> > +	/* Acquire unique ID */
> > +	err = ida_alloc(&counter_ida, GFP_KERNEL);
> > +	if (err < 0) {
> > +		goto err_ida_alloc;
> > +	}
> > +	dev->id = err;
> > +
> > +	err = counter_chrdev_add(counter);
> 
> Should think about renaming  counter_chrdev_add() given it
> does init and allocation stuff but no adding.

This is orthogonal to this series though. So I won't address this in the
context of the lifetime fixes here.

> Personal inclination here would be to keep the elements in here
> in the same order as in counter_register() where it doesn't matter
> in the interests of slightly easier comparison of the code.

I reordered a bit because counter_register fails to undo ida_alloc() in
the error path. However I might have missed that some initialisation has
to be done before calling counter_chrdev_add().

Will check in detail for v3.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
  2021-12-29 11:27     ` Uwe Kleine-König
@ 2021-12-29 12:07       ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-29 12:07 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, linux-iio, Greg Kroah-Hartman,
	William Breathitt Gray, linux-kernel, kernel, Jonathan Cameron

[-- Attachment #1: Type: text/plain, Size: 981 bytes --]

Hello,

On Wed, Dec 29, 2021 at 12:27:32PM +0100, Uwe Kleine-König wrote:
> > Personal inclination here would be to keep the elements in here
> > in the same order as in counter_register() where it doesn't matter
> > in the interests of slightly easier comparison of the code.
> 
> I reordered a bit because counter_register fails to undo ida_alloc() in
> the error path. However I might have missed that some initialisation has
> to be done before calling counter_chrdev_add().

Another issue in counter_register() is: If counter_sysfs_add() fails,
put_device() is called which eventually calls counter_device_release()
-> counter_chrdev_remove() -> kfifo_free(). I think it's not a real
problem, but it's ugly because because counter_chrdev_add()
-> kfifo_alloc() wasn't called yet.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 17/23] counter: intel-qep: Convert to new counter registration
  2021-12-28 10:56     ` Uwe Kleine-König
@ 2021-12-29 12:42       ` Jarkko Nikula
  0 siblings, 0 replies; 125+ messages in thread
From: Jarkko Nikula @ 2021-12-29 12:42 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: William Breathitt Gray, Felipe Balbi (Intel),
	Lars-Peter Clausen, Raymond Tan, linux-iio, Greg Kroah-Hartman,
	linux-kernel, kernel, Jonathan Cameron

On 12/28/21 12:56, Uwe Kleine-König wrote:
> On Mon, Dec 27, 2021 at 05:02:39PM +0200, Jarkko Nikula wrote:
>> On 12/27/21 11:45, Uwe Kleine-König wrote:
>>> This fixes device lifetime issues where it was possible to free a live
>>> struct device.
>>>
>>> Fixes: b711f687a1c1 ("counter: Add support for Intel Quadrature Encoder Peripheral")
>>> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>>> ---
>>>    drivers/counter/intel-qep.c | 28 ++++++++++++++++------------
>>>    1 file changed, 16 insertions(+), 12 deletions(-)
>>>
>> Should the Fixes tag rather be b6c50affda59 ("counter: Add character device
>> interface") instead of when each drivers were introduced? I mean was it
>> possible to hit the issue before /dev/counter was introduced?
> 
> I'm not sure if there is an issue before this, but it was already wrong
> before for sure. Maybe it's possible to hold a reference somehow via
> sysfs?
> 
> The thought that made me tag the individual driver commits was: With the
> approach used to fix the issue all drivers need to be modified and an
> unconverted driver doesn't benefit from the availability of
> counter_alloc() / counter_add() if it isn't used. So all trees that
> include b711f687a1c1 but not "counter: intel-qep: Convert to new counter
> registration" are broken (more or less exploitable). So I think the
> added Fixes line is the right choice.
> 
Fair enough. Noticed only now after this patch (with patches 1, 4, 8 and 
13 applied) second counter instance initialization fails:

[    8.113999] sysfs: cannot create duplicate filename '/dev/char/244:0
[    8.139604] Call Trace:
[    8.139606]  <TASK>
[    8.139608]  show_stack+0x3d/0x3f
[    8.139615]  dump_stack_lvl+0x5b/0x82
[    8.139619]  dump_stack+0x10/0x12
[    8.139621]  sysfs_warn_dup.cold+0x17/0x27
[    8.139624]  sysfs_do_create_link_sd+0xc2/0xd0
[    8.139629]  sysfs_create_link+0x1c/0x30
[    8.139631]  device_add+0x54f/0x7c0
[    8.139635]  ? cdev_default_release+0x20/0x20
[    8.139638]  cdev_device_add+0x47/0x90
[    8.139642]  devm_counter_add+0x61/0xe0 [counter]
[    8.139647]  intel_qep_probe+0x16f/0x1b0
...
[    8.325081] intel-qep 0000:00:18.6: error -EEXIST: Failed to add counter
[    8.371793] intel-qep: probe of 0000:00:18.6 failed with error -17

Positive result is that following test doesn't produce an oops after a 
few iterations like before this patch.

while :; do { sleep 5; echo bang; } > /dev/counter0 & sleep 1; echo 
0000:00:18.4 >/sys/bus/pci/drivers/intel-qep/unbind; sleep 8; echo 
0000:00:18.4 >/sys/bus/pci/drivers/intel-qep/bind; done

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

* Re: [PATCH v2 08/23] counter: intel-qep: Convert to counter_priv() wrapper
  2021-12-27  9:45 ` [PATCH v2 08/23] counter: intel-qep: " Uwe Kleine-König
  2021-12-28 18:06   ` Jonathan Cameron
  2021-12-29  7:35   ` William Breathitt Gray
@ 2021-12-29 12:43   ` Jarkko Nikula
  2 siblings, 0 replies; 125+ messages in thread
From: Jarkko Nikula @ 2021-12-29 12:43 UTC (permalink / raw)
  To: Uwe Kleine-König, William Breathitt Gray
  Cc: Lars-Peter Clausen, kernel, Jonathan Cameron, linux-iio,
	Greg Kroah-Hartman, linux-kernel, Felipe Balbi (Intel),
	Raymond Tan

On 12/27/21 11:45, Uwe Kleine-König wrote:
> This is a straight forward conversion to the new counter_priv() wrapper.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>   drivers/counter/intel-qep.c | 18 +++++++++---------
>   1 file changed, 9 insertions(+), 9 deletions(-)
> 
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
  2021-12-28 18:00   ` Jonathan Cameron
  2021-12-29 11:27     ` Uwe Kleine-König
@ 2021-12-29 13:49     ` Jarkko Nikula
  2021-12-29 15:47       ` Uwe Kleine-König
  1 sibling, 1 reply; 125+ messages in thread
From: Jarkko Nikula @ 2021-12-29 13:49 UTC (permalink / raw)
  To: Jonathan Cameron, Uwe Kleine-König
  Cc: William Breathitt Gray, Lars-Peter Clausen, kernel,
	Jonathan Cameron, linux-iio, Greg Kroah-Hartman, linux-kernel

On 12/28/21 20:00, Jonathan Cameron wrote:
> On Mon, 27 Dec 2021 10:45:16 +0100
> Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:
>> +	if (err < 0)
>> +		goto err_chrdev_add;
>> +
>> +	device_initialize(dev);
>> +	/* Configure device structure for Counter */
>> +	dev->type = &counter_device_type;
>> +	dev->bus = &counter_bus_type;
>> +	dev->devt = MKDEV(MAJOR(counter_devt), id);
> 
> As 0-day pointed out id not initialized.
> 
This was the reason why second counter instance initialization failed 
for me when testing the patch 17. I fixed it locally by changing the 
line a few rows above the MKDEV():

-	dev->id = err;
+	dev->id = id = err;

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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
  2021-12-29 13:49     ` Jarkko Nikula
@ 2021-12-29 15:47       ` Uwe Kleine-König
  0 siblings, 0 replies; 125+ messages in thread
From: Uwe Kleine-König @ 2021-12-29 15:47 UTC (permalink / raw)
  To: Jarkko Nikula
  Cc: Jonathan Cameron, Lars-Peter Clausen, linux-iio,
	Greg Kroah-Hartman, William Breathitt Gray, linux-kernel, kernel,
	Jonathan Cameron

[-- Attachment #1: Type: text/plain, Size: 1144 bytes --]

On Wed, Dec 29, 2021 at 03:49:29PM +0200, Jarkko Nikula wrote:
> On 12/28/21 20:00, Jonathan Cameron wrote:
> > On Mon, 27 Dec 2021 10:45:16 +0100
> > Uwe Kleine-König         <u.kleine-koenig@pengutronix.de> wrote:
> > > +	if (err < 0)
> > > +		goto err_chrdev_add;
> > > +
> > > +	device_initialize(dev);
> > > +	/* Configure device structure for Counter */
> > > +	dev->type = &counter_device_type;
> > > +	dev->bus = &counter_bus_type;
> > > +	dev->devt = MKDEV(MAJOR(counter_devt), id);
> > 
> > As 0-day pointed out id not initialized.
> > 
> This was the reason why second counter instance initialization failed for me
> when testing the patch 17. I fixed it locally by changing the line a few
> rows above the MKDEV():
> 
> -	dev->id = err;
> +	dev->id = id = err;

Instead I dropped id for v3. I failed to check this mailthread again
before sending it out. So I missed your feedback. I will go through it
again and comment later.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 05/23] counter: 104-quad-8: Convert to counter_priv() wrapper
  2021-12-29 11:15     ` Uwe Kleine-König
@ 2021-12-29 22:40       ` William Breathitt Gray
  0 siblings, 0 replies; 125+ messages in thread
From: William Breathitt Gray @ 2021-12-29 22:40 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Lars-Peter Clausen, linux-iio, Greg Kroah-Hartman, linux-kernel,
	kernel, Jonathan Cameron, Syed Nayyar Waris

[-- Attachment #1: Type: text/plain, Size: 1584 bytes --]

On Wed, Dec 29, 2021 at 12:15:22PM +0100, Uwe Kleine-König wrote:
> Hello William,
> 
> On Wed, Dec 29, 2021 at 04:27:33PM +0900, William Breathitt Gray wrote:
> > On Mon, Dec 27, 2021 at 10:45:08AM +0100, Uwe Kleine-König wrote:
> > > This is a straight forward conversion to the new counter_priv() wrapper.
> > > 
> > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > 
> > This patch results in a minor merge conflict with commit c95cc0d95702
> > ("counter: 104-quad-8: Fix persistent enabled events bug") in linux-next
> > due to context changes in quad8_events_configure() and
> > quad8_watch_validate(). Fixing this after a rebase is trivial so I'll
> > give my Ack here.
> 
> this raises the question how this patch set is to be merged. My
> expectaion up to now was, that this goes via you, so the merge conflict
> shouldn't be an issue? What is your expectation who will pick up this
> series?
> 
> Would a PR helpful, or will the series be picked up from the mailing
> list?
> 
> I'm about to prepare a v3 adding all the review tags and fixing the few
> issues that were pointed out.
> 
> Best regards
> Uwe
> 
> -- 
> Pengutronix e.K.                           | Uwe Kleine-König            |
> Industrial Linux Solutions                 | https://www.pengutronix.de/ |

If Greg or Jonathan don't pick this series up from the mailing list
here, I can merge it to my personal tree and then submit it in the next
cycle with any other Counter subsystem changes that come in along the
way.

William Breathitt Gray

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
@ 2022-01-06 10:53 ` Dan Carpenter
  0 siblings, 0 replies; 125+ messages in thread
From: Dan Carpenter @ 2022-01-06 10:53 UTC (permalink / raw)
  To: kbuild, Uwe Kleine-König, William Breathitt Gray
  Cc: lkp, kbuild-all, Lars-Peter Clausen, kernel, Jonathan Cameron,
	linux-iio, Greg Kroah-Hartman, linux-kernel

Hi "Uwe,

url:    https://github.com/0day-ci/linux/commits/Uwe-Kleine-K-nig/counter-cleanups-and-device-lifetime-fixes/20211227-174815
base:   a7904a538933c525096ca2ccde1e60d0ee62c08e
config: i386-randconfig-m021-20211227 (https://download.01.org/0day-ci/archive/20211229/202112290340.PMwi47LV-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/counter/counter-core.c:175 counter_alloc() error: uninitialized symbol 'id'.

vim +/id +175 drivers/counter/counter-core.c

250e0e3d91caea Uwe Kleine-König       2021-12-27  144  struct counter_device *counter_alloc(size_t sizeof_priv)
250e0e3d91caea Uwe Kleine-König       2021-12-27  145  {
250e0e3d91caea Uwe Kleine-König       2021-12-27  146  	struct counter_device_allochelper *ch;
250e0e3d91caea Uwe Kleine-König       2021-12-27  147  	struct counter_device *counter;
250e0e3d91caea Uwe Kleine-König       2021-12-27  148  	struct device *dev;
250e0e3d91caea Uwe Kleine-König       2021-12-27  149  	int id, err;
250e0e3d91caea Uwe Kleine-König       2021-12-27  150  
250e0e3d91caea Uwe Kleine-König       2021-12-27  151  	ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
250e0e3d91caea Uwe Kleine-König       2021-12-27  152  	if (!ch) {
250e0e3d91caea Uwe Kleine-König       2021-12-27  153  		err = -ENOMEM;
250e0e3d91caea Uwe Kleine-König       2021-12-27  154  		goto err_alloc_ch;
250e0e3d91caea Uwe Kleine-König       2021-12-27  155  	}
250e0e3d91caea Uwe Kleine-König       2021-12-27  156  
250e0e3d91caea Uwe Kleine-König       2021-12-27  157  	counter = &ch->counter;
250e0e3d91caea Uwe Kleine-König       2021-12-27  158  	dev = &counter->dev;
250e0e3d91caea Uwe Kleine-König       2021-12-27  159  
250e0e3d91caea Uwe Kleine-König       2021-12-27  160  	/* Acquire unique ID */
250e0e3d91caea Uwe Kleine-König       2021-12-27  161  	err = ida_alloc(&counter_ida, GFP_KERNEL);
250e0e3d91caea Uwe Kleine-König       2021-12-27  162  	if (err < 0) {
250e0e3d91caea Uwe Kleine-König       2021-12-27  163  		goto err_ida_alloc;
250e0e3d91caea Uwe Kleine-König       2021-12-27  164  	}
250e0e3d91caea Uwe Kleine-König       2021-12-27  165  	dev->id = err;
250e0e3d91caea Uwe Kleine-König       2021-12-27  166  
250e0e3d91caea Uwe Kleine-König       2021-12-27  167  	err = counter_chrdev_add(counter);
250e0e3d91caea Uwe Kleine-König       2021-12-27  168  	if (err < 0)
250e0e3d91caea Uwe Kleine-König       2021-12-27  169  		goto err_chrdev_add;
250e0e3d91caea Uwe Kleine-König       2021-12-27  170  
250e0e3d91caea Uwe Kleine-König       2021-12-27  171  	device_initialize(dev);
250e0e3d91caea Uwe Kleine-König       2021-12-27  172  	/* Configure device structure for Counter */
250e0e3d91caea Uwe Kleine-König       2021-12-27  173  	dev->type = &counter_device_type;
250e0e3d91caea Uwe Kleine-König       2021-12-27  174  	dev->bus = &counter_bus_type;
250e0e3d91caea Uwe Kleine-König       2021-12-27 @175  	dev->devt = MKDEV(MAJOR(counter_devt), id);

"id" is uninitialized.  Should this be "dev->id"?

250e0e3d91caea Uwe Kleine-König       2021-12-27  176  
250e0e3d91caea Uwe Kleine-König       2021-12-27  177  	mutex_init(&counter->ops_exist_lock);
250e0e3d91caea Uwe Kleine-König       2021-12-27  178  
250e0e3d91caea Uwe Kleine-König       2021-12-27  179  	return counter;
250e0e3d91caea Uwe Kleine-König       2021-12-27  180  
250e0e3d91caea Uwe Kleine-König       2021-12-27  181  err_chrdev_add:
250e0e3d91caea Uwe Kleine-König       2021-12-27  182  
250e0e3d91caea Uwe Kleine-König       2021-12-27  183  	ida_free(&counter_ida, dev->id);
250e0e3d91caea Uwe Kleine-König       2021-12-27  184  err_ida_alloc:
250e0e3d91caea Uwe Kleine-König       2021-12-27  185  
250e0e3d91caea Uwe Kleine-König       2021-12-27  186  	kfree(ch);
250e0e3d91caea Uwe Kleine-König       2021-12-27  187  err_alloc_ch:
250e0e3d91caea Uwe Kleine-König       2021-12-27  188  
250e0e3d91caea Uwe Kleine-König       2021-12-27  189  	return ERR_PTR(err);
250e0e3d91caea Uwe Kleine-König       2021-12-27  190  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org


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

* Re: [PATCH v2 13/23] counter: Provide alternative counter registration functions
@ 2022-01-06 10:53 ` Dan Carpenter
  0 siblings, 0 replies; 125+ messages in thread
From: Dan Carpenter @ 2022-01-06 10:53 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 4426 bytes --]

Hi "Uwe,

url:    https://github.com/0day-ci/linux/commits/Uwe-Kleine-K-nig/counter-cleanups-and-device-lifetime-fixes/20211227-174815
base:   a7904a538933c525096ca2ccde1e60d0ee62c08e
config: i386-randconfig-m021-20211227 (https://download.01.org/0day-ci/archive/20211229/202112290340.PMwi47LV-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/counter/counter-core.c:175 counter_alloc() error: uninitialized symbol 'id'.

vim +/id +175 drivers/counter/counter-core.c

250e0e3d91caea Uwe Kleine-König       2021-12-27  144  struct counter_device *counter_alloc(size_t sizeof_priv)
250e0e3d91caea Uwe Kleine-König       2021-12-27  145  {
250e0e3d91caea Uwe Kleine-König       2021-12-27  146  	struct counter_device_allochelper *ch;
250e0e3d91caea Uwe Kleine-König       2021-12-27  147  	struct counter_device *counter;
250e0e3d91caea Uwe Kleine-König       2021-12-27  148  	struct device *dev;
250e0e3d91caea Uwe Kleine-König       2021-12-27  149  	int id, err;
250e0e3d91caea Uwe Kleine-König       2021-12-27  150  
250e0e3d91caea Uwe Kleine-König       2021-12-27  151  	ch = kzalloc(sizeof(*ch) + sizeof_priv, GFP_KERNEL);
250e0e3d91caea Uwe Kleine-König       2021-12-27  152  	if (!ch) {
250e0e3d91caea Uwe Kleine-König       2021-12-27  153  		err = -ENOMEM;
250e0e3d91caea Uwe Kleine-König       2021-12-27  154  		goto err_alloc_ch;
250e0e3d91caea Uwe Kleine-König       2021-12-27  155  	}
250e0e3d91caea Uwe Kleine-König       2021-12-27  156  
250e0e3d91caea Uwe Kleine-König       2021-12-27  157  	counter = &ch->counter;
250e0e3d91caea Uwe Kleine-König       2021-12-27  158  	dev = &counter->dev;
250e0e3d91caea Uwe Kleine-König       2021-12-27  159  
250e0e3d91caea Uwe Kleine-König       2021-12-27  160  	/* Acquire unique ID */
250e0e3d91caea Uwe Kleine-König       2021-12-27  161  	err = ida_alloc(&counter_ida, GFP_KERNEL);
250e0e3d91caea Uwe Kleine-König       2021-12-27  162  	if (err < 0) {
250e0e3d91caea Uwe Kleine-König       2021-12-27  163  		goto err_ida_alloc;
250e0e3d91caea Uwe Kleine-König       2021-12-27  164  	}
250e0e3d91caea Uwe Kleine-König       2021-12-27  165  	dev->id = err;
250e0e3d91caea Uwe Kleine-König       2021-12-27  166  
250e0e3d91caea Uwe Kleine-König       2021-12-27  167  	err = counter_chrdev_add(counter);
250e0e3d91caea Uwe Kleine-König       2021-12-27  168  	if (err < 0)
250e0e3d91caea Uwe Kleine-König       2021-12-27  169  		goto err_chrdev_add;
250e0e3d91caea Uwe Kleine-König       2021-12-27  170  
250e0e3d91caea Uwe Kleine-König       2021-12-27  171  	device_initialize(dev);
250e0e3d91caea Uwe Kleine-König       2021-12-27  172  	/* Configure device structure for Counter */
250e0e3d91caea Uwe Kleine-König       2021-12-27  173  	dev->type = &counter_device_type;
250e0e3d91caea Uwe Kleine-König       2021-12-27  174  	dev->bus = &counter_bus_type;
250e0e3d91caea Uwe Kleine-König       2021-12-27 @175  	dev->devt = MKDEV(MAJOR(counter_devt), id);

"id" is uninitialized.  Should this be "dev->id"?

250e0e3d91caea Uwe Kleine-König       2021-12-27  176  
250e0e3d91caea Uwe Kleine-König       2021-12-27  177  	mutex_init(&counter->ops_exist_lock);
250e0e3d91caea Uwe Kleine-König       2021-12-27  178  
250e0e3d91caea Uwe Kleine-König       2021-12-27  179  	return counter;
250e0e3d91caea Uwe Kleine-König       2021-12-27  180  
250e0e3d91caea Uwe Kleine-König       2021-12-27  181  err_chrdev_add:
250e0e3d91caea Uwe Kleine-König       2021-12-27  182  
250e0e3d91caea Uwe Kleine-König       2021-12-27  183  	ida_free(&counter_ida, dev->id);
250e0e3d91caea Uwe Kleine-König       2021-12-27  184  err_ida_alloc:
250e0e3d91caea Uwe Kleine-König       2021-12-27  185  
250e0e3d91caea Uwe Kleine-König       2021-12-27  186  	kfree(ch);
250e0e3d91caea Uwe Kleine-König       2021-12-27  187  err_alloc_ch:
250e0e3d91caea Uwe Kleine-König       2021-12-27  188  
250e0e3d91caea Uwe Kleine-König       2021-12-27  189  	return ERR_PTR(err);
250e0e3d91caea Uwe Kleine-König       2021-12-27  190  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

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

end of thread, other threads:[~2022-01-06 10:54 UTC | newest]

Thread overview: 125+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-27  9:45 [PATCH v2 00/23] counter: cleanups and device lifetime fixes Uwe Kleine-König
2021-12-27  9:45 ` Uwe Kleine-König
2021-12-27  9:45 ` [PATCH v2 01/23] counter: Use container_of instead of drvdata to track counter_device Uwe Kleine-König
2021-12-28 17:14   ` Jonathan Cameron
2021-12-29  6:38   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 02/23] counter: ftm-quaddec: Drop unused platform_set_drvdata() Uwe Kleine-König
2021-12-28 17:37   ` Jonathan Cameron
2021-12-29  6:42   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 03/23] counter: microchip-tcb-capture: " Uwe Kleine-König
2021-12-27  9:45   ` Uwe Kleine-König
2021-12-28 17:38   ` Jonathan Cameron
2021-12-28 17:38     ` Jonathan Cameron
2021-12-29  6:44   ` William Breathitt Gray
2021-12-29  6:44     ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 04/23] counter: Provide a wrapper to access device private data Uwe Kleine-König
2021-12-27 11:02   ` Greg Kroah-Hartman
2021-12-27 11:34     ` Lars-Peter Clausen
2021-12-27 11:52       ` Greg Kroah-Hartman
2021-12-27 12:28         ` Lars-Peter Clausen
2021-12-28 18:01   ` Jonathan Cameron
2021-12-29  6:47   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 05/23] counter: 104-quad-8: Convert to counter_priv() wrapper Uwe Kleine-König
2021-12-28 18:02   ` Jonathan Cameron
2021-12-29 11:11     ` Uwe Kleine-König
2021-12-29  7:27   ` William Breathitt Gray
2021-12-29 11:15     ` Uwe Kleine-König
2021-12-29 22:40       ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 06/23] counter: interrupt-cnt: " Uwe Kleine-König
2021-12-28 18:04   ` Jonathan Cameron
2021-12-29  7:34   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 07/23] counter: microchip-tcb-capture: " Uwe Kleine-König
2021-12-27  9:45   ` Uwe Kleine-König
2021-12-28 18:05   ` Jonathan Cameron
2021-12-28 18:05     ` Jonathan Cameron
2021-12-29  7:35   ` William Breathitt Gray
2021-12-29  7:35     ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 08/23] counter: intel-qep: " Uwe Kleine-König
2021-12-28 18:06   ` Jonathan Cameron
2021-12-29  7:35   ` William Breathitt Gray
2021-12-29 12:43   ` Jarkko Nikula
2021-12-27  9:45 ` [PATCH v2 09/23] counter: ftm-quaddec: " Uwe Kleine-König
2021-12-28 18:07   ` Jonathan Cameron
2021-12-29  7:36   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 10/23] counter: ti-eqep: " Uwe Kleine-König
2021-12-28 18:07   ` Jonathan Cameron
2021-12-29  7:45   ` William Breathitt Gray
2021-12-29 11:19     ` Uwe Kleine-König
2021-12-27  9:45 ` [PATCH v2 11/23] counter: stm32-lptimer-cnt: " Uwe Kleine-König
2021-12-27  9:45   ` Uwe Kleine-König
2021-12-28 18:08   ` Jonathan Cameron
2021-12-28 18:08     ` Jonathan Cameron
2021-12-29  7:48   ` William Breathitt Gray
2021-12-29  7:48     ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 12/23] counter: stm32-timer-cnt: " Uwe Kleine-König
2021-12-27  9:45   ` Uwe Kleine-König
2021-12-28 18:08   ` Jonathan Cameron
2021-12-28 18:08     ` Jonathan Cameron
2021-12-29  7:48   ` William Breathitt Gray
2021-12-29  7:48     ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 13/23] counter: Provide alternative counter registration functions Uwe Kleine-König
2021-12-27 12:16   ` Lars-Peter Clausen
2021-12-28 11:22     ` Uwe Kleine-König
2021-12-27 12:18   ` kernel test robot
2021-12-27 12:18     ` kernel test robot
2021-12-28 18:00   ` Jonathan Cameron
2021-12-29 11:27     ` Uwe Kleine-König
2021-12-29 12:07       ` Uwe Kleine-König
2021-12-29 13:49     ` Jarkko Nikula
2021-12-29 15:47       ` Uwe Kleine-König
2021-12-29  8:13   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 14/23] counter: Update documentation for new " Uwe Kleine-König
2021-12-28 18:12   ` Jonathan Cameron
2021-12-29  8:19     ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 15/23] counter: 104-quad-8: Convert to new counter registration Uwe Kleine-König
2021-12-27 12:19   ` Lars-Peter Clausen
2021-12-28 11:06     ` Uwe Kleine-König
2021-12-28 18:17   ` Jonathan Cameron
2021-12-29  8:24   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 16/23] counter: interrupt-cnt: " Uwe Kleine-König
2021-12-27 10:59   ` Greg Kroah-Hartman
2021-12-27 11:21     ` Lars-Peter Clausen
2021-12-27 11:34       ` Greg Kroah-Hartman
2021-12-27 11:44         ` Lars-Peter Clausen
2021-12-27 21:09         ` Uwe Kleine-König
2021-12-28 18:18   ` Jonathan Cameron
2021-12-29  8:27   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 17/23] counter: intel-qep: " Uwe Kleine-König
2021-12-27 15:02   ` Jarkko Nikula
2021-12-28 10:56     ` Uwe Kleine-König
2021-12-29 12:42       ` Jarkko Nikula
2021-12-28 18:20   ` Jonathan Cameron
2021-12-29  8:29   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 18/23] counter: ftm-quaddec: " Uwe Kleine-König
2021-12-28 18:23   ` Jonathan Cameron
2021-12-29  8:33   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 19/23] counter: microchip-tcb-capture: " Uwe Kleine-König
2021-12-28 18:24   ` Jonathan Cameron
2021-12-29  8:36   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 20/23] counter: stm32-timer-cnt: " Uwe Kleine-König
2021-12-27  9:45   ` Uwe Kleine-König
2021-12-28 18:25   ` Jonathan Cameron
2021-12-28 18:25     ` Jonathan Cameron
2021-12-29  8:37   ` William Breathitt Gray
2021-12-29  8:37     ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 21/23] counter: stm32-lptimer-cnt: " Uwe Kleine-König
2021-12-27  9:45   ` Uwe Kleine-König
2021-12-28 18:26   ` Jonathan Cameron
2021-12-28 18:26     ` Jonathan Cameron
2021-12-29  8:39   ` William Breathitt Gray
2021-12-29  8:39     ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 22/23] counter: ti-eqep: " Uwe Kleine-König
2021-12-28 18:29   ` Jonathan Cameron
2021-12-29  8:41   ` William Breathitt Gray
2021-12-27  9:45 ` [PATCH v2 23/23] counter: remove old and now unused registration API Uwe Kleine-König
2021-12-28 18:31   ` Jonathan Cameron
2021-12-29  8:43   ` William Breathitt Gray
2021-12-27 12:25 ` [PATCH v2 00/23] counter: cleanups and device lifetime fixes Lars-Peter Clausen
2021-12-27 12:25   ` Lars-Peter Clausen
2021-12-28 17:35   ` Jonathan Cameron
2021-12-28 17:35     ` Jonathan Cameron
2021-12-29  8:49     ` William Breathitt Gray
2021-12-29  8:49       ` William Breathitt Gray
2021-12-28 19:45 [PATCH v2 13/23] counter: Provide alternative counter registration functions kernel test robot
2022-01-06 10:53 ` Dan Carpenter
2022-01-06 10:53 ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.