2020-11-14 23:31:11

by William Breathitt Gray

[permalink] [raw]
Subject: [PATCH v2] counter: microchip-tcb-capture: Fix CMR value check

The ATMEL_TC_ETRGEDG_* defines are not masks but rather possible values
for CMR. This patch fixes the action_get() callback to properly check
for these values rather than mask them.

Fixes: 106b104137fd ("counter: Add microchip TCB capture counter")
Cc: Kamel Bouhara <[email protected]>
Acked-by: Alexandre Belloni <[email protected]>
Signed-off-by: William Breathitt Gray <[email protected]>
---
drivers/counter/microchip-tcb-capture.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
index 039c54a78aa5..710acc0a3704 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -183,16 +183,20 @@ static int mchp_tc_count_action_get(struct counter_device *counter,

regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);

- *action = MCHP_TC_SYNAPSE_ACTION_NONE;
-
- if (cmr & ATMEL_TC_ETRGEDG_NONE)
+ switch (cmr & ATMEL_TC_ETRGEDG) {
+ default:
*action = MCHP_TC_SYNAPSE_ACTION_NONE;
- else if (cmr & ATMEL_TC_ETRGEDG_RISING)
+ break;
+ case ATMEL_TC_ETRGEDG_RISING:
*action = MCHP_TC_SYNAPSE_ACTION_RISING_EDGE;
- else if (cmr & ATMEL_TC_ETRGEDG_FALLING)
+ break;
+ case ATMEL_TC_ETRGEDG_FALLING:
*action = MCHP_TC_SYNAPSE_ACTION_FALLING_EDGE;
- else if (cmr & ATMEL_TC_ETRGEDG_BOTH)
+ break;
+ case ATMEL_TC_ETRGEDG_BOTH:
*action = MCHP_TC_SYNAPSE_ACTION_BOTH_EDGE;
+ break;
+ }

return 0;
}
--
2.29.2


2020-11-15 17:00:57

by Kamel BOUHARA

[permalink] [raw]
Subject: Re: [PATCH v2] counter: microchip-tcb-capture: Fix CMR value check

On Sat, Nov 14, 2020 at 06:28:05PM -0500, William Breathitt Gray wrote:
> The ATMEL_TC_ETRGEDG_* defines are not masks but rather possible values
> for CMR. This patch fixes the action_get() callback to properly check
> for these values rather than mask them.
>
> Fixes: 106b104137fd ("counter: Add microchip TCB capture counter")
> Cc: Kamel Bouhara <[email protected]>
> Acked-by: Alexandre Belloni <[email protected]>
> Signed-off-by: William Breathitt Gray <[email protected]>
> ---

Acked-by: Kamel Bouhara <[email protected]>

> drivers/counter/microchip-tcb-capture.c | 16 ++++++++++------
> 1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index 039c54a78aa5..710acc0a3704 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -183,16 +183,20 @@ static int mchp_tc_count_action_get(struct counter_device *counter,
>
> regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
>
> - *action = MCHP_TC_SYNAPSE_ACTION_NONE;
> -
> - if (cmr & ATMEL_TC_ETRGEDG_NONE)
> + switch (cmr & ATMEL_TC_ETRGEDG) {
> + default:
> *action = MCHP_TC_SYNAPSE_ACTION_NONE;
> - else if (cmr & ATMEL_TC_ETRGEDG_RISING)
> + break;
> + case ATMEL_TC_ETRGEDG_RISING:
> *action = MCHP_TC_SYNAPSE_ACTION_RISING_EDGE;
> - else if (cmr & ATMEL_TC_ETRGEDG_FALLING)
> + break;
> + case ATMEL_TC_ETRGEDG_FALLING:
> *action = MCHP_TC_SYNAPSE_ACTION_FALLING_EDGE;
> - else if (cmr & ATMEL_TC_ETRGEDG_BOTH)
> + break;
> + case ATMEL_TC_ETRGEDG_BOTH:
> *action = MCHP_TC_SYNAPSE_ACTION_BOTH_EDGE;
> + break;
> + }
>
> return 0;
> }
> --
> 2.29.2
>

--
Kamel Bouhara, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

2020-11-21 16:34:24

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2] counter: microchip-tcb-capture: Fix CMR value check

On Sun, 15 Nov 2020 16:26:17 +0100
Kamel Bouhara <[email protected]> wrote:

> On Sat, Nov 14, 2020 at 06:28:05PM -0500, William Breathitt Gray wrote:
> > The ATMEL_TC_ETRGEDG_* defines are not masks but rather possible values
> > for CMR. This patch fixes the action_get() callback to properly check
> > for these values rather than mask them.
> >
> > Fixes: 106b104137fd ("counter: Add microchip TCB capture counter")
> > Cc: Kamel Bouhara <[email protected]>
> > Acked-by: Alexandre Belloni <[email protected]>
> > Signed-off-by: William Breathitt Gray <[email protected]>
> > ---
>
> Acked-by: Kamel Bouhara <[email protected]>
>
Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

> > drivers/counter/microchip-tcb-capture.c | 16 ++++++++++------
> > 1 file changed, 10 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> > index 039c54a78aa5..710acc0a3704 100644
> > --- a/drivers/counter/microchip-tcb-capture.c
> > +++ b/drivers/counter/microchip-tcb-capture.c
> > @@ -183,16 +183,20 @@ static int mchp_tc_count_action_get(struct counter_device *counter,
> >
> > regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
> >
> > - *action = MCHP_TC_SYNAPSE_ACTION_NONE;
> > -
> > - if (cmr & ATMEL_TC_ETRGEDG_NONE)
> > + switch (cmr & ATMEL_TC_ETRGEDG) {
> > + default:
> > *action = MCHP_TC_SYNAPSE_ACTION_NONE;
> > - else if (cmr & ATMEL_TC_ETRGEDG_RISING)
> > + break;
> > + case ATMEL_TC_ETRGEDG_RISING:
> > *action = MCHP_TC_SYNAPSE_ACTION_RISING_EDGE;
> > - else if (cmr & ATMEL_TC_ETRGEDG_FALLING)
> > + break;
> > + case ATMEL_TC_ETRGEDG_FALLING:
> > *action = MCHP_TC_SYNAPSE_ACTION_FALLING_EDGE;
> > - else if (cmr & ATMEL_TC_ETRGEDG_BOTH)
> > + break;
> > + case ATMEL_TC_ETRGEDG_BOTH:
> > *action = MCHP_TC_SYNAPSE_ACTION_BOTH_EDGE;
> > + break;
> > + }
> >
> > return 0;
> > }
> > --
> > 2.29.2
> >
>
> --
> Kamel Bouhara, Bootlin
> Embedded Linux and kernel engineering
> https://bootlin.com