2015-02-08 22:44:27

by Luis de Bethencourt

[permalink] [raw]
Subject: [PATCH] rtl2832: remove compiler warning

Cleaning the following compiler warning:
rtl2832.c:703:12: warning: 'tmp' may be used uninitialized in this function

Even though it could never happen since if rtl2832_rd_demod_reg () doesn't set
tmp, this line would never run because we go to err. It is still nice to avoid
compiler warnings.

Signed-off-by: Luis de Bethencourt <[email protected]>
---
drivers/media/dvb-frontends/rtl2832.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
index 5d2d8f4..ad36d1c 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -685,7 +685,7 @@ static int rtl2832_read_status(struct dvb_frontend *fe, fe_status_t *status)
struct rtl2832_dev *dev = fe->demodulator_priv;
struct i2c_client *client = dev->client;
int ret;
- u32 tmp;
+ u32 tmp = 0;

dev_dbg(&client->dev, "\n");

--
2.1.0


2015-02-08 22:47:03

by Luis de Bethencourt

[permalink] [raw]
Subject: Re: [PATCH] rtl2832: remove compiler warning

On Sun, Feb 08, 2015 at 10:44:22PM +0000, Luis de Bethencourt wrote:
> Cleaning the following compiler warning:
> rtl2832.c:703:12: warning: 'tmp' may be used uninitialized in this function
>
> Even though it could never happen since if rtl2832_rd_demod_reg () doesn't set
> tmp, this line would never run because we go to err. It is still nice to avoid
> compiler warnings.
>
> Signed-off-by: Luis de Bethencourt <[email protected]>
> ---
> drivers/media/dvb-frontends/rtl2832.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
> index 5d2d8f4..ad36d1c 100644
> --- a/drivers/media/dvb-frontends/rtl2832.c
> +++ b/drivers/media/dvb-frontends/rtl2832.c
> @@ -685,7 +685,7 @@ static int rtl2832_read_status(struct dvb_frontend *fe, fe_status_t *status)
> struct rtl2832_dev *dev = fe->demodulator_priv;
> struct i2c_client *client = dev->client;
> int ret;
> - u32 tmp;
> + u32 tmp = 0;
>
> dev_dbg(&client->dev, "\n");
>
> --
> 2.1.0
>

Hello all :)

This warning can be seen in:
http://hverkuil.home.xs4all.nl/logs/Saturday.log

Thank you Hans for the daily build and logs.

Luis

2015-02-10 10:57:31

by Antti Palosaari

[permalink] [raw]
Subject: Re: [PATCH] rtl2832: remove compiler warning

On 02/09/2015 12:44 AM, Luis de Bethencourt wrote:
> Cleaning the following compiler warning:
> rtl2832.c:703:12: warning: 'tmp' may be used uninitialized in this function
>
> Even though it could never happen since if rtl2832_rd_demod_reg () doesn't set
> tmp, this line would never run because we go to err. It is still nice to avoid
> compiler warnings.
>
> Signed-off-by: Luis de Bethencourt <[email protected]>
> ---
> drivers/media/dvb-frontends/rtl2832.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
> index 5d2d8f4..ad36d1c 100644
> --- a/drivers/media/dvb-frontends/rtl2832.c
> +++ b/drivers/media/dvb-frontends/rtl2832.c
> @@ -685,7 +685,7 @@ static int rtl2832_read_status(struct dvb_frontend *fe, fe_status_t *status)
> struct rtl2832_dev *dev = fe->demodulator_priv;
> struct i2c_client *client = dev->client;
> int ret;
> - u32 tmp;
> + u32 tmp = 0;
>
> dev_dbg(&client->dev, "\n");

I looked the code and I cannot see how it could used as uninitialized.
Dunno how it could be fixed properly.

Also, I think idiom to say compiler that variable could be uninitialized
is to store its own value. But I am fine with zero initialization too.

u32 tmp = tmp;

regards
Antti

--
http://palosaari.fi/

2015-02-10 14:07:37

by Luis de Bethencourt

[permalink] [raw]
Subject: Re: [PATCH] rtl2832: remove compiler warning

On Tue, Feb 10, 2015 at 12:57:24PM +0200, Antti Palosaari wrote:
> On 02/09/2015 12:44 AM, Luis de Bethencourt wrote:
> >Cleaning the following compiler warning:
> >rtl2832.c:703:12: warning: 'tmp' may be used uninitialized in this function
> >
> >Even though it could never happen since if rtl2832_rd_demod_reg () doesn't set
> >tmp, this line would never run because we go to err. It is still nice to avoid
> >compiler warnings.
> >
> >Signed-off-by: Luis de Bethencourt <[email protected]>
> >---
> > drivers/media/dvb-frontends/rtl2832.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
> >index 5d2d8f4..ad36d1c 100644
> >--- a/drivers/media/dvb-frontends/rtl2832.c
> >+++ b/drivers/media/dvb-frontends/rtl2832.c
> >@@ -685,7 +685,7 @@ static int rtl2832_read_status(struct dvb_frontend *fe, fe_status_t *status)
> > struct rtl2832_dev *dev = fe->demodulator_priv;
> > struct i2c_client *client = dev->client;
> > int ret;
> >- u32 tmp;
> >+ u32 tmp = 0;
> >
> > dev_dbg(&client->dev, "\n");
>
> I looked the code and I cannot see how it could used as uninitialized. Dunno
> how it could be fixed properly.

Hi Antti,

I agree. If rtl2832_rd_demod_reg() in line 696 doesn't set tmp it is because
it has errored out. Which means rtl2832_read_status() itself will goto err
before the check for 'if (tmp == 11)' line that generates the warning.

I mentioned this in my commit message :)

>
> Also, I think idiom to say compiler that variable could be uninitialized is
> to store its own value. But I am fine with zero initialization too.
>
> u32 tmp = tmp;
>
> regards
> Antti
>
> --
> http://palosaari.fi/

If you prefer I use the 'u32 tmp = tmp;' I am happy to change my patch.
You say you are fine with zero initialization too, but I prefer offering
whatever you think is best.

Thanks for taking the time to look at this,
Luis

2015-02-10 23:35:59

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH] rtl2832: remove compiler warning

Em Tue, 10 Feb 2015 12:57:24 +0200
Antti Palosaari <[email protected]> escreveu:

> On 02/09/2015 12:44 AM, Luis de Bethencourt wrote:
> > Cleaning the following compiler warning:
> > rtl2832.c:703:12: warning: 'tmp' may be used uninitialized in this function
> >
> > Even though it could never happen since if rtl2832_rd_demod_reg () doesn't set
> > tmp, this line would never run because we go to err. It is still nice to avoid
> > compiler warnings.
> >
> > Signed-off-by: Luis de Bethencourt <[email protected]>
> > ---
> > drivers/media/dvb-frontends/rtl2832.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
> > index 5d2d8f4..ad36d1c 100644
> > --- a/drivers/media/dvb-frontends/rtl2832.c
> > +++ b/drivers/media/dvb-frontends/rtl2832.c
> > @@ -685,7 +685,7 @@ static int rtl2832_read_status(struct dvb_frontend *fe, fe_status_t *status)
> > struct rtl2832_dev *dev = fe->demodulator_priv;
> > struct i2c_client *client = dev->client;
> > int ret;
> > - u32 tmp;
> > + u32 tmp = 0;
> >
> > dev_dbg(&client->dev, "\n");
>
> I looked the code and I cannot see how it could used as uninitialized.
> Dunno how it could be fixed properly.
>
> Also, I think idiom to say compiler that variable could be uninitialized
> is to store its own value. But I am fine with zero initialization too.
>
> u32 tmp = tmp;

Actually, the right way is to declare it as:

u32 uninitialized_var(tmp)

The syntax to suppress compiler warnings depends on the compiler:

include/linux/compiler-clang.h:#define uninitialized_var(x) x = *(&(x))
include/linux/compiler-gcc.h:#define uninitialized_var(x) x = x

Also, using uninitialized_var() better documents it.

Regards,
Mauro

2015-02-11 11:15:55

by Luis de Bethencourt

[permalink] [raw]
Subject: Re: [PATCH] rtl2832: remove compiler warning

On Tue, Feb 10, 2015 at 09:35:52PM -0200, Mauro Carvalho Chehab wrote:
> Em Tue, 10 Feb 2015 12:57:24 +0200
> Antti Palosaari <[email protected]> escreveu:
>
> > On 02/09/2015 12:44 AM, Luis de Bethencourt wrote:
> > > Cleaning the following compiler warning:
> > > rtl2832.c:703:12: warning: 'tmp' may be used uninitialized in this function
> > >
> > > Even though it could never happen since if rtl2832_rd_demod_reg () doesn't set
> > > tmp, this line would never run because we go to err. It is still nice to avoid
> > > compiler warnings.
> > >
> > > Signed-off-by: Luis de Bethencourt <[email protected]>
> > > ---
> > > drivers/media/dvb-frontends/rtl2832.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
> > > index 5d2d8f4..ad36d1c 100644
> > > --- a/drivers/media/dvb-frontends/rtl2832.c
> > > +++ b/drivers/media/dvb-frontends/rtl2832.c
> > > @@ -685,7 +685,7 @@ static int rtl2832_read_status(struct dvb_frontend *fe, fe_status_t *status)
> > > struct rtl2832_dev *dev = fe->demodulator_priv;
> > > struct i2c_client *client = dev->client;
> > > int ret;
> > > - u32 tmp;
> > > + u32 tmp = 0;
> > >
> > > dev_dbg(&client->dev, "\n");
> >
> > I looked the code and I cannot see how it could used as uninitialized.
> > Dunno how it could be fixed properly.
> >
> > Also, I think idiom to say compiler that variable could be uninitialized
> > is to store its own value. But I am fine with zero initialization too.
> >
> > u32 tmp = tmp;
>
> Actually, the right way is to declare it as:
>
> u32 uninitialized_var(tmp)
>
> The syntax to suppress compiler warnings depends on the compiler:
>
> include/linux/compiler-clang.h:#define uninitialized_var(x) x = *(&(x))
> include/linux/compiler-gcc.h:#define uninitialized_var(x) x = x
>
> Also, using uninitialized_var() better documents it.
>
> Regards,
> Mauro

Hi Mauro,

That is a way more elegant solution. Great!
I will check out that compiler-clang header file, it's interesting.

I just sent a revised patch using this :)

Thanks,
Luis