Skip to contentSkip to conversation

Fix uninitialised variable warning in mei-amt-version.c

PATCH In review David Howells 3 participants 6 messages Jan 3, 2014 – Jan 4, 2014 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 7/7 Fix uninitialised variable warning in mei-amt-version.c

Fix the following warning:

	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;
			     ^

The call chain:

	-->main()
	   -->amt_host_if_init()
	      -->mei_init()
	         -->mei_deinit()

results in this on the first time through because main()::acmd has not yet been initialised.

To fix this, acmd.fd needs to be initialised to -1.

cc Tomas Winkler <[email protected]>
cc Greg Kroah-Hartman <[email protected]>

---

 Documentation/misc-devices/mei/mei-amt-version.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/misc-devices/mei/mei-amt-version.c +1 -1
index 49e4f770864a..7027a8da0ba0 100644
@@ -440,7 +440,7 @@ out:
 int main(int argc, char **argv)
 {
 	struct amt_code_versions ver;
-	struct amt_host_if acmd;
+	struct amt_host_if acmd = { .mei_cl.fd = -1 };
 	unsigned int i;
 	uint32_t status;
 	int ret;
#1 lore raw
Quoted 17 lines · David Howells

Fix the following warning:

	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;
			     ^

The call chain:

	-->main()
	   -->amt_host_if_init()
	      -->mei_init()
	         -->mei_deinit()
Quoted 8 lines

results in this on the first time through because main()::acmd has not yet been initialised.

To fix this, acmd.fd needs to be initialised to -1.

cc Tomas Winkler <[email protected]>
cc Greg Kroah-Hartman <[email protected]>

I've been using a local patch now for quite some time. I currently use it on v3.12.6. I haven't yet bothered to submit it. My (draft) commit summary reads:

"Building mei-amt-version.o triggers a GCC warning:

    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;
                         ^

GCC is correct. See, the call chain that GCC detects must be

    main()
        amt_host_if_init()
            mei_init()
                mei_deinit()

But when we enter mei_deinit() struct amt_host_if acmd is still unitialized. That makes the test for (effectively) amt_host_if->mei_cl->fd bogus.

But it turns out that call of mei_deinit() isn't needed at all. All of the members of mei_cl will be set later in mei_init() and none will be used before they are set. So we can simply drop this call of mei_deinit()."

Is that analysis (still) correct?

Paul Bolle

Quoted 17 lines
 Documentation/misc-devices/mei/mei-amt-version.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/misc-devices/mei/mei-amt-version.c +1 -1
index 49e4f770864a..7027a8da0ba0 100644
@@ -440,7 +440,7 @@ out:
 int main(int argc, char **argv)
 {
 	struct amt_code_versions ver;
-	struct amt_host_if acmd;
+	struct amt_host_if acmd = { .mei_cl.fd = -1 };
 	unsigned int i;
 	uint32_t status;
 	int ret;
#2 lore raw
Quoted 6 lines · Paul Bolle

But it turns out that call of mei_deinit() isn't needed at all. All of the members of mei_cl will be set later in mei_init() and none will be used before they are set. So we can simply drop this call of mei_deinit()."

Is that analysis (still) correct?

It looks true as the code stands. Can you send me your patch?

David

#3 lore raw

PATCH 1/1 mei: mei-amt-version: remove unneeded call of mei_deinit()

Quoted 9 lines · David Howells
Quoted 6 lines · Paul Bolle

But it turns out that call of mei_deinit() isn't needed at all. All of the members of mei_cl will be set later in mei_init() and none will be used before they are set. So we can simply drop this call of mei_deinit()."

Is that analysis (still) correct?

It looks true as the code stands. Can you send me your patch?

Sure. Below the scissors (hope I've typed those correctly).

Paul Bolle
-------->8-------
From: Paul Bolle <[email protected]>

Building mei-amt-version.o triggers a GCC warning:

    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;
                         ^

GCC is correct. See, the call chain that GCC detects must be

    main()
        amt_host_if_init()
            mei_init()
                mei_deinit()

But when we enter mei_deinit() struct amt_host_if acmd is still unitialized. That makes the test for (effectively) amt_host_if->mei_cl->fd bogus.

But it turns out that call of mei_deinit() isn't needed at all. All of the members of mei_cl will be set later in mei_init() and none will be used before they are set. So we can simply drop this call of mei_deinit().

---
 Documentation/misc-devices/mei/mei-amt-version.c | 2 --
 1 file changed, 2 deletions(-)
Documentation/misc-devices/mei/mei-amt-version.c +0 -2
index 49e4f77..57d0d87 100644
@@ -115,8 +115,6 @@ static bool mei_init(struct mei *me, const uuid_le *guid,
 	struct mei_client *cl;
 	struct mei_connect_client_data data;
 
-	mei_deinit(me);
-
 	me->verbose = verbose;
 
 	me->fd = open("/dev/mei", O_RDWR);
Signature · 1 line
1.8.4.2
author Acked-by on v1 1/1
#4 lore raw

Re: [PATCH] mei: mei-amt-version: remove unneeded call of mei_deinit()

Quoted 21 lines · Paul Bolle

From: Paul Bolle <[email protected]>

Building mei-amt-version.o triggers a GCC warning:

    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;
                         ^

GCC is correct. See, the call chain that GCC detects must be

    main()
        amt_host_if_init()
            mei_init()
                mei_deinit()

But when we enter mei_deinit() struct amt_host_if acmd is still unitialized. That makes the test for (effectively) amt_host_if->mei_cl->fd bogus.

Quoted 6 lines

But it turns out that call of mei_deinit() isn't needed at all. All of the members of mei_cl will be set later in mei_init() and none will be used before they are set. So we can simply drop this call of mei_deinit().

Builds without warning for me.

#5 lore raw
In reply to David Howells
Quoted 12 lines

-----Original Message-----
From: David Howells [mailto:[email protected]]
Sent: Friday, January 03, 2014 18:34
To: Paul Bolle
Cc: [email protected]; [email protected]; Greg Kroah-Hartman; Winkler, Tomas; [email protected]
Subject: Re: [PATCH 7/7] Fix uninitialised variable warning in mei-amt-version.c

Paul Bolle <[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines

But it turns out that call of mei_deinit() isn't needed at all. All of the members of mei_cl will be set later in mei_init() and none will be used before they are set. So we can simply drop this call of mei_deinit()."

Is that analysis (still) correct?

It looks true as the code stands. Can you send me your patch?

Yes, the analysis is correct, need to fix the typo in the title and but otherwise ACK.

Thanks
Tomas