Skip to contentSkip to conversation

libvhost-user: Declare uffdio_register early to make it C90 compliant

PATCH In review Marcel Holtmann 1 participant 1 message Dec 19, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 5/7 libvhost-user: Declare uffdio_register early to make it C90 compliant

When using libvhost-user source in an external project that wants to comply with the C90 standard, it is best to declare variables before code.

CC libvhost-user.o
libvhost-user.c: In function ‘generate_faults’:
libvhost-user.c:683:9: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

  683 |         struct uffdio_register reg_struct;
      |         ^~~~~~

In this case, it is also simple enough and doesn't cause any extra ifdef additions.

---
 subprojects/libvhost-user/libvhost-user.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
subprojects/libvhost-user/libvhost-user.c +3 -1
index 211d31a4cc88..bf92cc85c086 100644
@@ -626,6 +626,8 @@ generate_faults(VuDev *dev) {
         VuDevRegion *dev_region = &dev->regions[i];
         int ret;
 #ifdef UFFDIO_REGISTER
+        struct uffdio_register reg_struct;
+
         /*
          * We should already have an open ufd. Mark each memory
          * range as ufd.
@@ -659,7 +661,7 @@ generate_faults(VuDev *dev) {
                     "%s: Failed to madvise(NOHUGEPAGE) region %d: %s\n",
                     __func__, i, strerror(errno));
         }
-        struct uffdio_register reg_struct;
+
         reg_struct.range.start = (uintptr_t)dev_region->mmap_addr;
         reg_struct.range.len = dev_region->size + dev_region->mmap_offset;
         reg_struct.mode = UFFDIO_REGISTER_MODE_MISSING;
Signature · 1 line
2.38.1