2018-07-23 09:22:24

by Nicholas Mc Guire

[permalink] [raw]
Subject: [PATCH] iio: ad_sigma_delta: use unsigned long for timeout

wait_for_completion_timeout returns unsigned long not int so an appropriate
variable is declared and the assignment and check fixed up.

Signed-off-by: Nicholas Mc Guire <[email protected]>
---

found by experimental coccinelle script

As the timeout returned is always << INT_MAX there is no side-effect with the
type conversion here, never the less proper types should be used.

Patch was compile tested with: x86_64_defconfig + CONFIG_SPI=y, CONFIG_IIO=y,
CONFIG_AD7793=y (implies CONFIG_AD_SIGMA_DELTA=y)

Patch is against 4.18-rc5 (localversion-next is next-20180720)

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

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index cf1b048..fc95107 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -209,6 +209,7 @@ static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
unsigned int mode, unsigned int channel)
{
int ret;
+ unsigned long timeout;

ret = ad_sigma_delta_set_channel(sigma_delta, channel);
if (ret)
@@ -224,8 +225,8 @@ static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,

sigma_delta->irq_dis = false;
enable_irq(sigma_delta->spi->irq);
- ret = wait_for_completion_timeout(&sigma_delta->completion, 2*HZ);
- if (ret == 0) {
+ timeout = wait_for_completion_timeout(&sigma_delta->completion, 2 * HZ);
+ if (timeout == 0) {
sigma_delta->irq_dis = true;
disable_irq_nosync(sigma_delta->spi->irq);
ret = -EIO;
--
2.1.4



2018-07-26 11:46:18

by Alexandru Ardelean

[permalink] [raw]
Subject: Re: [PATCH] iio: ad_sigma_delta: use unsigned long for timeout

On Mon, 2018-07-23 at 11:18 +0200, Nicholas Mc Guire wrote:
> wait_for_completion_timeout returns unsigned long not int so an
> appropriate
> variable is declared and the assignment and check fixed up.
>

Patch looks good.

Thanks for this

Alex

> Signed-off-by: Nicholas Mc Guire <[email protected]>
> ---
>
> found by experimental coccinelle script
>
> As the timeout returned is always << INT_MAX there is no side-effect with
> the
> type conversion here, never the less proper types should be used.
>
> Patch was compile tested with: x86_64_defconfig + CONFIG_SPI=y,
> CONFIG_IIO=y,
> CONFIG_AD7793=y (implies CONFIG_AD_SIGMA_DELTA=y)
>
> Patch is against 4.18-rc5 (localversion-next is next-20180720)
>
> drivers/iio/adc/ad_sigma_delta.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/ad_sigma_delta.c
> b/drivers/iio/adc/ad_sigma_delta.c
> index cf1b048..fc95107 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -209,6 +209,7 @@ static int ad_sd_calibrate(struct ad_sigma_delta
> *sigma_delta,
> unsigned int mode, unsigned int channel)
> {
> int ret;
> + unsigned long timeout;
>
> ret = ad_sigma_delta_set_channel(sigma_delta, channel);
> if (ret)
> @@ -224,8 +225,8 @@ static int ad_sd_calibrate(struct ad_sigma_delta
> *sigma_delta,
>
> sigma_delta->irq_dis = false;
> enable_irq(sigma_delta->spi->irq);
> - ret = wait_for_completion_timeout(&sigma_delta->completion,
> 2*HZ);
> - if (ret == 0) {
> + timeout = wait_for_completion_timeout(&sigma_delta->completion,
> 2 * HZ);
> + if (timeout == 0) {
> sigma_delta->irq_dis = true;
> disable_irq_nosync(sigma_delta->spi->irq);
> ret = -EIO;

2018-07-27 06:41:42

by Alexandru Ardelean

[permalink] [raw]
Subject: Re: [PATCH] iio: ad_sigma_delta: use unsigned long for timeout

On Thu, 2018-07-26 at 11:44 +0000, Ardelean, Alexandru wrote:
> On Mon, 2018-07-23 at 11:18 +0200, Nicholas Mc Guire wrote:
> > wait_for_completion_timeout returns unsigned long not int so an
> > appropriate
> > variable is declared and the assignment and check fixed up.
> >
>
> Patch looks good.
>
> Thanks for this

[ I forgot to add this ]

Reviewed-by: Alexandru Ardelean <[email protected]>


>
> Alex
>
> > Signed-off-by: Nicholas Mc Guire <[email protected]>
> > ---
> >
> > found by experimental coccinelle script
> >
> > As the timeout returned is always << INT_MAX there is no side-effect
> > with
> > the
> > type conversion here, never the less proper types should be used.
> >
> > Patch was compile tested with: x86_64_defconfig + CONFIG_SPI=y,
> > CONFIG_IIO=y,
> > CONFIG_AD7793=y (implies CONFIG_AD_SIGMA_DELTA=y)
> >
> > Patch is against 4.18-rc5 (localversion-next is next-20180720)
> >
> > drivers/iio/adc/ad_sigma_delta.c | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/iio/adc/ad_sigma_delta.c
> > b/drivers/iio/adc/ad_sigma_delta.c
> > index cf1b048..fc95107 100644
> > --- a/drivers/iio/adc/ad_sigma_delta.c
> > +++ b/drivers/iio/adc/ad_sigma_delta.c
> > @@ -209,6 +209,7 @@ static int ad_sd_calibrate(struct ad_sigma_delta
> > *sigma_delta,
> > unsigned int mode, unsigned int channel)
> > {
> > int ret;
> > + unsigned long timeout;
> >
> > ret = ad_sigma_delta_set_channel(sigma_delta, channel);
> > if (ret)
> > @@ -224,8 +225,8 @@ static int ad_sd_calibrate(struct ad_sigma_delta
> > *sigma_delta,
> >
> > sigma_delta->irq_dis = false;
> > enable_irq(sigma_delta->spi->irq);
> > - ret = wait_for_completion_timeout(&sigma_delta->completion,
> > 2*HZ);
> > - if (ret == 0) {
> > + timeout = wait_for_completion_timeout(&sigma_delta-
> > >completion,
> > 2 * HZ);
> > + if (timeout == 0) {
> > sigma_delta->irq_dis = true;
> > disable_irq_nosync(sigma_delta->spi->irq);
> > ret =
> > -EIO;N�����r��y���b�X��ǧv�^�)޺{.n�+����{��*"��^n�r���z���h����&���G��
> > �h�(�階�ݢj"���m�����z�ޖ���f���h���~�m�