Skip to contentSkip to conversation

tools/libs: don't set errno to negative values

PATCH In review Juergen Gross 2 participants 11 messages Apr 20, 2022 – Apr 22, 2022

lore
Share & tools
lore
#0 lore raw

cover tools/libs: don't set errno to negative values

There are a few places in the libs where errno is set to a negative value. Fix those.

Juergen Gross (4):
tools/libs/evtchn: don't set errno to negative values tools/libs/ctrl: don't set errno to a negative value tools/libs/guest: don't set errno to a negative value tools/libs/light: don't set errno to a negative value

 tools/libs/ctrl/xc_domain.c    | 4 +---
 tools/libs/evtchn/freebsd.c    | 2 +-
 tools/libs/evtchn/minios.c     | 2 +-
 tools/libs/evtchn/netbsd.c     | 2 +-
 tools/libs/evtchn/solaris.c    | 2 +-
 tools/libs/guest/xg_dom_core.c | 2 +-
 tools/libs/light/libxl_linux.c | 2 +-
 7 files changed, 7 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 tools/libs/evtchn: don't set errno to negative values

Setting errno to a negative value makes no sense.

---
 tools/libs/evtchn/freebsd.c | 2 +-
 tools/libs/evtchn/minios.c  | 2 +-
 tools/libs/evtchn/netbsd.c  | 2 +-
 tools/libs/evtchn/solaris.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
tools/libs/evtchn/freebsd.c +1 -1
index c4d075350b..422836f1a1 100644
@@ -58,7 +58,7 @@ int osdep_evtchn_close(xenevtchn_handle *xce)
 
 int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid)
 {
-    errno = -EOPNOTSUPP;
+    errno = EOPNOTSUPP;
 
     return -1;
 }
tools/libs/evtchn/minios.c +1 -1
index 65cfccfd09..8ff46de884 100644
@@ -143,7 +143,7 @@ int osdep_evtchn_close(xenevtchn_handle *xce)
 
 int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid)
 {
-    errno = -EOPNOTSUPP;
+    errno = EOPNOTSUPP;
 
     return -1;
 }
tools/libs/evtchn/netbsd.c +1 -1
index 0b223c4beb..2de9cefc67 100644
@@ -53,7 +53,7 @@ int osdep_evtchn_close(xenevtchn_handle *xce)
 
 int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid)
 {
-    errno = -EOPNOTSUPP;
+    errno = EOPNOTSUPP;
 
     return -1;
 }
tools/libs/evtchn/solaris.c +1 -1
index 7fef88a73e..375a5f9b4f 100644
@@ -53,7 +53,7 @@ int osdep_evtchn_close(xenevtchn_handle *xce)
 
 int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid)
 {
-    errno = -EOPNOTSUPP;
+    errno = EOPNOTSUPP;
     return -1;
 }
 
Signature · 1 line
2.34.1
#3 lore raw

PATCH 2/4 tools/libs/ctrl: don't set errno to a negative value

In reply to Juergen Gross

The claimed reason for setting errno to -1 is wrong. On x86 xc_domain_pod_target() will set errno to a sane value in the error case.

---
 tools/libs/ctrl/xc_domain.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
tools/libs/ctrl/xc_domain.c +1 -3
index ef62f66009..71608c00e9 100644
@@ -1293,9 +1293,7 @@ int xc_domain_get_pod_target(xc_interface *xch,
                              uint64_t *pod_cache_pages,
                              uint64_t *pod_entries)
 {
-    /* On x86 (above) xc_domain_pod_target will incorrectly return -1
-     * with errno==-1 on error. Do the same for least surprise. */
-    errno = -1;
+    errno = EOPNOTSUPP;
     return -1;
 }
 #endif
Signature · 1 line
2.34.1
#5 lore raw

PATCH 3/4 tools/libs/guest: don't set errno to a negative value

In reply to Juergen Gross

Setting errno to a negative error value makes no sense.

---
 tools/libs/guest/xg_dom_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libs/guest/xg_dom_core.c +1 -1
index c17cf9f712..c4f4e7f3e2 100644
@@ -855,7 +855,7 @@ int xc_dom_devicetree_file(struct xc_dom_image *dom, const char *filename)
         return -1;
     return 0;
 #else
-    errno = -EINVAL;
+    errno = EINVAL;
     return -1;
 #endif
 }
Signature · 1 line
2.34.1
#7 lore raw

PATCH 4/4 tools/libs/light: don't set errno to a negative value

In reply to Juergen Gross

Setting errno to a negative value makes no sense.

---
 tools/libs/light/libxl_linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libs/light/libxl_linux.c +1 -1
index 8d62dfd255..27f2bce718 100644
@@ -288,7 +288,7 @@ int libxl__pci_topology_init(libxl__gc *gc,
         if (i == num_devs) {
             LOG(ERROR, "Too many devices");
             err = ERROR_FAIL;
-            errno = -ENOSPC;
+            errno = ENOSPC;
             goto out;
         }
 
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH 4/4] tools/libs/light: don't set errno to a negative value

Quoted 8 lines · Andrew Cooper
Quoted 1 line · Juergen Gross

Setting errno to a negative value makes no sense.

Fixes e78e8b9bb649b
Quoted 1 line

Do you want me to send the patches with the Fixes tags added?

TBH I didn't bother to do the research for those, as the wrong values don't seem to cause any harm today. I just stumbled over the issues and thought it would be a good idea to fix those.

Juergen

#10 lore raw

Re: [PATCH 4/4] tools/libs/light: don't set errno to a negative value

Quoted 8 lines · Juergen Gross
Quoted 7 lines · Andrew Cooper
Quoted 1 line · Juergen Gross

Setting errno to a negative value makes no sense.

Fixes e78e8b9bb649b
Quoted 1 line
Quoted 7 lines
Quoted 1 line

Do you want me to send the patches with the Fixes tags added?

TBH I didn't bother to do the research for those, as the wrong values don't seem to cause any harm today. I just stumbled over the issues and thought it would be a good idea to fix those.

Given that there's nothing else to adjust, I was thinking of just fixing them on commit.

But we should backport these to all appropriate releases (cc Jan).

~Andrew