All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
To: <william.gray@linaro.org>, <lee@kernel.org>
Cc: <alexandre.torgue@foss.st.com>, <fabrice.gasnier@foss.st.com>,
	<linux-iio@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH 1/8] counter: chrdev: fix getting array extensions
Date: Tue, 29 Aug 2023 15:40:22 +0200	[thread overview]
Message-ID: <20230829134029.2402868-2-fabrice.gasnier@foss.st.com> (raw)
In-Reply-To: <20230829134029.2402868-1-fabrice.gasnier@foss.st.com>

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

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;
-- 
2.25.1


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

WARNING: multiple messages have this Message-ID (diff)
From: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
To: <william.gray@linaro.org>, <lee@kernel.org>
Cc: <alexandre.torgue@foss.st.com>, <fabrice.gasnier@foss.st.com>,
	<linux-iio@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH 1/8] counter: chrdev: fix getting array extensions
Date: Tue, 29 Aug 2023 15:40:22 +0200	[thread overview]
Message-ID: <20230829134029.2402868-2-fabrice.gasnier@foss.st.com> (raw)
In-Reply-To: <20230829134029.2402868-1-fabrice.gasnier@foss.st.com>

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

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;
-- 
2.25.1


  reply	other threads:[~2023-08-29 13:41 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-29 13:40 [PATCH 0/8] counter: fix, improvements and stm32 timer events support Fabrice Gasnier
2023-08-29 13:40 ` Fabrice Gasnier
2023-08-29 13:40 ` Fabrice Gasnier [this message]
2023-08-29 13:40   ` [PATCH 1/8] counter: chrdev: fix getting array extensions Fabrice Gasnier
2023-09-04 20:36   ` William Breathitt Gray
2023-09-04 20:36     ` William Breathitt Gray
2023-08-29 13:40 ` [PATCH 2/8] counter: chrdev: remove a typo in header file comment Fabrice Gasnier
2023-08-29 13:40   ` Fabrice Gasnier
2023-09-04 20:40   ` William Breathitt Gray
2023-09-04 20:40     ` William Breathitt Gray
2023-08-29 13:40 ` [PATCH 3/8] tools/counter: add a flexible watch events tool Fabrice Gasnier
2023-08-29 13:40   ` Fabrice Gasnier
2023-09-17 19:07   ` William Breathitt Gray
2023-09-17 19:07     ` William Breathitt Gray
2023-09-19 15:37     ` Fabrice Gasnier
2023-09-19 15:37       ` Fabrice Gasnier
2023-09-21 13:05       ` Fabrice Gasnier
2023-09-21 13:05         ` Fabrice Gasnier
2023-10-04  1:06       ` William Breathitt Gray
2023-10-04  1:06         ` William Breathitt Gray
2023-08-29 13:40 ` [PATCH 4/8] mfd: stm32-timers: add support for interrupts Fabrice Gasnier
2023-08-29 13:40   ` Fabrice Gasnier
2023-09-21 11:50   ` (subset) " Lee Jones
2023-09-21 11:50     ` Lee Jones
2023-08-29 13:40 ` [PATCH 5/8] counter: stm32-timer-cnt: rename quadrature signal Fabrice Gasnier
2023-08-29 13:40   ` Fabrice Gasnier
2023-09-04 19:34   ` William Breathitt Gray
2023-09-04 19:34     ` William Breathitt Gray
2023-08-29 13:40 ` [PATCH 6/8] counter: stm32-timer-cnt: introduce clock signal Fabrice Gasnier
2023-08-29 13:40   ` Fabrice Gasnier
2023-08-29 13:40 ` [PATCH 7/8] counter: stm32-timer-cnt: populate capture channels and check encoder Fabrice Gasnier
2023-08-29 13:40   ` Fabrice Gasnier
2023-08-29 13:40 ` [PATCH 8/8] counter: stm32-timer-cnt: add support for events Fabrice Gasnier
2023-08-29 13:40   ` Fabrice Gasnier
2023-08-29 18:00   ` kernel test robot
2023-08-29 18:00     ` kernel test robot
2023-08-30  7:40   ` kernel test robot
2023-08-30  7:40     ` kernel test robot
2023-09-21 11:51   ` Lee Jones
2023-09-21 11:51     ` Lee Jones
2023-09-04 19:31 ` [PATCH 0/8] counter: fix, improvements and stm32 timer events support William Breathitt Gray
2023-09-04 19:31   ` William Breathitt Gray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230829134029.2402868-2-fabrice.gasnier@foss.st.com \
    --to=fabrice.gasnier@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=william.gray@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.