diff mbox series

iio: kfifo: mask flags without zero-check in devm_iio_kfifo_buffer_setup()

Message ID 20210306162834.7339-1-ardeleanalex@gmail.com (mailing list archive)
State New, archived
Headers show
Series iio: kfifo: mask flags without zero-check in devm_iio_kfifo_buffer_setup() | expand

Commit Message

Alexandru Ardelean March 6, 2021, 4:28 p.m. UTC
As pointed by Lars, this doesn't require a zero-check. Also, while looking
at this a little closer at it (again), the masking can be done later, as
there is a zero-check for 'mode_flags' anyway, which returns -EINVAL. And
we only need the 'mode_flags' later in the logic.

This change is more of a tweak.

Fixes: ae9886d6aa29 ("iio: kfifo: add devm_iio_kfifo_buffer_setup() helper")
Cc: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
---

Apologies for the late-ness of this.
I don't know if this makes sense to squash in the original, or to have
as a fix commit.
It is a bit messy now that the original is committed into the tree,
and now we're fixing/tweaking it.

 drivers/iio/buffer/kfifo_buf.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Jonathan Cameron March 7, 2021, 12:29 p.m. UTC | #1
On Sat,  6 Mar 2021 18:28:34 +0200
Alexandru Ardelean <ardeleanalex@gmail.com> wrote:

> As pointed by Lars, this doesn't require a zero-check. Also, while looking
> at this a little closer at it (again), the masking can be done later, as
> there is a zero-check for 'mode_flags' anyway, which returns -EINVAL. And
> we only need the 'mode_flags' later in the logic.
> 
> This change is more of a tweak.
> 
> Fixes: ae9886d6aa29 ("iio: kfifo: add devm_iio_kfifo_buffer_setup() helper")
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>

I've applied this as a separate patch.  Thanks,

Jonathan

> ---
> 
> Apologies for the late-ness of this.
> I don't know if this makes sense to squash in the original, or to have
> as a fix commit.
> It is a bit messy now that the original is committed into the tree,
> and now we're fixing/tweaking it.
> 
>  drivers/iio/buffer/kfifo_buf.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c
> index e8a434f84778..8e3a1a9e495c 100644
> --- a/drivers/iio/buffer/kfifo_buf.c
> +++ b/drivers/iio/buffer/kfifo_buf.c
> @@ -275,9 +275,6 @@ int devm_iio_kfifo_buffer_setup(struct device *dev,
>  {
>  	struct iio_buffer *buffer;
>  
> -	if (mode_flags)
> -		mode_flags &= kfifo_access_funcs.modes;
> -
>  	if (!mode_flags)
>  		return -EINVAL;
>  
> @@ -285,6 +282,8 @@ int devm_iio_kfifo_buffer_setup(struct device *dev,
>  	if (!buffer)
>  		return -ENOMEM;
>  
> +	mode_flags &= kfifo_access_funcs.modes;
> +
>  	indio_dev->modes |= mode_flags;
>  	indio_dev->setup_ops = setup_ops;
>
diff mbox series

Patch

diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c
index e8a434f84778..8e3a1a9e495c 100644
--- a/drivers/iio/buffer/kfifo_buf.c
+++ b/drivers/iio/buffer/kfifo_buf.c
@@ -275,9 +275,6 @@  int devm_iio_kfifo_buffer_setup(struct device *dev,
 {
 	struct iio_buffer *buffer;
 
-	if (mode_flags)
-		mode_flags &= kfifo_access_funcs.modes;
-
 	if (!mode_flags)
 		return -EINVAL;
 
@@ -285,6 +282,8 @@  int devm_iio_kfifo_buffer_setup(struct device *dev,
 	if (!buffer)
 		return -ENOMEM;
 
+	mode_flags &= kfifo_access_funcs.modes;
+
 	indio_dev->modes |= mode_flags;
 	indio_dev->setup_ops = setup_ops;