[PATCH 0/9] Replacing malloc and the like with GLib's variants

Mahmoud Mandour posted 9 patches 3 years, 1 month ago
Test checkpatch failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20210313163653.37089-1-ma.mandourr@gmail.com
Maintainers: Stefan Hajnoczi <stefanha@redhat.com>, Christian Borntraeger <borntraeger@de.ibm.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Kyle Evans <kevans@freebsd.org>, Max Filippov <jcmvbkbc@gmail.com>, Thomas Huth <thuth@redhat.com>, Warner Losh <imp@bsdimp.com>, Gerd Hoffmann <kraxel@redhat.com>, Cornelia Huck <cohuck@redhat.com>
There is a newer version of this series
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(-)
[PATCH 0/9] Replacing malloc and the like with GLib's variants
Posted by Mahmoud Mandour 3 years, 1 month ago
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(-)

-- 
2.25.1


Re: [PATCH 0/9] Replacing malloc and the like with GLib's variants
Posted by no-reply@patchew.org 3 years, 1 month ago
Patchew URL: https://patchew.org/QEMU/20210313163653.37089-1-ma.mandourr@gmail.com/



Hi,

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

Type: series
Message-id: 20210313163653.37089-1-ma.mandourr@gmail.com
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/20210313094747.2966948-1-laurent@vivier.eu -> patchew/20210313094747.2966948-1-laurent@vivier.eu
 * [new tag]         patchew/20210313163653.37089-1-ma.mandourr@gmail.com -> patchew/20210313163653.37089-1-ma.mandourr@gmail.com
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/20210313163653.37089-1-ma.mandourr@gmail.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com