[6/6] Staging: iio: resolver: Prefer using the BIT macro
diff mbox series

Message ID 1441858434-2846-6-git-send-email-shraddha.6596@gmail.com
State New, archived
Headers show
Series
  • [1/6] Staging: iio: addac: adt7316.c : Prefer using BIT macro
Related show

Commit Message

Shraddha Barke Sept. 10, 2015, 4:13 a.m. UTC
This patch replaces bit shifting on 1 with the BIT(x) macro
as it's extensively used by other function in this driver.

This was done with coccinelle:
@@ int g; @@

-(1 << g)
+BIT(g)

Signed-off-by: Shraddha Barke <shraddha.6596@gmail.com>
---
 drivers/staging/iio/resolver/ad2s1210.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Joe Perches Sept. 10, 2015, 4:24 a.m. UTC | #1
On Thu, 2015-09-10 at 09:43 +0530, Shraddha Barke wrote:
> This patch replaces bit shifting on 1 with the BIT(x) macro
> as it's extensively used by other function in this driver.
[]
> diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c
[]
> @@ -149,7 +149,7 @@ int ad2s1210_update_frequency_control_word(struct ad2s1210_state *st)
>  	int ret;
>  	unsigned char fcw;
>  
> -	fcw = (unsigned char)(st->fexcit * (1 << 15) / st->fclkin);
> +	fcw = (unsigned char)(st->fexcit * BIT(15) / st->fclkin);

Multiplying by a bit isn't very obvious.
Maybe just shift it.

	fcw = (unsigned char)((st->fexcit << 15) / st->fclkin);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Julia Lawall Sept. 10, 2015, 8:05 a.m. UTC | #2
On Wed, 9 Sep 2015, Joe Perches wrote:

> On Thu, 2015-09-10 at 09:43 +0530, Shraddha Barke wrote:
> > This patch replaces bit shifting on 1 with the BIT(x) macro
> > as it's extensively used by other function in this driver.
> []
> > diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c
> []
> > @@ -149,7 +149,7 @@ int ad2s1210_update_frequency_control_word(struct ad2s1210_state *st)
> >  	int ret;
> >  	unsigned char fcw;
> >
> > -	fcw = (unsigned char)(st->fexcit * (1 << 15) / st->fclkin);
> > +	fcw = (unsigned char)(st->fexcit * BIT(15) / st->fclkin);
>
> Multiplying by a bit isn't very obvious.
> Maybe just shift it.
>
> 	fcw = (unsigned char)((st->fexcit << 15) / st->fclkin);

That looks nicer.  Shraddha maybe you can find this issue elsewhere.

julia
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Patch
diff mbox series

diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c
index 7bc3e4a..1cf7134 100644
--- a/drivers/staging/iio/resolver/ad2s1210.c
+++ b/drivers/staging/iio/resolver/ad2s1210.c
@@ -149,7 +149,7 @@  int ad2s1210_update_frequency_control_word(struct ad2s1210_state *st)
 	int ret;
 	unsigned char fcw;
 
-	fcw = (unsigned char)(st->fexcit * (1 << 15) / st->fclkin);
+	fcw = (unsigned char)(st->fexcit * BIT(15) / st->fclkin);
 	if (fcw < AD2S1210_MIN_FCW || fcw > AD2S1210_MAX_FCW) {
 		dev_err(&st->sdev->dev, "ad2s1210: FCW out of range\n");
 		return -ERANGE;