Skip to contentSkip to conversation

Replacing malloc and the like with GLib's variants

PATCH NAK Mahmoud Mandour 3 participants 13 messages Mar 13, 2021 – Mar 14, 2021 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

cover Replacing malloc and the like with GLib's variants

Inspired by the task in the Bite-sized tasks page, I've tried to change some of the occurrences of malloc(), calloc(), and realloc() calls and their respective free() calls. I also included some minor style improvements that caused errors and warnings when supplied to the checkpatch.pl script.

At numerous places, the change is quite obvious. However, some other malloc() and the like have no immediately visible free() calls. Analysis was done to trace the roots of each free() call to match each GLib function with a g_free(), and every malloc(), realloc(), or calloc() call with a call to free().

Mahmoud Mandour (9):
bsd-user/elfload.c: Replaced calls to malloc/free with GLib variants hw/audio/fmopl.c: Fixing some style errors. hw/audio/fmopl.c: Replaced calls to malloc with GLib's variants pc-bios/s390-ccw/netmain.c: Changed a malloc/free to GLib's variants target/xtensa: Replaced malloc/free with GLib's variants. util/compatfd.c: Replaced a malloc with GLib's g_try_malloc tools/virtiofsd/buffer.c: replaced a calloc call with GLib's

    g_try_new0

tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc tools/virtiofsd: Replacing malloc-like calls with GLib's variants

 bsd-user/elfload.c               | 74 ++++++++++++++++----------------
 hw/audio/fmopl.c                 | 61 ++++++++++++++------------
 pc-bios/s390-ccw/netmain.c       |  6 +--
 target/xtensa/xtensa-isa.c       | 28 ++++++------
 tools/virtiofsd/buffer.c         |  4 +-
 tools/virtiofsd/fuse_lowlevel.c  | 30 ++++++-------
 tools/virtiofsd/fuse_opt.c       |  4 +-
 tools/virtiofsd/fuse_virtio.c    | 34 +++++++--------
 tools/virtiofsd/passthrough_ll.c | 32 +++++++-------
 util/compatfd.c                  | 10 ++---
 10 files changed, 145 insertions(+), 138 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/9 bsd-user/elfload.c: Replaced calls to malloc/free with GLib variants

Replaced the calls to malloc(), realloc(), and free() to their equivalents in GLib's allocation functions in various places.

---
 bsd-user/elfload.c | 74 +++++++++++++++++++++++-----------------------
 1 file changed, 37 insertions(+), 37 deletions(-)
bsd-user/elfload.c +37 -37
index 5f4d824d78..7b0793693b 100644
@@ -867,8 +867,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex,
         if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZE)
             return ~(abi_ulong)0UL;
 
-        elf_phdata =  (struct elf_phdr *)
-                malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum);
+        elf_phdata = g_try_new(struct elf_phdr, interp_elf_ex->ephnum)
 
         if (!elf_phdata)
           return ~((abi_ulong)0UL);
@@ -878,7 +877,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex,
          * we will be doing the wrong thing.
          */
         if (interp_elf_ex->e_phentsize != sizeof(struct elf_phdr)) {
-            free(elf_phdata);
+            g_free(elf_phdata);
             return ~((abi_ulong)0UL);
         }
 
@@ -891,7 +890,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex,
         if (retval < 0) {
                 perror("load_elf_interp");
                 exit(-1);
-                free (elf_phdata);
+                g_free(elf_phdata);
                 return retval;
         }
 #ifdef BSWAP_NEEDED
@@ -940,7 +939,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex,
             if (error == -1) {
               /* Real error */
               close(interpreter_fd);
-              free(elf_phdata);
+              g_free(elf_phdata);
               return ~((abi_ulong)0UL);
             }
 
@@ -983,7 +982,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex,
                         PROT_READ|PROT_WRITE|PROT_EXEC,
                         MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1, 0);
         }
-        free(elf_phdata);
+        g_free(elf_phdata);
 
         *interp_load_addr = load_addr;
         return ((abi_ulong) interp_elf_ex->e_entry) + load_addr;
@@ -1064,24 +1063,24 @@ static void load_symbols(struct elfhdr *hdr, int fd)
 
  found:
     /* Now know where the strtab and symtab are.  Snarf them. */
-    s = malloc(sizeof(*s));
-    syms = malloc(symtab.sh_size);
+    s = g_try_malloc(sizeof(*s));
+    syms = g_try_malloc(symtab.sh_size);
     if (!syms) {
-        free(s);
+        g_free(s);
         return;
     }
-    s->disas_strtab = strings = malloc(strtab.sh_size);
+    s->disas_strtab = strings = g_malloc(strtab.sh_size);
     if (!s->disas_strtab) {
-        free(s);
-        free(syms);
+        g_free(s);
+        g_free(syms);
         return;
     }
 
     lseek(fd, symtab.sh_offset, SEEK_SET);
     if (read(fd, syms, symtab.sh_size) != symtab.sh_size) {
-        free(s);
-        free(syms);
-        free(strings);
+        g_free(s);
+        g_free(syms);
+        g_free(strings);
         return;
     }
 
@@ -1113,11 +1112,11 @@ static void load_symbols(struct elfhdr *hdr, int fd)
         that we threw away.  Whether or not this has any effect on the
         memory allocation depends on the malloc implementation and how
         many symbols we managed to discard. */
-    new_syms = realloc(syms, nsyms * sizeof(*syms));
+    new_syms = g_try_realloc(syms, nsyms * sizeof(*syms));
     if (new_syms == NULL) {
-        free(s);
-        free(syms);
-        free(strings);
+        g_free(s);
+        g_free(syms);
+        g_free(strings);
         return;
     }
     syms = new_syms;
@@ -1126,9 +1125,9 @@ static void load_symbols(struct elfhdr *hdr, int fd)
 
     lseek(fd, strtab.sh_offset, SEEK_SET);
     if (read(fd, strings, strtab.sh_size) != strtab.sh_size) {
-        free(s);
-        free(syms);
-        free(strings);
+        g_free(s);
+        g_free(syms);
+        g_free(strings);
         return;
     }
     s->disas_num_syms = nsyms;
@@ -1190,7 +1189,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
     }
 
     /* Now read in all of the header information */
-    elf_phdata = (struct elf_phdr *)malloc(elf_ex.e_phentsize*elf_ex.e_phnum);
+    elf_phdata =
+        (struct elf_phdr *)g_try_malloc(elf_ex.e_phentsizei * elf_ex.e_phnum);
     if (elf_phdata == NULL) {
         return -ENOMEM;
     }
@@ -1204,7 +1204,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
     if (retval < 0) {
         perror("load_elf_binary");
         exit(-1);
-        free (elf_phdata);
+        g_free(elf_phdata);
         return -errno;
     }
 
@@ -1231,8 +1231,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
         if (elf_ppnt->p_type == PT_INTERP) {
             if ( elf_interpreter != NULL )
             {
-                free (elf_phdata);
-                free(elf_interpreter);
+                g_free(elf_phdata);
+                g_free(elf_interpreter);
                 close(bprm->fd);
                 return -EINVAL;
             }
@@ -1242,10 +1242,10 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
              * is an a.out format binary
              */
 
-            elf_interpreter = (char *)malloc(elf_ppnt->p_filesz);
+            elf_interpreter = (char *)g_try_malloc(elf_ppnt->p_filesz);
 
             if (elf_interpreter == NULL) {
-                free (elf_phdata);
+                g_free(elf_phdata);
                 close(bprm->fd);
                 return -ENOMEM;
             }
@@ -1298,8 +1298,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
             if (retval < 0) {
                 perror("load_elf_binary3");
                 exit(-1);
-                free (elf_phdata);
-                free(elf_interpreter);
+                g_free(elf_phdata);
+                g_free(elf_interpreter);
                 close(bprm->fd);
                 return retval;
             }
@@ -1323,8 +1323,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
         }
 
         if (!interpreter_type) {
-            free(elf_interpreter);
-            free(elf_phdata);
+            g_free(elf_interpreter);
+            g_free(elf_phdata);
             close(bprm->fd);
             return -ELIBBAD;
         }
@@ -1346,8 +1346,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
             }
         }
         if (!bprm->p) {
-            free(elf_interpreter);
-            free (elf_phdata);
+            g_free(elf_interpreter);
+            g_free(elf_phdata);
             close(bprm->fd);
             return -E2BIG;
         }
@@ -1486,17 +1486,17 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
         reloc_func_desc = interp_load_addr;
 
         close(interpreter_fd);
-        free(elf_interpreter);
+        g_free(elf_interpreter);
 
         if (elf_entry == ~((abi_ulong)0UL)) {
             printf("Unable to load interpreter\n");
-            free(elf_phdata);
+            g_free(elf_phdata);
             exit(-1);
             return 0;
         }
     }
 
-    free(elf_phdata);
+    g_free(elf_phdata);
 
     if (qemu_log_enabled())
         load_symbols(&elf_ex, bprm->fd);
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/9 hw/audio/fmopl.c: Fixing some style errors.

In reply to Mahmoud Mandour

Fixed style errors on the relevant lines in which
I will introduce changes.

---
 hw/audio/fmopl.c | 52 ++++++++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 26 deletions(-)
hw/audio/fmopl.c +26 -26
index 8a71a569fa..45f15c53b3 100644
@@ -607,26 +607,26 @@ static int OPLOpenTable( void )
 	double pom;
 
 	/* allocate dynamic tables */
-	if( (TL_TABLE = malloc(TL_MAX*2*sizeof(int32_t))) == NULL)
-		return 0;
-	if( (SIN_TABLE = malloc(SIN_ENT*4 *sizeof(int32_t *))) == NULL)
-	{
-		free(TL_TABLE);
-		return 0;
-	}
-	if( (AMS_TABLE = malloc(AMS_ENT*2 *sizeof(int32_t))) == NULL)
-	{
-		free(TL_TABLE);
-		free(SIN_TABLE);
-		return 0;
-	}
-	if( (VIB_TABLE = malloc(VIB_ENT*2 *sizeof(int32_t))) == NULL)
-	{
-		free(TL_TABLE);
-		free(SIN_TABLE);
-		free(AMS_TABLE);
-		return 0;
-	}
+    if((TL_TABLE = malloc(TL_MAX * 2 * sizeof(int32_t))) == NULL)
+        return 0;
+    if((SIN_TABLE = malloc(SIN_ENT * 4 *sizeof(int32_t *))) == NULL)
+    {
+        free(TL_TABLE);
+        return 0;
+    }
+    if((AMS_TABLE = malloc(AMS_ENT * 2 * sizeof(int32_t))) == NULL)
+    {
+        free(TL_TABLE);
+        free(SIN_TABLE);
+        return 0;
+    }
+    if((VIB_TABLE = malloc(VIB_ENT *2 * sizeof(int32_t))) == NULL)
+    {
+        free(TL_TABLE);
+        free(SIN_TABLE);
+        free(AMS_TABLE);
+        return 0;
+    }
     ENV_CURVE = g_new(int32_t, 2 * EG_ENT + 1);
 	/* make total level table */
 	for (t = 0;t < EG_ENT-1 ;t++){
@@ -696,10 +696,10 @@ static int OPLOpenTable( void )
 static void OPLCloseTable( void )
 {
     g_free(ENV_CURVE);
-	free(TL_TABLE);
-	free(SIN_TABLE);
-	free(AMS_TABLE);
-	free(VIB_TABLE);
+    free(TL_TABLE);
+    free(SIN_TABLE);
+    free(AMS_TABLE);
+    free(VIB_TABLE);
 }
 
 /* CSM Key Control */
@@ -1082,7 +1082,7 @@ FM_OPL *OPLCreate(int clock, int rate)
 	state_size  = sizeof(FM_OPL);
 	state_size += sizeof(OPL_CH)*max_ch;
 	/* allocate memory block */
-	ptr = malloc(state_size);
+    ptr = malloc(state_size);
 	if(ptr==NULL) return NULL;
 	/* clear */
 	memset(ptr,0,state_size);
@@ -1128,7 +1128,7 @@ void OPLDestroy(FM_OPL *OPL)
 	}
 #endif
 	OPL_UnLockTable();
-	free(OPL);
+    free(OPL);
 }
 
 /* ----------  Option handlers ----------       */
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/9 hw/audio/fmopl.c: Replaced calls to malloc with GLib's variants

In reply to Mahmoud Mandour

Replaced calls to malloc(), and free() to their equivalent allocation functions from GLib.

Also added checking for null after ENV_CURVE allocation following the same pattern of checking on preceeding table allocations.

---
 hw/audio/fmopl.c | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)
hw/audio/fmopl.c +24 -17
index 45f15c53b3..6cecf2b963 100644
@@ -607,27 +607,34 @@ static int OPLOpenTable( void )
 	double pom;
 
 	/* allocate dynamic tables */
-    if((TL_TABLE = malloc(TL_MAX * 2 * sizeof(int32_t))) == NULL)
+    if((TL_TABLE = g_try_new(int32_t, TL_MAX * 2)) == NULL)
         return 0;
-    if((SIN_TABLE = malloc(SIN_ENT * 4 *sizeof(int32_t *))) == NULL)
+    if((SIN_TABLE = g_try_new(int32_t *, SIN_ENT * 4)) == NULL)
     {
-        free(TL_TABLE);
+        g_free(TL_TABLE);
         return 0;
     }
-    if((AMS_TABLE = malloc(AMS_ENT * 2 * sizeof(int32_t))) == NULL)
+    if((AMS_TABLE = g_try_new(int32_t, AMS_ENT * 2)) == NULL)
     {
-        free(TL_TABLE);
-        free(SIN_TABLE);
+        g_free(TL_TABLE);
+        g_free(SIN_TABLE);
         return 0;
     }
-    if((VIB_TABLE = malloc(VIB_ENT *2 * sizeof(int32_t))) == NULL)
+    if((VIB_TABLE = g_try_new(int32_t, VIB_ENT * 2)) == NULL)
     {
-        free(TL_TABLE);
-        free(SIN_TABLE);
-        free(AMS_TABLE);
+        g_free(TL_TABLE);
+        g_free(SIN_TABLE);
+        g_free(AMS_TABLE);
+        return 0;
+    }
+    if((ENV_CURVE = g_try_new(int32_t, 2 * EG_ENT + 1)) == NULL)
+    {
+        g_free(TL_TABLE);
+        g_free(SIN_TABLE);
+        g_free(AMS_TABLE);
+        g_free(VIB_TABLE);
         return 0;
     }
-    ENV_CURVE = g_new(int32_t, 2 * EG_ENT + 1);
 	/* make total level table */
 	for (t = 0;t < EG_ENT-1 ;t++){
 		rate = ((1<<TL_BITS)-1)/pow(10,EG_STEP*t/20);	/* dB -> voltage */
@@ -696,10 +703,10 @@ static int OPLOpenTable( void )
 static void OPLCloseTable( void )
 {
     g_free(ENV_CURVE);
-    free(TL_TABLE);
-    free(SIN_TABLE);
-    free(AMS_TABLE);
-    free(VIB_TABLE);
+    g_free(TL_TABLE);
+    g_free(SIN_TABLE);
+    g_free(AMS_TABLE);
+    g_free(VIB_TABLE);
 }
 
 /* CSM Key Control */
@@ -1082,7 +1089,7 @@ FM_OPL *OPLCreate(int clock, int rate)
 	state_size  = sizeof(FM_OPL);
 	state_size += sizeof(OPL_CH)*max_ch;
 	/* allocate memory block */
-    ptr = malloc(state_size);
+    ptr = g_try_malloc(state_size);
 	if(ptr==NULL) return NULL;
 	/* clear */
 	memset(ptr,0,state_size);
@@ -1128,7 +1135,7 @@ void OPLDestroy(FM_OPL *OPL)
 	}
 #endif
 	OPL_UnLockTable();
-    free(OPL);
+    g_free(OPL);
 }
 
 /* ----------  Option handlers ----------       */
Signature · 1 line
2.25.1
#4 lore raw

PATCH 4/9 pc-bios/s390-ccw/netmain.c: Changed a malloc/free to GLib's variants

In reply to Mahmoud Mandour

Changed a call to malloc() and its respective calls free() with GLib's allocation and deallocation functions.

---
 pc-bios/s390-ccw/netmain.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
pc-bios/s390-ccw/netmain.c +3 -3
index 056e93a818..7f78150144 100644
@@ -243,7 +243,7 @@ static const char *get_uuid(void)
     int i, cc, chk = 0;
     static char uuid_str[37];
 
-    mem = malloc(2 * PAGE_SIZE);
+    mem = g_try_malloc(2 * PAGE_SIZE);
     if (!mem) {
         puts("Out of memory ... can not get UUID.");
         return NULL;
@@ -261,7 +261,7 @@ static const char *get_uuid(void)
                  : "d" (r0), "d" (r1), [addr] "a" (buf)
                  : "cc", "memory");
     if (cc) {
-        free(mem);
+        g_free(mem);
         return NULL;
     }
 
@@ -269,7 +269,7 @@ static const char *get_uuid(void)
         uuid[i] = buf[STSI322_VMDB_UUID_OFFSET + i];
         chk |= uuid[i];
     }
-    free(mem);
+    g_free(mem);
     if (!chk) {
         return NULL;
     }
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH 4/9] pc-bios/s390-ccw/netmain.c: Changed a malloc/free to GLib's variants

Quoted 4 lines · Mahmoud Mandour

Changed a call to malloc() and its respective calls free() with GLib's allocation and deallocation functions.

Nack.

This is BIOS code and it does not have glib.

Quoted 36 lines
---
  pc-bios/s390-ccw/netmain.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
pc-bios/s390-ccw/netmain.c +3 -3
index 056e93a818..7f78150144 100644
@@ -243,7 +243,7 @@ static const char *get_uuid(void)
      int i, cc, chk = 0;
      static char uuid_str[37];
 
-    mem = malloc(2 * PAGE_SIZE);
+    mem = g_try_malloc(2 * PAGE_SIZE);
      if (!mem) {
          puts("Out of memory ... can not get UUID.");
          return NULL;
@@ -261,7 +261,7 @@ static const char *get_uuid(void)
                   : "d" (r0), "d" (r1), [addr] "a" (buf)
                   : "cc", "memory");
      if (cc) {
-        free(mem);
+        g_free(mem);
          return NULL;
      }
 
@@ -269,7 +269,7 @@ static const char *get_uuid(void)
          uuid[i] = buf[STSI322_VMDB_UUID_OFFSET + i];
          chk |= uuid[i];
      }
-    free(mem);
+    g_free(mem);
      if (!chk) {
          return NULL;
      }
#6 lore raw

Re: [PATCH 4/9] pc-bios/s390-ccw/netmain.c: Changed a malloc/free to GLib's variants

Quoted 5 lines

Nack.

This is BIOS code and it does not have glib.

Thank you so much for the helping notice. This did not cause build problems nor was mentioned in the bite-sized tasks page as a place to not change. In any case, there are some more problems with this series so I was going to resend it (after amending those problems). Therefore I'm going to exclude this commit.

Quoted 48 lines · Christian Borntraeger
Quoted 4 lines · Mahmoud Mandour

Changed a call to malloc() and its respective calls free() with GLib's allocation and deallocation functions.

Nack.

This is BIOS code and it does not have glib.

Quoted 36 lines
---
  pc-bios/s390-ccw/netmain.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
pc-bios/s390-ccw/netmain.c +3 -3
index 056e93a818..7f78150144 100644
@@ -243,7 +243,7 @@ static const char *get_uuid(void)
      int i, cc, chk = 0;
      static char uuid_str[37];
 
-    mem = malloc(2 * PAGE_SIZE);
+    mem = g_try_malloc(2 * PAGE_SIZE);
      if (!mem) {
          puts("Out of memory ... can not get UUID.");
          return NULL;
@@ -261,7 +261,7 @@ static const char *get_uuid(void)
                   : "d" (r0), "d" (r1), [addr] "a" (buf)
                   : "cc", "memory");
      if (cc) {
-        free(mem);
+        g_free(mem);
          return NULL;
      }
 
@@ -269,7 +269,7 @@ static const char *get_uuid(void)
          uuid[i] = buf[STSI322_VMDB_UUID_OFFSET + i];
          chk |= uuid[i];
      }
-    free(mem);
+    g_free(mem);
      if (!chk) {
          return NULL;
      }
#7 lore raw

PATCH 5/9 target/xtensa: Replaced malloc/free with GLib's variants.

In reply to Mahmoud Mandour

Replaced the calls to malloc() and their respective calls to free() with GLib's allocation and deallocation functions.

---
 target/xtensa/xtensa-isa.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
target/xtensa/xtensa-isa.c +14 -14
index 630b4f9da1..d4f742a67c 100644
@@ -79,7 +79,7 @@ int xtensa_insnbuf_size(xtensa_isa isa)
 xtensa_insnbuf xtensa_insnbuf_alloc(xtensa_isa isa)
 {
     xtensa_insnbuf result = (xtensa_insnbuf)
-        malloc(xtensa_insnbuf_size(isa) * sizeof(xtensa_insnbuf_word));
+        g_try_malloc(xtensa_insnbuf_size(isa) * sizeof(xtensa_insnbuf_word));
 
     CHECK_ALLOC(result, 0);
     return result;
@@ -89,7 +89,7 @@ xtensa_insnbuf xtensa_insnbuf_alloc(xtensa_isa isa)
 void xtensa_insnbuf_free(xtensa_isa isa __attribute__ ((unused)),
                          xtensa_insnbuf buf)
 {
-    free(buf);
+    g_free(buf);
 }
 
 
@@ -237,7 +237,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
 
     /* Set up the opcode name lookup table. */
     isa->opname_lookup_table =
-        malloc(isa->num_opcodes * sizeof(xtensa_lookup_entry));
+        g_try_new(xtensa_lookup_entry, isa->num_opcodes);
     CHECK_ALLOC_FOR_INIT(isa->opname_lookup_table, NULL, errno_p, error_msg_p);
     for (n = 0; n < isa->num_opcodes; n++) {
         isa->opname_lookup_table[n].key = isa->opcodes[n].name;
@@ -248,7 +248,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
 
     /* Set up the state name lookup table. */
     isa->state_lookup_table =
-        malloc(isa->num_states * sizeof(xtensa_lookup_entry));
+        g_try_new(xtensa_lookup_entry, isa->num_states);
     CHECK_ALLOC_FOR_INIT(isa->state_lookup_table, NULL, errno_p, error_msg_p);
     for (n = 0; n < isa->num_states; n++) {
         isa->state_lookup_table[n].key = isa->states[n].name;
@@ -259,7 +259,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
 
     /* Set up the sysreg name lookup table. */
     isa->sysreg_lookup_table =
-        malloc(isa->num_sysregs * sizeof(xtensa_lookup_entry));
+        g_try_new(xtensa_lookup_entry, isa->num_sysregs);
     CHECK_ALLOC_FOR_INIT(isa->sysreg_lookup_table, NULL, errno_p, error_msg_p);
     for (n = 0; n < isa->num_sysregs; n++) {
         isa->sysreg_lookup_table[n].key = isa->sysregs[n].name;
@@ -271,7 +271,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
     /* Set up the user & system sysreg number tables. */
     for (is_user = 0; is_user < 2; is_user++) {
         isa->sysreg_table[is_user] =
-            malloc((isa->max_sysreg_num[is_user] + 1) * sizeof(xtensa_sysreg));
+            g_try_new(xtensa_sysreg, isa->max_sysreg_num[is_user] + 1);
         CHECK_ALLOC_FOR_INIT(isa->sysreg_table[is_user], NULL,
                              errno_p, error_msg_p);
 
@@ -290,7 +290,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
 
     /* Set up the interface lookup table. */
     isa->interface_lookup_table =
-        malloc(isa->num_interfaces * sizeof(xtensa_lookup_entry));
+        g_try_new(xtensa_lookup_entry, isa->num_interfaces);
     CHECK_ALLOC_FOR_INIT(isa->interface_lookup_table, NULL, errno_p,
                          error_msg_p);
     for (n = 0; n < isa->num_interfaces; n++) {
@@ -302,7 +302,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
 
     /* Set up the funcUnit lookup table. */
     isa->funcUnit_lookup_table =
-        malloc(isa->num_funcUnits * sizeof(xtensa_lookup_entry));
+        g_try_new(xtensa_lookup_entry, isa->num_funcUnits);
     CHECK_ALLOC_FOR_INIT(isa->funcUnit_lookup_table, NULL, errno_p,
                          error_msg_p);
     for (n = 0; n < isa->num_funcUnits; n++) {
@@ -333,33 +333,33 @@ void xtensa_isa_free(xtensa_isa isa)
      */
 
     if (intisa->opname_lookup_table) {
-        free(intisa->opname_lookup_table);
+        g_free(intisa->opname_lookup_table);
         intisa->opname_lookup_table = 0;
     }
 
     if (intisa->state_lookup_table) {
-        free(intisa->state_lookup_table);
+        g_free(intisa->state_lookup_table);
         intisa->state_lookup_table = 0;
     }
 
     if (intisa->sysreg_lookup_table) {
-        free(intisa->sysreg_lookup_table);
+        g_free(intisa->sysreg_lookup_table);
         intisa->sysreg_lookup_table = 0;
     }
     for (n = 0; n < 2; n++) {
         if (intisa->sysreg_table[n]) {
-            free(intisa->sysreg_table[n]);
+            g_free(intisa->sysreg_table[n]);
             intisa->sysreg_table[n] = 0;
         }
     }
 
     if (intisa->interface_lookup_table) {
-        free(intisa->interface_lookup_table);
+        g_free(intisa->interface_lookup_table);
         intisa->interface_lookup_table = 0;
     }
 
     if (intisa->funcUnit_lookup_table) {
-        free(intisa->funcUnit_lookup_table);
+        g_free(intisa->funcUnit_lookup_table);
         intisa->funcUnit_lookup_table = 0;
     }
 }
Signature · 1 line
2.25.1
#8 lore raw

PATCH 6/9 util/compatfd.c: Replaced a malloc with GLib's g_try_malloc

In reply to Mahmoud Mandour

Replaced a malloc() call and its respective free() call with GLib's g_try_malloc() and g_free(). Also, did slight styling changes that were producing errors using the checkpatch.pl script.

---
 util/compatfd.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
util/compatfd.c +5 -5
index ee47dd8089..834ddd0573 100644
@@ -20,8 +20,7 @@
 #include <sys/syscall.h>
 #endif
 
-struct sigfd_compat_info
-{
+struct sigfd_compat_info {
     sigset_t mask;
     int fd;
 };
@@ -53,8 +52,9 @@ static void *sigwait_compat(void *opaque)
 
                 len = write(info->fd, (char *)&buffer + offset,
                             sizeof(buffer) - offset);
-                if (len == -1 && errno == EINTR)
+                if (len == -1 && errno == EINTR) {
                     continue;
+                }
 
                 if (len <= 0) {
                     return NULL;
@@ -72,14 +72,14 @@ static int qemu_signalfd_compat(const sigset_t *mask)
     QemuThread thread;
     int fds[2];
 
-    info = malloc(sizeof(*info));
+    info = g_try_malloc(sizeof(*info));
     if (info == NULL) {
         errno = ENOMEM;
         return -1;
     }
 
     if (pipe(fds) == -1) {
-        free(info);
+        g_free(info);
         return -1;
     }
 
Signature · 1 line
2.25.1
#9 lore raw

PATCH 7/9 tools/virtiofsd/buffer.c: replaced a calloc call with GLib's g_try_new0

In reply to Mahmoud Mandour

Replaced a call to calloc() and its respective free() call with GLib's g_try_new0() and g_free() calls.

---
 tools/virtiofsd/buffer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/virtiofsd/buffer.c +2 -2
index 874f01c488..b5f04be356 100644
@@ -37,7 +37,7 @@ static ssize_t fuse_buf_writev(struct fuse_buf *out_buf,
     struct iovec *iov;
     int fd = out_buf->fd;
 
-    iov = calloc(iovcnt, sizeof(struct iovec));
+    iov = g_try_new0(struct iovec, iovcnt);
     if (!iov) {
         return -ENOMEM;
     }
@@ -61,7 +61,7 @@ static ssize_t fuse_buf_writev(struct fuse_buf *out_buf,
         res = -errno;
     }
 
-    free(iov);
+    g_free(iov);
     return res;
 }
 
Signature · 1 line
2.25.1
#10 lore raw

PATCH 8/9 tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc

In reply to Mahmoud Mandour

Replaced a malloc() call and its respective free() with GLib's g_try_malloc() and g_free() calls.

---
 tools/virtiofsd/fuse_opt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/virtiofsd/fuse_opt.c +2 -2
index f0ab8d22f4..9d371448e9 100644
@@ -272,7 +272,7 @@ static int process_opt_sep_arg(struct fuse_opt_context *ctx,
     }
 
     param = ctx->argv[ctx->argctr];
-    newarg = malloc(sep + strlen(param) + 1);
+    newarg = g_try_malloc(sep + strlen(param) + 1);
     if (!newarg) {
         return alloc_failed();
     }
@@ -280,7 +280,7 @@ static int process_opt_sep_arg(struct fuse_opt_context *ctx,
     memcpy(newarg, arg, sep);
     strcpy(newarg + sep, param);
     res = process_opt(ctx, opt, sep, newarg, iso);
-    free(newarg);
+    g_free(newarg);
 
     return res;
 }
Signature · 1 line
2.25.1
#11 lore raw

PATCH 9/9 tools/virtiofsd: Replacing malloc-like calls with GLib's variants

In reply to Mahmoud Mandour

Changed calls to malloc(), calloc(), and realloc() with their equivalent allocation functions in GLib, and replaced their respective free() calls with g_free().

Allocation and deallocation of fuse_req structs, fuse_pollhandle structs, fuse_session structs and many local variables are now established through GLib's functions.

---
 tools/virtiofsd/fuse_lowlevel.c  | 30 ++++++++++++++--------------
 tools/virtiofsd/fuse_virtio.c    | 34 ++++++++++++++++----------------
 tools/virtiofsd/passthrough_ll.c | 32 +++++++++++++++---------------
 3 files changed, 48 insertions(+), 48 deletions(-)
tools/virtiofsd/fuse_lowlevel.c +15 -15
index 1aa26c6333..5e188f8d8f 100644
@@ -106,7 +106,7 @@ static void list_add_req(struct fuse_req *req, struct fuse_req *next)
 static void destroy_req(fuse_req_t req)
 {
     pthread_mutex_destroy(&req->lock);
-    free(req);
+    g_free(req);
 }
 
 void fuse_free_req(fuse_req_t req)
@@ -130,7 +130,7 @@ static struct fuse_req *fuse_ll_alloc_req(struct fuse_session *se)
 {
     struct fuse_req *req;
 
-    req = (struct fuse_req *)calloc(1, sizeof(struct fuse_req));
+    req = g_try_new(struct fuse_req, 1);
     if (req == NULL) {
         fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate request\n");
     } else {
@@ -219,7 +219,7 @@ int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count)
     int res;
     struct iovec *padded_iov;
 
-    padded_iov = malloc((count + 1) * sizeof(struct iovec));
+    padded_iov = g_try_new(struct iovec, count + 1);
     if (padded_iov == NULL) {
         return fuse_reply_err(req, ENOMEM);
     }
@@ -228,7 +228,7 @@ int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count)
     count++;
 
     res = send_reply_iov(req, 0, padded_iov, count);
-    free(padded_iov);
+    g_free(padded_iov);
 
     return res;
 }
@@ -568,7 +568,7 @@ static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(const struct iovec *iov,
     struct fuse_ioctl_iovec *fiov;
     size_t i;
 
-    fiov = malloc(sizeof(fiov[0]) * count);
+    fiov = g_try_new(struct fuse_ioctl_iovec, count);
     if (!fiov) {
         return NULL;
     }
@@ -629,8 +629,8 @@ int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov,
 
     res = send_reply_iov(req, 0, iov, count);
 out:
-    free(in_fiov);
-    free(out_fiov);
+    g_free(in_fiov);
+    g_free(out_fiov);
 
     return res;
 
@@ -667,7 +667,7 @@ int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
     struct fuse_ioctl_out arg;
     int res;
 
-    padded_iov = malloc((count + 2) * sizeof(struct iovec));
+    padded_iov = g_try_new(struct iovec, count + 2);
     if (padded_iov == NULL) {
         return fuse_reply_err(req, ENOMEM);
     }
@@ -680,7 +680,7 @@ int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
     memcpy(&padded_iov[2], iov, count * sizeof(struct iovec));
 
     res = send_reply_iov(req, 0, padded_iov, count + 2);
-    free(padded_iov);
+    g_free(padded_iov);
 
     return res;
 }
@@ -1684,7 +1684,7 @@ static struct fuse_req *check_interrupt(struct fuse_session *se,
         if (curr->u.i.unique == req->unique) {
             req->interrupted = 1;
             list_del_req(curr);
-            free(curr);
+            g_free(curr);
             return NULL;
         }
     }
@@ -1760,7 +1760,7 @@ static void do_ioctl(fuse_req_t req, fuse_ino_t nodeid,
 
 void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
 {
-    free(ph);
+    g_free(ph);
 }
 
 static void do_poll(fuse_req_t req, fuse_ino_t nodeid,
@@ -1783,7 +1783,7 @@ static void do_poll(fuse_req_t req, fuse_ino_t nodeid,
         struct fuse_pollhandle *ph = NULL;
 
         if (arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) {
-            ph = malloc(sizeof(struct fuse_pollhandle));
+            ph = g_try_new(struct fuse_pollhandle, 1);
             if (ph == NULL) {
                 fuse_reply_err(req, ENOMEM);
                 return;
@@ -2476,7 +2476,7 @@ void fuse_session_destroy(struct fuse_session *se)
     free(se->vu_socket_path);
     se->vu_socket_path = NULL;
 
-    free(se);
+    g_free(se);
 }
 
 
@@ -2499,7 +2499,7 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
         return NULL;
     }
 
-    se = (struct fuse_session *)calloc(1, sizeof(struct fuse_session));
+    se = g_try_new0(struct fuse_session, 1);
     if (se == NULL) {
         fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate fuse object\n");
         goto out1;
@@ -2559,7 +2559,7 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
 out4:
     fuse_opt_free_args(args);
 out2:
-    free(se);
+    g_free(se);
 out1:
     return NULL;
 }
tools/virtiofsd/fuse_virtio.c +17 -17
index 523ee64fb7..598c97db1f 100644
@@ -347,7 +347,7 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
      * Build a copy of the the in_sg iov so we can skip bits in it,
      * including changing the offsets
      */
-    struct iovec *in_sg_cpy = calloc(sizeof(struct iovec), in_num);
+    struct iovec *in_sg_cpy = g_try_new0(struct iovec, in_num);
     assert(in_sg_cpy);
     memcpy(in_sg_cpy, in_sg, sizeof(struct iovec) * in_num);
     /* These get updated as we skip */
@@ -386,7 +386,7 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
             ret = errno;
             fuse_log(FUSE_LOG_DEBUG, "%s: preadv failed (%m) len=%zd\n",
                      __func__, len);
-            free(in_sg_cpy);
+            g_free(in_sg_cpy);
             goto err;
         }
         fuse_log(FUSE_LOG_DEBUG, "%s: preadv ret=%d len=%zd\n", __func__,
@@ -410,13 +410,13 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
         if (ret != len) {
             fuse_log(FUSE_LOG_DEBUG, "%s: ret!=len\n", __func__);
             ret = EIO;
-            free(in_sg_cpy);
+            g_free(in_sg_cpy);
             goto err;
         }
         in_sg_left -= ret;
         len -= ret;
     } while (in_sg_left);
-    free(in_sg_cpy);
+    g_free(in_sg_cpy);
 
     /* Need to fix out->len on EOF */
     if (len) {
@@ -476,7 +476,7 @@ static void fv_queue_worker(gpointer data, gpointer user_data)
      * They're spread over multiple descriptors in a scatter/gather set
      * and we can't trust the guest to keep them still; so copy in/out.
      */
-    fbuf.mem = malloc(se->bufsize);
+    fbuf.mem = g_try_malloc(se->bufsize);
     assert(fbuf.mem);
 
     fuse_mutex_init(&req->ch.lock);
@@ -528,10 +528,10 @@ static void fv_queue_worker(gpointer data, gpointer user_data)
         fbuf.size = out_sg[0].iov_len + out_sg[1].iov_len;
 
         /* Allocate the bufv, with space for the rest of the iov */
-        pbufv = malloc(sizeof(struct fuse_bufvec) +
+        pbufv = g_try_malloc(sizeof(struct fuse_bufvec) +
                        sizeof(struct fuse_buf) * (out_num - 2));
         if (!pbufv) {
-            fuse_log(FUSE_LOG_ERR, "%s: pbufv malloc failed\n",
+            fuse_log(FUSE_LOG_ERR, "%s: pbufv g_try_malloc failed\n",
                     __func__);
             goto out;
         }
@@ -573,7 +573,7 @@ static void fv_queue_worker(gpointer data, gpointer user_data)
 
 out:
     if (allocated_bufv) {
-        free(pbufv);
+        g_free(pbufv);
     }
 
     /* If the request has no reply, still recycle the virtqueue element */
@@ -592,8 +592,8 @@ out:
     }
 
     pthread_mutex_destroy(&req->ch.lock);
-    free(fbuf.mem);
-    free(req);
+    g_free(fbuf.mem);
+    g_free(req);
 }
 
 /* Thread function for individual queues, created when a queue is 'started' */
@@ -733,7 +733,7 @@ static void fv_queue_cleanup_thread(struct fv_VuDev *vud, int qidx)
     pthread_mutex_destroy(&ourqi->vq_lock);
     close(ourqi->kill_fd);
     ourqi->kick_fd = -1;
-    free(vud->qi[qidx]);
+    g_free(vud->qi[qidx]);
     vud->qi[qidx] = NULL;
 }
 
@@ -764,14 +764,14 @@ static void fv_queue_set_started(VuDev *dev, int qidx, bool started)
     if (started) {
         /* Fire up a thread to watch this queue */
         if (qidx >= vud->nqueues) {
-            vud->qi = realloc(vud->qi, (qidx + 1) * sizeof(vud->qi[0]));
+            vud->qi = g_try_realloc_n(vud->qi, (qidx + 1), sizeof(vud->qi[0]));
             assert(vud->qi);
             memset(vud->qi + vud->nqueues, 0,
                    sizeof(vud->qi[0]) * (1 + (qidx - vud->nqueues)));
             vud->nqueues = qidx + 1;
         }
         if (!vud->qi[qidx]) {
-            vud->qi[qidx] = calloc(sizeof(struct fv_QueueInfo), 1);
+            vud->qi[qidx] = g_try_new0(struct fv_QueueInfo, 1);
             assert(vud->qi[qidx]);
             vud->qi[qidx]->virtio_dev = vud;
             vud->qi[qidx]->qidx = qidx;
@@ -1032,9 +1032,9 @@ int virtio_session_mount(struct fuse_session *se)
              __func__);
 
     /* TODO: Some cleanup/deallocation! */
-    se->virtio_dev = calloc(sizeof(struct fv_VuDev), 1);
+    se->virtio_dev = g_try_new0(struct fv_VuDev, 1);
     if (!se->virtio_dev) {
-        fuse_log(FUSE_LOG_ERR, "%s: virtio_dev calloc failed\n", __func__);
+        fuse_log(FUSE_LOG_ERR, "%s: virtio_dev g_try_new0 failed\n", __func__);
         close(data_sock);
         return -1;
     }
@@ -1059,8 +1059,8 @@ void virtio_session_close(struct fuse_session *se)
         return;
     }
 
-    free(se->virtio_dev->qi);
+    g_free(se->virtio_dev->qi);
     pthread_rwlock_destroy(&se->virtio_dev->vu_dispatch_rwlock);
-    free(se->virtio_dev);
+    g_free(se->virtio_dev);
     se->virtio_dev = NULL;
 }
tools/virtiofsd/passthrough_ll.c +16 -16
index fc7e1b1e8e..5c475a30af 100644
@@ -399,7 +399,7 @@ static void lo_map_init(struct lo_map *map)
 
 static void lo_map_destroy(struct lo_map *map)
 {
-    free(map->elems);
+    g_free(map->elems);
 }
 
 static int lo_map_grow(struct lo_map *map, size_t new_nelems)
@@ -411,7 +411,7 @@ static int lo_map_grow(struct lo_map *map, size_t new_nelems)
         return 1;
     }
 
-    new_elems = realloc(map->elems, sizeof(map->elems[0]) * new_nelems);
+    new_elems = g_realloc_n(map->elems, new_nelems, sizeof(map->elems[0]));
     if (!new_elems) {
         return 0;
     }
@@ -549,7 +549,7 @@ static void lo_inode_put(struct lo_data *lo, struct lo_inode **inodep)
 
     if (g_atomic_int_dec_and_test(&inode->refcount)) {
         close(inode->fd);
-        free(inode);
+        g_free(inode);
     }
 }
 
@@ -904,7 +904,7 @@ static void posix_locks_value_destroy(gpointer data)
      * closing this fd should release all OFD locks.
      */
     close(plock->fd);
-    free(plock);
+    g_free(plock);
 }
 
 static int do_statx(struct lo_data *lo, int dirfd, const char *pathname,
@@ -1020,7 +1020,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
     if (inode) {
         close(newfd);
     } else {
-        inode = calloc(1, sizeof(struct lo_inode));
+        inode = g_try_new0(struct lo_inode, 1);
         if (!inode) {
             goto out_err;
         }
@@ -1532,7 +1532,7 @@ static void lo_dirp_put(struct lo_dirp **dp)
 
     if (g_atomic_int_dec_and_test(&d->refcount)) {
         closedir(d->dp);
-        free(d);
+        g_free(d);
     }
 }
 
@@ -1564,7 +1564,7 @@ static void lo_opendir(fuse_req_t req, fuse_ino_t ino,
     int fd;
     ssize_t fh;
 
-    d = calloc(1, sizeof(struct lo_dirp));
+    d = g_try_new0(struct lo_dirp, 1);
     if (d == NULL) {
         goto out_err;
     }
@@ -1606,7 +1606,7 @@ out_err:
         } else if (fd != -1) {
             close(fd);
         }
-        free(d);
+        g_free(d);
     }
     fuse_reply_err(req, error);
 }
@@ -1633,7 +1633,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
     }
 
     err = ENOMEM;
-    buf = calloc(1, size);
+    buf = g_try_malloc0(size);
     if (!buf) {
         goto error;
     }
@@ -1719,7 +1719,7 @@ error:
     } else {
         fuse_reply_buf(req, buf, size - rem);
     }
-    free(buf);
+    g_free(buf);
 }
 
 static void lo_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
@@ -1943,7 +1943,7 @@ static struct lo_inode_plock *lookup_create_plock_ctx(struct lo_data *lo,
         return plock;
     }
 
-    plock = malloc(sizeof(struct lo_inode_plock));
+    plock = g_try_new(struct lo_inode_plock, 1);
     if (!plock) {
         *err = ENOMEM;
         return NULL;
@@ -1954,7 +1954,7 @@ static struct lo_inode_plock *lookup_create_plock_ctx(struct lo_data *lo,
     fd = lo_inode_open(lo, inode, O_RDWR);
     if (fd < 0) {
         *err = -fd;
-        free(plock);
+        g_free(plock);
         return NULL;
     }
 
@@ -2731,7 +2731,7 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name,
              ino, name, size);
 
     if (size) {
-        value = malloc(size);
+        value = g_try_malloc(size);
         if (!value) {
             goto out_err;
         }
@@ -2770,7 +2770,7 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name,
         fuse_reply_xattr(req, ret);
     }
 out_free:
-    free(value);
+    g_free(value);
 
     if (fd >= 0) {
         close(fd);
@@ -2812,7 +2812,7 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size)
              size);
 
     if (size) {
-        value = malloc(size);
+        value = g_try_malloc(size);
         if (!value) {
             goto out_err;
         }
@@ -2897,7 +2897,7 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size)
         fuse_reply_xattr(req, ret);
     }
 out_free:
-    free(value);
+    g_free(value);
 
     if (fd >= 0) {
         close(fd);
Signature · 1 line
2.25.1
#12 lore raw
In reply to Mahmoud Mandour
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [PATCH 0/9] Replacing malloc and the like with GLib's variants

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
a6a3a12 tools/virtiofsd: Replacing malloc-like calls with GLib's variants 159f751 tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc b2cf8da tools/virtiofsd/buffer.c: replaced a calloc call with GLib's g_try_new0 5d20862 util/compatfd.c: Replaced a malloc with GLib's g_try_malloc 6a11f79 target/xtensa: Replaced malloc/free with GLib's variants. 7169f27 pc-bios/s390-ccw/netmain.c: Changed a malloc/free to GLib's variants 836befe hw/audio/fmopl.c: Replaced calls to malloc with GLib's variants fb66b78 hw/audio/fmopl.c: Fixing some style errors.
ded3f81 bsd-user/elfload.c: Replaced calls to malloc/free with GLib variants

=== OUTPUT BEGIN ===
1/9 Checking commit ded3f81fd71b (bsd-user/elfload.c: Replaced calls to malloc/free with GLib variants) 2/9 Checking commit fb66b785f597 (hw/audio/fmopl.c: Fixing some style errors.)
ERROR: space required before the open parenthesis '('
#44: FILE: hw/audio/fmopl.c:610:
+ if((TL_TABLE = malloc(TL_MAX * 2 * sizeof(int32_t))) == NULL)

ERROR: do not use assignment in if condition
#44: FILE: hw/audio/fmopl.c:610:
+ if((TL_TABLE = malloc(TL_MAX * 2 * sizeof(int32_t))) == NULL)

ERROR: braces {} are necessary for all arms of this statement #44: FILE: hw/audio/fmopl.c:610:
+ if((TL_TABLE = malloc(TL_MAX * 2 * sizeof(int32_t))) == NULL)
[...]

ERROR: that open brace { should be on the previous line #46: FILE: hw/audio/fmopl.c:612:
+ if((SIN_TABLE = malloc(SIN_ENT * 4 *sizeof(int32_t *))) == NULL)
+ {

ERROR: spaces required around that '*' (ctx:WxV)
#46: FILE: hw/audio/fmopl.c:612:
+ if((SIN_TABLE = malloc(SIN_ENT * 4 *sizeof(int32_t *))) == NULL)

                                        ^

ERROR: space required before the open parenthesis '(' #46: FILE: hw/audio/fmopl.c:612:
+ if((SIN_TABLE = malloc(SIN_ENT * 4 *sizeof(int32_t *))) == NULL)

ERROR: do not use assignment in if condition
#46: FILE: hw/audio/fmopl.c:612:
+ if((SIN_TABLE = malloc(SIN_ENT * 4 *sizeof(int32_t *))) == NULL)

ERROR: that open brace { should be on the previous line #51: FILE: hw/audio/fmopl.c:617:
+ if((AMS_TABLE = malloc(AMS_ENT * 2 * sizeof(int32_t))) == NULL)
+ {

ERROR: space required before the open parenthesis '(' #51: FILE: hw/audio/fmopl.c:617:
+ if((AMS_TABLE = malloc(AMS_ENT * 2 * sizeof(int32_t))) == NULL)

ERROR: do not use assignment in if condition
#51: FILE: hw/audio/fmopl.c:617:
+ if((AMS_TABLE = malloc(AMS_ENT * 2 * sizeof(int32_t))) == NULL)

ERROR: that open brace { should be on the previous line #57: FILE: hw/audio/fmopl.c:623:
+ if((VIB_TABLE = malloc(VIB_ENT *2 * sizeof(int32_t))) == NULL)
+ {

ERROR: spaces required around that '*' (ctx:WxV)
#57: FILE: hw/audio/fmopl.c:623:
+ if((VIB_TABLE = malloc(VIB_ENT *2 * sizeof(int32_t))) == NULL)

                                    ^

ERROR: space required before the open parenthesis '(' #57: FILE: hw/audio/fmopl.c:623:
+ if((VIB_TABLE = malloc(VIB_ENT *2 * sizeof(int32_t))) == NULL)

ERROR: do not use assignment in if condition
#57: FILE: hw/audio/fmopl.c:623:
+ if((VIB_TABLE = malloc(VIB_ENT *2 * sizeof(int32_t))) == NULL)

total: 14 errors, 0 warnings, 76 lines checked

Patch 2/9 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

3/9 Checking commit 836befe9f057 (hw/audio/fmopl.c: Replaced calls to malloc with GLib's variants)
ERROR: space required before the open parenthesis '('
#29: FILE: hw/audio/fmopl.c:610:
+ if((TL_TABLE = g_try_new(int32_t, TL_MAX * 2)) == NULL)

ERROR: do not use assignment in if condition
#29: FILE: hw/audio/fmopl.c:610:
+ if((TL_TABLE = g_try_new(int32_t, TL_MAX * 2)) == NULL)

ERROR: braces {} are necessary for all arms of this statement #29: FILE: hw/audio/fmopl.c:610:
+ if((TL_TABLE = g_try_new(int32_t, TL_MAX * 2)) == NULL)
[...]

ERROR: space required before the open parenthesis '(' #32: FILE: hw/audio/fmopl.c:612:
+ if((SIN_TABLE = g_try_new(int32_t *, SIN_ENT * 4)) == NULL)

ERROR: do not use assignment in if condition
#32: FILE: hw/audio/fmopl.c:612:
+ if((SIN_TABLE = g_try_new(int32_t *, SIN_ENT * 4)) == NULL)

ERROR: space required before the open parenthesis '(' #39: FILE: hw/audio/fmopl.c:617:
+ if((AMS_TABLE = g_try_new(int32_t, AMS_ENT * 2)) == NULL)

ERROR: do not use assignment in if condition
#39: FILE: hw/audio/fmopl.c:617:
+ if((AMS_TABLE = g_try_new(int32_t, AMS_ENT * 2)) == NULL)

ERROR: space required before the open parenthesis '(' #48: FILE: hw/audio/fmopl.c:623:
+ if((VIB_TABLE = g_try_new(int32_t, VIB_ENT * 2)) == NULL)

ERROR: do not use assignment in if condition
#48: FILE: hw/audio/fmopl.c:623:
+ if((VIB_TABLE = g_try_new(int32_t, VIB_ENT * 2)) == NULL)

ERROR: that open brace { should be on the previous line #58: FILE: hw/audio/fmopl.c:630:
+ if((ENV_CURVE = g_try_new(int32_t, 2 * EG_ENT + 1)) == NULL)
+ {

ERROR: space required before the open parenthesis '(' #58: FILE: hw/audio/fmopl.c:630:
+ if((ENV_CURVE = g_try_new(int32_t, 2 * EG_ENT + 1)) == NULL)

ERROR: do not use assignment in if condition
#58: FILE: hw/audio/fmopl.c:630:
+ if((ENV_CURVE = g_try_new(int32_t, 2 * EG_ENT + 1)) == NULL)

total: 12 errors, 0 warnings, 75 lines checked

Patch 3/9 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

4/9 Checking commit 7169f277a76a (pc-bios/s390-ccw/netmain.c: Changed a malloc/free to GLib's variants) 5/9 Checking commit 6a11f79ebba6 (target/xtensa: Replaced malloc/free with GLib's variants.)
ERROR: g_free(NULL) is safe this check is probably not required
#97: FILE: target/xtensa/xtensa-isa.c:336:

     if (intisa->opname_lookup_table) {

+ g_free(intisa->opname_lookup_table);

ERROR: g_free(NULL) is safe this check is probably not required #103: FILE: target/xtensa/xtensa-isa.c:341:

     if (intisa->state_lookup_table) {

+ g_free(intisa->state_lookup_table);

ERROR: g_free(NULL) is safe this check is probably not required #109: FILE: target/xtensa/xtensa-isa.c:346:

     if (intisa->sysreg_lookup_table) {

+ g_free(intisa->sysreg_lookup_table);

ERROR: g_free(NULL) is safe this check is probably not required #115: FILE: target/xtensa/xtensa-isa.c:351:

         if (intisa->sysreg_table[n]) {

+ g_free(intisa->sysreg_table[n]);

ERROR: g_free(NULL) is safe this check is probably not required #122: FILE: target/xtensa/xtensa-isa.c:357:

     if (intisa->interface_lookup_table) {

+ g_free(intisa->interface_lookup_table);

ERROR: g_free(NULL) is safe this check is probably not required #128: FILE: target/xtensa/xtensa-isa.c:362:

     if (intisa->funcUnit_lookup_table) {

+ g_free(intisa->funcUnit_lookup_table);

total: 6 errors, 0 warnings, 103 lines checked

Patch 5/9 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

6/9 Checking commit 5d208628105b (util/compatfd.c: Replaced a malloc with GLib's g_try_malloc) 7/9 Checking commit b2cf8da37f0e (tools/virtiofsd/buffer.c: replaced a calloc call with GLib's g_try_new0) 8/9 Checking commit 159f751ac549 (tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc) 9/9 Checking commit a6a3a12373a3 (tools/virtiofsd: Replacing malloc-like calls with GLib's variants) === OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]