Skip to contentSkip to conversation

tools/xen-ucode: fix error code propagation of microcode load operation

PATCH In review Igor Druzhinin 2 participants 3 messages Jun 16, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/xen-ucode: fix error code propagation of microcode load operation

Otherwise it's impossible to know the reason for a fault or blob rejection inside the automation.

While at it, also change return code of incorrect invokation to EINVAL.

---
Changes in v2:
- simply call "return errno". On Linux that seems to be safe as values <=255 are correctly propagated, on non-Linux I couldn't find error codes >127.
- return positive value on incorrect invokation

---
 tools/misc/xen-ucode.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/misc/xen-ucode.c +4 -1
index 0c257f4..409cace 100644
@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
         fprintf(stderr,
                 "xen-ucode: Xen microcode updating tool\n"
                 "Usage: %s <microcode blob>\n", argv[0]);
-        return 0;
+        return EINVAL;
     }
 
     filename = argv[1];
@@ -62,8 +62,11 @@ int main(int argc, char *argv[])
 
     ret = xc_microcode_update(xch, buf, len);
     if ( ret )
+    {
         fprintf(stderr, "Failed to update microcode. (err: %s)\n",
                 strerror(errno));
+        return errno;
+    }
 
     xc_interface_close(xch);
 
Signature · 1 line
2.7.4
#1 lore raw

tools/misc/xen-ucode.c int main(int argc, char *argv[]) · line 68

Quoted 8 lines · Igor Druzhinin
tools/misc/xen-ucode.c +2 -0
@@ -62,8 +62,11 @@ int main(int argc, char *argv[])
 
     ret = xc_microcode_update(xch, buf, len);
     if ( ret )
+    {
         fprintf(stderr, "Failed to update microcode. (err: %s)\n",
                 strerror(errno));
+        return errno;

I think you need to latch errno, as fprintf() may in principle run into another error.

Jan

#2 lore raw
Quoted 5 lines · Jan Beulich

[CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.

Quoted 2 lines · Igor Druzhinin
(quoted diff) +0 -0
@@ -62,8 +62,11 @@ int main(int argc, char *argv[])
 
Quoted 9 lines

tools/misc/xen-ucode.c int main(int argc, char *argv[]) · line 68

Quoted 6 lines
tools/misc/xen-ucode.c +2 -0
     ret = xc_microcode_update(xch, buf, len);
     if ( ret )
+    {
         fprintf(stderr, "Failed to update microcode. (err: %s)\n",
                 strerror(errno));
+        return errno;

I think you need to latch errno, as fprintf() may in principle run into another error.

Yes, I also noticed that but the whole file has this problem so I didn't change it here specifically.

If fixing the whole file - I'd rather rewrite error reporting completely:
return 1 on error, 0 on success, etc. From what I've read returning errno has many incompatibilities and might lead to surprise consequences.

I'll send v3 to clean this all up.

Igor