diff mbox

[kernel,1/1] powerpc/Documentation/misc-devices/: Fix one compile error

Message ID 1487748144-13685-1-git-send-email-fgao@ikuai8.com
State Not Applicable
Headers show

Commit Message

高峰 Feb. 22, 2017, 7:22 a.m. UTC
From: Gao Feng <fgao@ikuai8.com>

When make allyesconfig, there is one compile error on my platform
"gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4".
The following is the output.

Documentation/misc-devices/mei/mei-amt-version.c: In function ‘main’:
Documentation/misc-devices/mei/mei-amt-version.c:103:5: warning: ‘acmd.fd’
is used uninitialized in this function [-Wuninitialized]
  if (cl->fd != -1)
     ^
Documentation/misc-devices/mei/mei-amt-version.c:443:21: note: ‘acmd.fd’
was declared here
  struct amt_host_if acmd;
                     ^
This commit fixes this compile error.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
 Documentation/misc-devices/mei/mei-amt-version.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Winkler, Tomas Feb. 22, 2017, 8:14 a.m. UTC | #1
On Wed, 2017-02-22 at 15:22 +0800, fgao@ikuai8.com wrote:
> From: Gao Feng <fgao@ikuai8.com>

> 

> When make allyesconfig, there is one compile error on my platform

> "gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4".

> The following is the output.

> 

> Documentation/misc-devices/mei/mei-amt-version.c: In function ‘main’:

> Documentation/misc-devices/mei/mei-amt-version.c:103:5: warning:

> ‘acmd.fd’

> is used uninitialized in this function [-Wuninitialized]

>   if (cl->fd != -1)

>      ^

> Documentation/misc-devices/mei/mei-amt-version.c:443:21: note:

> ‘acmd.fd’

> was declared here

>   struct amt_host_if acmd;

>                      ^

> This commit fixes this compile error.

> 

> Signed-off-by: Gao Feng <fgao@ikuai8.com>


This is false positive, as the variable is assined in mei_init(), in
any case, the code has moved under samples diretory in the current
kernel. Anything need to be fixed there first

Thanks 
Tomas

> ---

>  Documentation/misc-devices/mei/mei-amt-version.c | 1 +

>  1 file changed, 1 insertion(+)

> 

> diff --git a/Documentation/misc-devices/mei/mei-amt-version.c

> b/Documentation/misc-devices/mei/mei-amt-version.c

> index 49e4f77..ca035cb 100644

> --- a/Documentation/misc-devices/mei/mei-amt-version.c

> +++ b/Documentation/misc-devices/mei/mei-amt-version.c

> @@ -297,6 +297,7 @@ static bool amt_host_if_init(struct amt_host_if

> *acmd,

>  		      unsigned long send_timeout, bool verbose)

>  {

>  	acmd->send_timeout = (send_timeout) ? send_timeout : 20000;

> +	acmd->mei_cl.fd = -1;

>  	acmd->initialized = mei_init(&acmd->mei_cl, &MEI_IAMTHIF, 0,

> verbose);

>  	return acmd->initialized;

>  }
Feng Gao Feb. 22, 2017, 8:22 a.m. UTC | #2
On Wed, Feb 22, 2017 at 4:14 PM, Winkler, Tomas <tomas.winkler@intel.com> wrote:
> On Wed, 2017-02-22 at 15:22 +0800, fgao@ikuai8.com wrote:
>> From: Gao Feng <fgao@ikuai8.com>
>>
>> When make allyesconfig, there is one compile error on my platform
>> "gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4".
>> The following is the output.
>>
>> Documentation/misc-devices/mei/mei-amt-version.c: In function ‘main’:
>> Documentation/misc-devices/mei/mei-amt-version.c:103:5: warning:
>> ‘acmd.fd’
>> is used uninitialized in this function [-Wuninitialized]
>>   if (cl->fd != -1)
>>      ^
>> Documentation/misc-devices/mei/mei-amt-version.c:443:21: note:
>> ‘acmd.fd’
>> was declared here
>>   struct amt_host_if acmd;
>>                      ^
>> This commit fixes this compile error.
>>
>> Signed-off-by: Gao Feng <fgao@ikuai8.com>
>
> This is false positive, as the variable is assined in mei_init(), in
> any case, the code has moved under samples diretory in the current
> kernel. Anything need to be fixed there first
>
> Thanks
> Tomas

I think it is not false positive.
The function stack is main->amt_host_if_init->mei_init->mei_deinit.
There is one check "if (cl->fd != -1)".

Because this fd is not initialized to -1, so it may hit the condition,
and execute close.

So it should be fixed, although these codes would be moved to sample director.

Regards
Feng

>
>> ---
>>  Documentation/misc-devices/mei/mei-amt-version.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/Documentation/misc-devices/mei/mei-amt-version.c
>> b/Documentation/misc-devices/mei/mei-amt-version.c
>> index 49e4f77..ca035cb 100644
>> --- a/Documentation/misc-devices/mei/mei-amt-version.c
>> +++ b/Documentation/misc-devices/mei/mei-amt-version.c
>> @@ -297,6 +297,7 @@ static bool amt_host_if_init(struct amt_host_if
>> *acmd,
>>                     unsigned long send_timeout, bool verbose)
>>  {
>>       acmd->send_timeout = (send_timeout) ? send_timeout : 20000;
>> +     acmd->mei_cl.fd = -1;
>>       acmd->initialized = mei_init(&acmd->mei_cl, &MEI_IAMTHIF, 0,
>> verbose);
>>       return acmd->initialized;
>>  }
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Winkler, Tomas Feb. 22, 2017, 9:09 a.m. UTC | #3
> 

> On Wed, Feb 22, 2017 at 4:14 PM, Winkler, Tomas <tomas.winkler@intel.com>

> wrote:

> > On Wed, 2017-02-22 at 15:22 +0800, fgao@ikuai8.com wrote:

> >> From: Gao Feng <fgao@ikuai8.com>

> >>

> >> When make allyesconfig, there is one compile error on my platform

> >> "gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4".

> >> The following is the output.

> >>

> >> Documentation/misc-devices/mei/mei-amt-version.c: In function ‘main’:

> >> Documentation/misc-devices/mei/mei-amt-version.c:103:5: warning:

> >> ‘acmd.fd’

> >> is used uninitialized in this function [-Wuninitialized]

> >>   if (cl->fd != -1)

> >>      ^

> >> Documentation/misc-devices/mei/mei-amt-version.c:443:21: note:

> >> ‘acmd.fd’

> >> was declared here

> >>   struct amt_host_if acmd;

> >>                      ^

> >> This commit fixes this compile error.

> >>

> >> Signed-off-by: Gao Feng <fgao@ikuai8.com>

> >

> > This is false positive, as the variable is assined in mei_init(), in

> > any case, the code has moved under samples diretory in the current

> > kernel. Anything need to be fixed there first

> >

> > Thanks

> > Tomas

> 

> I think it is not false positive.

> The function stack is main->amt_host_if_init->mei_init->mei_deinit.

> There is one check "if (cl->fd != -1)".


Isn't  the first line in mei_init me->fd = open("/dev/mei", O_RDWR); ? 
I don't see mei_deinit called w/o mei_init called first. 
 
> Because this fd is not initialized to -1, so it may hit the condition, and execute

> close.

> 

> So it should be fixed, although these codes would be moved to sample

> director.


Please try with the master branch first in case  I'm still wrong.
Thanks
 
> Regards

> Feng

> 

> >

> >> ---

> >>  Documentation/misc-devices/mei/mei-amt-version.c | 1 +

> >>  1 file changed, 1 insertion(+)

> >>

> >> diff --git a/Documentation/misc-devices/mei/mei-amt-version.c

> >> b/Documentation/misc-devices/mei/mei-amt-version.c

> >> index 49e4f77..ca035cb 100644

> >> --- a/Documentation/misc-devices/mei/mei-amt-version.c

> >> +++ b/Documentation/misc-devices/mei/mei-amt-version.c

> >> @@ -297,6 +297,7 @@ static bool amt_host_if_init(struct amt_host_if

> >> *acmd,

> >>                     unsigned long send_timeout, bool verbose)  {

> >>       acmd->send_timeout = (send_timeout) ? send_timeout : 20000;

> >> +     acmd->mei_cl.fd = -1;

> >>       acmd->initialized = mei_init(&acmd->mei_cl, &MEI_IAMTHIF, 0,

> >> verbose);

> >>       return acmd->initialized;

> >>  }
Feng Gao Feb. 23, 2017, 3:37 a.m. UTC | #4
On Wed, Feb 22, 2017 at 5:09 PM, Winkler, Tomas <tomas.winkler@intel.com> wrote:
>
>>
>> On Wed, Feb 22, 2017 at 4:14 PM, Winkler, Tomas <tomas.winkler@intel.com>
>> wrote:
>> > On Wed, 2017-02-22 at 15:22 +0800, fgao@ikuai8.com wrote:
>> >> From: Gao Feng <fgao@ikuai8.com>
>> >>
>> >> When make allyesconfig, there is one compile error on my platform
>> >> "gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4".
>> >> The following is the output.
>> >>
>> >> Documentation/misc-devices/mei/mei-amt-version.c: In function ‘main’:
>> >> Documentation/misc-devices/mei/mei-amt-version.c:103:5: warning:
>> >> ‘acmd.fd’
>> >> is used uninitialized in this function [-Wuninitialized]
>> >>   if (cl->fd != -1)
>> >>      ^
>> >> Documentation/misc-devices/mei/mei-amt-version.c:443:21: note:
>> >> ‘acmd.fd’
>> >> was declared here
>> >>   struct amt_host_if acmd;
>> >>                      ^
>> >> This commit fixes this compile error.
>> >>
>> >> Signed-off-by: Gao Feng <fgao@ikuai8.com>
>> >
>> > This is false positive, as the variable is assined in mei_init(), in
>> > any case, the code has moved under samples diretory in the current
>> > kernel. Anything need to be fixed there first
>> >
>> > Thanks
>> > Tomas
>>
>> I think it is not false positive.
>> The function stack is main->amt_host_if_init->mei_init->mei_deinit.
>> There is one check "if (cl->fd != -1)".
>
> Isn't  the first line in mei_init me->fd = open("/dev/mei", O_RDWR); ?
> I don't see mei_deinit called w/o mei_init called first.

The codes of powerpc.git(git://git.kernel.org/pub/scm/linux/kernel/git/galak/powerpc.git)
are different with net.git.
The following are the codes from powerpc.git

static bool mei_init(struct mei *me, const uuid_le *guid,
                unsigned char req_protocol_version, bool verbose)
{
        int result;
        struct mei_client *cl;
        struct mei_connect_client_data data;

        mei_deinit(me);

        me->verbose = verbose;

        me->fd = open("/dev/mei", O_RDWR);
        if (me->fd == -1) {
                mei_err(me, "Cannot establish a handle to the Intel
MEI driver\n");
                goto err;
        }

The mei_deinit is invoked before open, so the gcc reports one warning.

Regards
Feng


>
>> Because this fd is not initialized to -1, so it may hit the condition, and execute
>> close.
>>
>> So it should be fixed, although these codes would be moved to sample
>> director.
>
> Please try with the master branch first in case  I'm still wrong.
> Thanks
>
>> Regards
>> Feng
>>
>> >
>> >> ---
>> >>  Documentation/misc-devices/mei/mei-amt-version.c | 1 +
>> >>  1 file changed, 1 insertion(+)
>> >>
>> >> diff --git a/Documentation/misc-devices/mei/mei-amt-version.c
>> >> b/Documentation/misc-devices/mei/mei-amt-version.c
>> >> index 49e4f77..ca035cb 100644
>> >> --- a/Documentation/misc-devices/mei/mei-amt-version.c
>> >> +++ b/Documentation/misc-devices/mei/mei-amt-version.c
>> >> @@ -297,6 +297,7 @@ static bool amt_host_if_init(struct amt_host_if
>> >> *acmd,
>> >>                     unsigned long send_timeout, bool verbose)  {
>> >>       acmd->send_timeout = (send_timeout) ? send_timeout : 20000;
>> >> +     acmd->mei_cl.fd = -1;
>> >>       acmd->initialized = mei_init(&acmd->mei_cl, &MEI_IAMTHIF, 0,
>> >> verbose);
>> >>       return acmd->initialized;
>> >>  }
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Documentation/misc-devices/mei/mei-amt-version.c b/Documentation/misc-devices/mei/mei-amt-version.c
index 49e4f77..ca035cb 100644
--- a/Documentation/misc-devices/mei/mei-amt-version.c
+++ b/Documentation/misc-devices/mei/mei-amt-version.c
@@ -297,6 +297,7 @@  static bool amt_host_if_init(struct amt_host_if *acmd,
 		      unsigned long send_timeout, bool verbose)
 {
 	acmd->send_timeout = (send_timeout) ? send_timeout : 20000;
+	acmd->mei_cl.fd = -1;
 	acmd->initialized = mei_init(&acmd->mei_cl, &MEI_IAMTHIF, 0, verbose);
 	return acmd->initialized;
 }