Skip to contentSkip to conversation

Counter updates, cleanups, and features for 5.18

PATCH RESEND In review William Breathitt Gray 2 participants 9 messages Mar 15, 2022 – Mar 16, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Counter updates, cleanups, and features for 5.18

First set of new Counter updates, cleanups, and features for 5.18

Only a few changes this cycle, but we do see the addition of a new COUNTER_EVENT_CHANGE_OF_STATE event type that allows userspace to watch counter pulses.

Features
* Add new COUNTER_EVENT_CHANGE_OF_STATE. This adds new counter event to notify user space about every new counter pulse. The interrupt-cnt driver is the first to use this new feature.

Cleanups
- Add Counter subsystem git tree to MAINTAINERS file.
- Set counter device name. This provides a convenient way to identify the counter device in devres_log events and similar situations.
- Add defaults to switch-statements. This pacifies warning messages from Clang static analysis reports.

Driver Updates
* 104-quad-8
- Add COMPILE_TEST depends
* interrupt-cnt
- Add counter_push_event()

Oleksij Rempel (2):
counter: add new COUNTER_EVENT_CHANGE_OF_STATE
counter: interrupt-cnt: add counter_push_event()

Tom Rix (1):
counter: add defaults to switch-statements

William Breathitt Gray (3):
counter: 104-quad-8: Add COMPILE_TEST depends
counter: Set counter device name
MAINTAINERS: Add Counter subsystem git tree

 MAINTAINERS                      |  1 +
 drivers/counter/Kconfig          |  2 +-
 drivers/counter/counter-chrdev.c |  4 ++++
 drivers/counter/counter-core.c   | 12 +++++++++++-
 drivers/counter/interrupt-cnt.c  |  7 +++++--
 include/uapi/linux/counter.h     |  2 ++
 6 files changed, 24 insertions(+), 4 deletions(-)

base-commit: 7e57714cd0ad2d5bb90e50b5096a0e671dec1ef3

Signature · 1 line
2.35.1
#1 lore raw

PATCH RESEND 1/6 counter: 104-quad-8: Add COMPILE_TEST depends

104_QUAD_8 depends on X86, but compiles fine on ARCH=arm. This patch adds support for COMPILE_TEST which is useful for compile testing code changes to the driver and Counter subsystem.

---
 drivers/counter/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/counter/Kconfig +1 -1
index 3dcdb681c4e4..5edd155f1911 100644
@@ -14,7 +14,7 @@ if COUNTER
 
 config 104_QUAD_8
 	tristate "ACCES 104-QUAD-8 driver"
-	depends on PC104 && X86
+	depends on (PC104 && X86) || COMPILE_TEST
 	select ISA_BUS_API
 	help
 	  Say yes here to build support for the ACCES 104-QUAD-8 quadrature
Signature · 1 line
2.35.1
Acked-by on v1 1/6
#2 lore raw

Re: [RESEND PATCH 1/6] counter: 104-quad-8: Add COMPILE_TEST depends

Quoted 28 lines · William Breathitt Gray

104_QUAD_8 depends on X86, but compiles fine on ARCH=arm. This patch adds support for COMPILE_TEST which is useful for compile testing code changes to the driver and Counter subsystem.

---
 drivers/counter/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/counter/Kconfig +1 -2
index 3dcdb681c4e4..5edd155f1911 100644
@@ -14,7 +14,7 @@ if COUNTER
 
 config 104_QUAD_8
        tristate "ACCES 104-QUAD-8 driver"
-       depends on PC104 && X86
+       depends on (PC104 && X86) || COMPILE_TEST
        select ISA_BUS_API
        help
          Say yes here to build support for the ACCES 104-QUAD-8 quadrature
--
Quoted 2 lines

2.35.1

Thanks

#3 lore raw

PATCH RESEND 2/6 counter: Set counter device name

In reply to William Breathitt Gray

Naming the counter device provides a convenient way to identify it in devres_log events and similar situations. This patch names the counter device by combining the prefix "counter" with the counter device's unique ID.

---
 drivers/counter/counter-core.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/counter/counter-core.c +11 -1
index 869894b74741..938651f9e9e0 100644
@@ -22,6 +22,8 @@
 #include "counter-chrdev.h"
 #include "counter-sysfs.h"
 
+#define COUNTER_NAME	"counter"
+
 /* Provides a unique ID for each counter device */
 static DEFINE_IDA(counter_ida);
 
@@ -113,8 +115,15 @@ struct counter_device *counter_alloc(size_t sizeof_priv)
 
 	device_initialize(dev);
 
+	err = dev_set_name(dev, COUNTER_NAME "%d", dev->id);
+	if (err)
+		goto err_dev_set_name;
+
 	return counter;
 
+err_dev_set_name:
+
+	counter_chrdev_remove(counter);
 err_chrdev_add:
 
 	ida_free(&counter_ida, dev->id);
@@ -247,7 +256,8 @@ static int __init counter_init(void)
 	if (err < 0)
 		return err;
 
-	err = alloc_chrdev_region(&counter_devt, 0, COUNTER_DEV_MAX, "counter");
+	err = alloc_chrdev_region(&counter_devt, 0, COUNTER_DEV_MAX,
+				  COUNTER_NAME);
 	if (err < 0)
 		goto err_unregister_bus;
 
Signature · 1 line
2.35.1
#4 lore raw

PATCH RESEND 3/6 counter: add new COUNTER_EVENT_CHANGE_OF_STATE

In reply to William Breathitt Gray

From: Oleksij Rempel <[email protected]>

Add new counter event to notify user space about every new counter pulse.

---
 include/uapi/linux/counter.h | 2 ++
 1 file changed, 2 insertions(+)
include/uapi/linux/counter.h +2 -0
index d0aa95aeff7b..96c5ffd368ad 100644
@@ -61,6 +61,8 @@ enum counter_event_type {
 	COUNTER_EVENT_THRESHOLD,
 	/* Index signal detected */
 	COUNTER_EVENT_INDEX,
+	/* State of counter is changed */
+	COUNTER_EVENT_CHANGE_OF_STATE,
 };
 
 /**
Signature · 1 line
2.35.1
#5 lore raw

PATCH RESEND 4/6 counter: interrupt-cnt: add counter_push_event()

In reply to William Breathitt Gray

From: Oleksij Rempel <[email protected]>

Add counter_push_event() to notify user space about new pulses

---
 drivers/counter/interrupt-cnt.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/counter/interrupt-cnt.c +5 -2
index 9e99702470c2..3b13f56bbb11 100644
@@ -26,10 +26,13 @@ struct interrupt_cnt_priv {
 
 static irqreturn_t interrupt_cnt_isr(int irq, void *dev_id)
 {
-	struct interrupt_cnt_priv *priv = dev_id;
+	struct counter_device *counter = dev_id;
+	struct interrupt_cnt_priv *priv = counter_priv(counter);
 
 	atomic_inc(&priv->count);
 
+	counter_push_event(counter, COUNTER_EVENT_CHANGE_OF_STATE, 0);
+
 	return IRQ_HANDLED;
 }
 
@@ -209,7 +212,7 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
 	irq_set_status_flags(priv->irq, IRQ_NOAUTOEN);
 	ret = devm_request_irq(dev, priv->irq, interrupt_cnt_isr,
 			       IRQF_TRIGGER_RISING | IRQF_NO_THREAD,
-			       dev_name(dev), priv);
+			       dev_name(dev), counter);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.35.1
#6 lore raw

PATCH RESEND 5/6 MAINTAINERS: Add Counter subsystem git tree

In reply to William Breathitt Gray

The Counter subsystem tree is now separate from the IIO tree.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 1ba1e4af2cbc..f4875a9faa2d 100644
@@ -4951,6 +4951,7 @@ COUNTER SUBSYSTEM
 M:	William Breathitt Gray <[email protected]>
 L:	[email protected]
 S:	Maintained
+T:	git [email protected]:vilhelmgray/counter.git
 F:	Documentation/ABI/testing/sysfs-bus-counter
 F:	Documentation/driver-api/generic-counter.rst
 F:	drivers/counter/
Signature · 1 line
2.35.1
#7 lore raw

PATCH RESEND 6/6 counter: add defaults to switch-statements

In reply to William Breathitt Gray

From: Tom Rix <[email protected]>

Clang static analysis reports this representative problem counter-chrdev.c:482:3: warning: Undefined or garbage value
returned to caller
return ret;
^~~~~~~~~~

counter_get_data() has a multilevel switches, some without defaults, so ret is sometimes not set.
Add returning -EINVAL similar to other defaults.

---
 drivers/counter/counter-chrdev.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/counter/counter-chrdev.c +4 -0
index b7c62f957a6a..69d340be9c93 100644
@@ -477,6 +477,8 @@ static int counter_get_data(struct counter_device *const counter,
 		case COUNTER_SCOPE_COUNT:
 			ret = comp->count_u8_read(counter, parent, &value_u8);
 			break;
+		default:
+			return -EINVAL;
 		}
 		*value = value_u8;
 		return ret;
@@ -496,6 +498,8 @@ static int counter_get_data(struct counter_device *const counter,
 		case COUNTER_SCOPE_COUNT:
 			ret = comp->count_u32_read(counter, parent, &value_u32);
 			break;
+		default:
+			return -EINVAL;
 		}
 		*value = value_u32;
 		return ret;
Signature · 1 line
2.35.1
Acked-by on v1 6/6
#8 lore raw

Re: [RESEND PATCH 6/6] counter: add defaults to switch-statements

Quoted 44 lines · William Breathitt Gray

From: Tom Rix <[email protected]>

Clang static analysis reports this representative problem counter-chrdev.c:482:3: warning: Undefined or garbage value
returned to caller
return ret;
^~~~~~~~~~

counter_get_data() has a multilevel switches, some without defaults, so ret is sometimes not set.
Add returning -EINVAL similar to other defaults.

---
 drivers/counter/counter-chrdev.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/counter/counter-chrdev.c +4 -1
index b7c62f957a6a..69d340be9c93 100644
@@ -477,6 +477,8 @@ static int counter_get_data(struct counter_device *const counter,
                case COUNTER_SCOPE_COUNT:
                        ret = comp->count_u8_read(counter, parent, &value_u8);
                        break;
+               default:
+                       return -EINVAL;
                }
                *value = value_u8;
                return ret;
@@ -496,6 +498,8 @@ static int counter_get_data(struct counter_device *const counter,
                case COUNTER_SCOPE_COUNT:
                        ret = comp->count_u32_read(counter, parent, &value_u32);
                        break;
+               default:
+                       return -EINVAL;
                }
                *value = value_u32;
                return ret;
--
Quoted 2 lines

2.35.1

Thanks