2017-10-08 19:30:31

by Christos Gkekas

[permalink] [raw]
Subject: [PATCH] ath10k: spectral: Simplify error checking

Variable val is unsigned so checking whether it is less than zero is
redundant.

Signed-off-by: Christos Gkekas <[email protected]>
---
drivers/net/wireless/ath/ath10k/spectral.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/net/wireless/ath/ath10k/spectral.c b/drivers/net/wireless/ath/ath10k/spectral.c
index dd9cc09..1867937 100644
--- a/drivers/net/wireless/ath/ath10k/spectral.c
+++ b/drivers/net/wireless/ath/ath10k/spectral.c
@@ -403,10 +403,7 @@ static ssize_t write_file_spectral_count(struct file *file,
return -EFAULT;

buf[len] = '\0';
- if (kstrtoul(buf, 0, &val))
- return -EINVAL;
-
- if (val < 0 || val > 255)
+ if (kstrtoul(buf, 0, &val) || val > 255)
return -EINVAL;

mutex_lock(&ar->conf_mutex);
--
2.7.4


2017-10-14 08:13:00

by Christos Gkekas

[permalink] [raw]
Subject: Re: [PATCH] ath10k: spectral: Simplify error checking

On 13/10/17 12:28:50 +0000, Kalle Valo wrote:
> Christos Gkekas <[email protected]> writes:
>
> > Variable val is unsigned so checking whether it is less than zero is
> > redundant.
> >
> > Signed-off-by: Christos Gkekas <[email protected]>
> > ---
> > drivers/net/wireless/ath/ath10k/spectral.c | 5 +----
> > 1 file changed, 1 insertion(+), 4 deletions(-)
> >
> > diff --git a/drivers/net/wireless/ath/ath10k/spectral.c b/drivers/net/wireless/ath/ath10k/spectral.c
> > index dd9cc09..1867937 100644
> > --- a/drivers/net/wireless/ath/ath10k/spectral.c
> > +++ b/drivers/net/wireless/ath/ath10k/spectral.c
> > @@ -403,10 +403,7 @@ static ssize_t write_file_spectral_count(struct file *file,
> > return -EFAULT;
> >
> > buf[len] = '\0';
> > - if (kstrtoul(buf, 0, &val))
> > - return -EINVAL;
> > -
> > - if (val < 0 || val > 255)
> > + if (kstrtoul(buf, 0, &val) || val > 255)
> > return -EINVAL;
>
> Removing the check for negative is correct but I don't think you are
> simplifying anything, on the contrary it's harder to read. Please keep
> the two if statements separate.
>
> --
> Kalle Valo

You are right, will make the change and send a new patch.
Thanks for your time.

Christos Gkekas

2017-10-13 12:28:55

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH] ath10k: spectral: Simplify error checking

Christos Gkekas <[email protected]> writes:

> Variable val is unsigned so checking whether it is less than zero is
> redundant.
>
> Signed-off-by: Christos Gkekas <[email protected]>
> ---
> drivers/net/wireless/ath/ath10k/spectral.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/ath10k/spectral.c b/drivers/net/wir=
eless/ath/ath10k/spectral.c
> index dd9cc09..1867937 100644
> --- a/drivers/net/wireless/ath/ath10k/spectral.c
> +++ b/drivers/net/wireless/ath/ath10k/spectral.c
> @@ -403,10 +403,7 @@ static ssize_t write_file_spectral_count(struct file=
*file,
> return -EFAULT;
> =20
> buf[len] =3D '\0';
> - if (kstrtoul(buf, 0, &val))
> - return -EINVAL;
> -
> - if (val < 0 || val > 255)
> + if (kstrtoul(buf, 0, &val) || val > 255)
> return -EINVAL;

Removing the check for negative is correct but I don't think you are
simplifying anything, on the contrary it's harder to read. Please keep
the two if statements separate.

--=20
Kalle Valo=