All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools/libxl: Fix build following c/s c3c8da9
@ 2015-06-29 12:41 Andrew Cooper
  2015-06-29 14:09 ` Ian Jackson
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cooper @ 2015-06-29 12:41 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Ian Jackson, Ian Campbell, Wei Liu

c/s c3c8da9 "libxl: ao: datacopier callback gets an rc" caused
libxl__domain_save_device_model() to pass its rc directly into the callback.

However in the preexisting code, there were 3 "goto out;" paths which left rc
uninitialised, which is cause by GCC 4.8's -Wmaybe-uninitialized

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
---
 tools/libxl/libxl_dom.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 600393d..d547eb5 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -2147,7 +2147,7 @@ void libxl__domain_save_device_model(libxl__egc *egc,
     STATE_AO_GC(dss->ao);
     struct stat st;
     uint32_t qemu_state_len;
-    int rc;
+    int rc = -1;
 
     dss->save_dm_callback = callback;
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools/libxl: Fix build following c/s c3c8da9
  2015-06-29 12:41 [PATCH] tools/libxl: Fix build following c/s c3c8da9 Andrew Cooper
@ 2015-06-29 14:09 ` Ian Jackson
  2015-06-29 14:22   ` Andrew Cooper
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Jackson @ 2015-06-29 14:09 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Wei Liu, Ian Campbell, Xen-devel

Andrew Cooper writes ("[PATCH] tools/libxl: Fix build following c/s c3c8da9"):
> c/s c3c8da9 "libxl: ao: datacopier callback gets an rc" caused
> libxl__domain_save_device_model() to pass its rc directly into the callback.
> 
> However in the preexisting code, there were 3 "goto out;" paths which left rc
> uninitialised, which is cause by GCC 4.8's -Wmaybe-uninitialized

The solution is not to initialise rc (to a bogus value) but to fix the
goto out paths to explicitly set rc.

Can you easily confirm that this fixes it ?

Ian.

diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index bdc0465..1c9418a 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -2190,17 +2190,20 @@ void libxl__domain_save_device_model(libxl__egc *egc,
     dc->readfd = open(filename, O_RDONLY);
     if (dc->readfd < 0) {
         LOGE(ERROR, "unable to open %s", dc->readwhat);
+        rc = ERROR_FAIL;
         goto out;
     }
 
     if (fstat(dc->readfd, &st))
     {
         LOGE(ERROR, "unable to fstat %s", dc->readwhat);
+        rc = ERROR_FAIL;
         goto out;
     }
 
     if (!S_ISREG(st.st_mode)) {
         LOG(ERROR, "%s is not a plain file!", dc->readwhat);
+        rc = ERROR_FAIL;
         goto out;
     }

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools/libxl: Fix build following c/s c3c8da9
  2015-06-29 14:09 ` Ian Jackson
@ 2015-06-29 14:22   ` Andrew Cooper
  2015-06-29 14:29     ` Ian Jackson
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cooper @ 2015-06-29 14:22 UTC (permalink / raw)
  To: Ian Jackson; +Cc: Wei Liu, Ian Campbell, Xen-devel

On 29/06/15 15:09, Ian Jackson wrote:
> Andrew Cooper writes ("[PATCH] tools/libxl: Fix build following c/s c3c8da9"):
>> c/s c3c8da9 "libxl: ao: datacopier callback gets an rc" caused
>> libxl__domain_save_device_model() to pass its rc directly into the callback.
>>
>> However in the preexisting code, there were 3 "goto out;" paths which left rc
>> uninitialised, which is cause by GCC 4.8's -Wmaybe-uninitialized
> The solution is not to initialise rc (to a bogus value) but to fix the
> goto out paths to explicitly set rc.
>
> Can you easily confirm that this fixes it ?

It does indeed.  Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>

However, the problem with this style is that it is subverted by:

rc = libxl__datacopier_start(dc);
if (rc) goto out;

out of context below, which cases rc to be initialised on all subsequent
error paths, and thus miss further issues where it is set incorrectly.

I would suggest introducing another int to hold the temporary from
libxl__datacopier_start().

~Andrew

>
> Ian.
>
> diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
> index bdc0465..1c9418a 100644
> --- a/tools/libxl/libxl_dom.c
> +++ b/tools/libxl/libxl_dom.c
> @@ -2190,17 +2190,20 @@ void libxl__domain_save_device_model(libxl__egc *egc,
>      dc->readfd = open(filename, O_RDONLY);
>      if (dc->readfd < 0) {
>          LOGE(ERROR, "unable to open %s", dc->readwhat);
> +        rc = ERROR_FAIL;
>          goto out;
>      }
>  
>      if (fstat(dc->readfd, &st))
>      {
>          LOGE(ERROR, "unable to fstat %s", dc->readwhat);
> +        rc = ERROR_FAIL;
>          goto out;
>      }
>  
>      if (!S_ISREG(st.st_mode)) {
>          LOG(ERROR, "%s is not a plain file!", dc->readwhat);
> +        rc = ERROR_FAIL;
>          goto out;
>      }
>  

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools/libxl: Fix build following c/s c3c8da9
  2015-06-29 14:22   ` Andrew Cooper
@ 2015-06-29 14:29     ` Ian Jackson
  2015-06-29 14:32       ` [PATCH] libxl: Fix uninitialised rc in libxl__domain_save_device_model Ian Jackson
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Jackson @ 2015-06-29 14:29 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Wei Liu, Ian Campbell, Xen-devel

Andrew Cooper writes ("Re: [PATCH] tools/libxl: Fix build following c/s c3c8da9"):
> On 29/06/15 15:09, Ian Jackson wrote:
> > Can you easily confirm that this fixes it ?
> 
> It does indeed.  Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>
> 
> However, the problem with this style is that it is subverted by:
> 
> rc = libxl__datacopier_start(dc);
> if (rc) goto out;
> 
> out of context below, which cases rc to be initialised on all subsequent
> error paths, and thus miss further issues where it is set incorrectly.

Yes, I agree that this is less than ideal.  It means that not all such
uninitialised rc's will be found, but ...

> I would suggest introducing another int to hold the temporary from
> libxl__datacopier_start().

... this would be quite inconvenient.

The right answer IMO is to replace the idiom

   rc = some_function(...);
   if (rc) goto out;

with a macro invocation

   CHECKING_RC( some_function(...) );

and maybe have a `goto out' macro, too

   GOTO_OUT_RC(FAIL);

But I'm not sure my co-maintainers agree.

Anyway, thanks for the tested-by.  I will make a proper commit message
etc. and apply my patch.

Ian.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] libxl: Fix uninitialised rc in libxl__domain_save_device_model
  2015-06-29 14:29     ` Ian Jackson
@ 2015-06-29 14:32       ` Ian Jackson
  0 siblings, 0 replies; 5+ messages in thread
From: Ian Jackson @ 2015-06-29 14:32 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson, Andrew Cooper, Wei Liu, Ian Campbell

c3c8da9 "libxl: ao: datacopier callback gets an rc" caused
libxl__domain_save_device_model() to pass its rc directly into the
callback.

However in the preexisting code, there were 3 "goto out;" paths which
left rc uninitialised.  This causes a build failure with GCC 4.8's
-Wmaybe-uninitialized.

Set the rc explicitly on each goto out path.

Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 tools/libxl/libxl_dom.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index bdc0465..1c9418a 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -2190,17 +2190,20 @@ void libxl__domain_save_device_model(libxl__egc *egc,
     dc->readfd = open(filename, O_RDONLY);
     if (dc->readfd < 0) {
         LOGE(ERROR, "unable to open %s", dc->readwhat);
+        rc = ERROR_FAIL;
         goto out;
     }
 
     if (fstat(dc->readfd, &st))
     {
         LOGE(ERROR, "unable to fstat %s", dc->readwhat);
+        rc = ERROR_FAIL;
         goto out;
     }
 
     if (!S_ISREG(st.st_mode)) {
         LOG(ERROR, "%s is not a plain file!", dc->readwhat);
+        rc = ERROR_FAIL;
         goto out;
     }
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-29 14:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-29 12:41 [PATCH] tools/libxl: Fix build following c/s c3c8da9 Andrew Cooper
2015-06-29 14:09 ` Ian Jackson
2015-06-29 14:22   ` Andrew Cooper
2015-06-29 14:29     ` Ian Jackson
2015-06-29 14:32       ` [PATCH] libxl: Fix uninitialised rc in libxl__domain_save_device_model Ian Jackson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.