[PATCH for-4.14 v2] tools/xen-ucode: fix error code propagation of microcode load operation

Igor Druzhinin posted 1 patch 3 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/xen tags/patchew/1592307754-8844-1-git-send-email-igor.druzhinin@citrix.com
Maintainers: Wei Liu <wl@xen.org>, Ian Jackson <ian.jackson@eu.citrix.com>
tools/misc/xen-ucode.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH for-4.14 v2] tools/xen-ucode: fix error code propagation of microcode load operation
Posted by Igor Druzhinin 3 years, 9 months ago
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(-)

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);
 
-- 
2.7.4


Re: [PATCH for-4.14 v2] tools/xen-ucode: fix error code propagation of microcode load operation
Posted by Jan Beulich 3 years, 9 months ago
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

Re: [PATCH for-4.14 v2] tools/xen-ucode: fix error code propagation of microcode load operation
Posted by Igor Druzhinin 3 years, 9 months ago
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