[for-4.14,v2] tools/xen-ucode: fix error code propagation of microcode load operation
diff mbox series

Message ID 1592307754-8844-1-git-send-email-igor.druzhinin@citrix.com
State New
Headers show
Series
  • [for-4.14,v2] tools/xen-ucode: fix error code propagation of microcode load operation
Related show

Commit Message

Igor Druzhinin June 16, 2020, 11:42 a.m. UTC
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.

Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
---
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(-)

Comments

Jan Beulich June 16, 2020, 12:25 p.m. UTC | #1
On 16.06.2020 13:42, Igor Druzhinin wrote:
> @@ -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
Igor Druzhinin June 16, 2020, 12:40 p.m. UTC | #2
On 16/06/2020 13:25, Jan Beulich wrote:
> [CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.
> 
> On 16.06.2020 13:42, Igor Druzhinin wrote:
>> @@ -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.

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

Patch
diff mbox series

diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c
index 0c257f4..409cace 100644
--- a/tools/misc/xen-ucode.c
+++ b/tools/misc/xen-ucode.c
@@ -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);