diff mbox series

[1/8] counter: chrdev: fix getting array extensions

Message ID 20230829134029.2402868-2-fabrice.gasnier@foss.st.com (mailing list archive)
State Handled Elsewhere
Headers show
Series counter: fix, improvements and stm32 timer events support | expand

Commit Message

Fabrice Gasnier Aug. 29, 2023, 1:40 p.m. UTC
When trying to watch a component array extension, and the array isn't the
first extended element, it fails as the type comparison is always done on
the 1st element. Fix it by indexing the 'ext' array.

Example on a dummy struct counter_comp:
static struct counter_comp dummy[] = {
	COUNTER_COMP_DIRECTION(..),
	...,
	COUNTER_COMP_ARRAY_CAPTURE(...),
};
static struct counter_count dummy_cnt = {
	...
	.ext = dummy,
	.num_ext = ARRAY_SIZE(dummy),
}

Currently, counter_get_ext() returns -EINVAL when trying to add a watch
event on one of the capture array element in such example.

Fixes: d2011be1e22f ("counter: Introduce the COUNTER_COMP_ARRAY component type")
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
---
 drivers/counter/counter-chrdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

William Breathitt Gray Sept. 4, 2023, 8:36 p.m. UTC | #1
On Tue, Aug 29, 2023 at 03:40:22PM +0200, Fabrice Gasnier wrote:
> When trying to watch a component array extension, and the array isn't the
> first extended element, it fails as the type comparison is always done on
> the 1st element. Fix it by indexing the 'ext' array.
> 
> Example on a dummy struct counter_comp:
> static struct counter_comp dummy[] = {
> 	COUNTER_COMP_DIRECTION(..),
> 	...,
> 	COUNTER_COMP_ARRAY_CAPTURE(...),
> };
> static struct counter_count dummy_cnt = {
> 	...
> 	.ext = dummy,
> 	.num_ext = ARRAY_SIZE(dummy),
> }
> 
> Currently, counter_get_ext() returns -EINVAL when trying to add a watch
> event on one of the capture array element in such example.
> 
> Fixes: d2011be1e22f ("counter: Introduce the COUNTER_COMP_ARRAY component type")
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

Applied to counter-fixes as commit 3170256d7bc1.

Thanks,

William Breathitt Gray
diff mbox series

Patch

diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c
index 80acdf62794a..afc94d0062b1 100644
--- a/drivers/counter/counter-chrdev.c
+++ b/drivers/counter/counter-chrdev.c
@@ -247,8 +247,8 @@  static int counter_get_ext(const struct counter_comp *const ext,
 		if (*id == component_id)
 			return 0;
 
-		if (ext->type == COUNTER_COMP_ARRAY) {
-			element = ext->priv;
+		if (ext[*ext_idx].type == COUNTER_COMP_ARRAY) {
+			element = ext[*ext_idx].priv;
 
 			if (component_id - *id < element->length)
 				return 0;