Skip to contentSkip to conversation

Fix some GCC warnings

PATCH In review Rodrigo Siqueira 2 participants 6 messages Jul 29, 2018 – Aug 20, 2018

lore
Share & tools
lore
#0 lore raw

v2 cover Fix some GCC warnings

During the compilation, some GCC (8.1) warnings are shown. This patchset address some of the warnings problems.

Changes since v2:
- Reduce the total amount of bytes allocated during command handling operation
- Remove unnecessary memset operation
- Improved commit message

Rodrigo Siqueira (2):
Make string commands dynamic allocate
Fix truncate string in the snprintf

 tools/intel_gvtg_test.c | 25 ++++++++++++++++---------
 tools/intel_reg.c       |  2 +-
 2 files changed, 17 insertions(+), 10 deletions(-)
Signature · 6 lines
2.17.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#1 lore raw

PATCH v2 1/2 Make string commands dynamic allocate

This patch fix the following GCC warning:

intel_gvtg_test.c: In function ‘create_guest’:
intel_gvtg_test.c:127:50: warning: ‘%s’ directive writing up to 4095 bytes into a region of size 4077 [-Wformat-overflow=] [..]
intel_gvtg_test.c:127:5: note: ‘sprintf’ output between 36 and 8226 bytes into a destination of size 4096
[..]

This patch changes the approach for allocating memory to handle QEMU commands by dynamically allocate space to save the whole command.

Changes since v1:
Arkadiusz Hiler:
- Remove overkill allocation for handling commands
- Remove unnecessary use of memset

---
 tools/intel_gvtg_test.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
tools/intel_gvtg_test.c +16 -9
index 659b7956..ad5ee6a6 100644
@@ -120,16 +120,23 @@ static int check_tools(void)
 
 static void create_guest(void)
 {
-    char create_qcow_cmd[PATH_MAX] = {0};
-    char create_vgpu_cmd[PATH_MAX] = {0};
-    char create_instance_cmd[PATH_MAX] = {0};
+    unsigned int max_size_cmd = 4 * PATH_MAX;
+    char *command;
 
-    sprintf(create_qcow_cmd, "qemu-img create -b %s -f qcow2 %s.qcow2",
+    command = malloc(max_size_cmd);
+    if (!command)
+        return;
+
+    sprintf(command, "qemu-img create -b %s -f qcow2 %s.qcow2",
             hda_path, hda_path);
-    sprintf(create_vgpu_cmd, "echo \"%s\" > /sys/bus/pci/devices/0000:00:02.0/"
+    igt_assert_eq(system(command), 0);
+
+    sprintf(command, "echo \"%s\" > /sys/bus/pci/devices/0000:00:02.0/"
            "mdev_supported_types/$(ls /sys/bus/pci/devices/0000:00:02.0/"
            "mdev_supported_types |awk {'print $1'}|tail -1)/create", uuid);
-    sprintf(create_instance_cmd, "%s -m 2048 -smp 2 -M pc -name gvtg_guest"
+    igt_assert_eq(system(command), 0);
+
+    sprintf(command, "%s -m 2048 -smp 2 -M pc -name gvtg_guest"
            " -hda %s.qcow2 -bios %s -enable-kvm --net nic,macaddr=%s -net"
            " tap,script=/etc/qemu-ifup -vga cirrus -k en-us"
            " -serial stdio -vnc :1 -machine kernel_irqchip=on -global"
@@ -137,9 +144,9 @@ static void create_guest(void)
            " -usb -usbdevice tablet -device vfio-pci,sysfsdev="
            "/sys/bus/pci/devices/0000:00:02.0/%s &",
            qemu_path, hda_path, bios_path, mac_addr, uuid);
-    igt_assert_eq(system(create_qcow_cmd), 0);
-    igt_assert_eq(system(create_vgpu_cmd), 0);
-    igt_assert_eq(system(create_instance_cmd), 0);
+    igt_assert_eq(system(command), 0);
+
+    free(command);
 }
 
 static void destroy_all_guest(void)
Signature · 6 lines
2.17.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH v2 2/2 Fix truncate string in the snprintf

In reply to Rodrigo Siqueira

This patch fix the following GCC warning:

../tools/intel_reg.c: In function ‘dump_decode’:
../tools/intel_reg.c:203:41: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
snprintf(decode, sizeof(decode), "\n%s", bin);
[..]
../tools/intel_reg.c:200:40: warning: ‘%s’ directive output may be truncated writing up to 1023 bytes into a region of size 1022 [-Wformat-truncation=]

    snprintf(decode, sizeof(decode), " (%s)\n%s", tmp, bin);
[..]
../tools/intel_reg.c:200:4: note: ‘snprintf’ output between 5 and 2051
bytes into a destination of size 1024
    snprintf(decode, sizeof(decode), " (%s)\n%s", tmp, bin);

[..]

Notice that snprintf writes in the decode variable the values from tmp and bin. These two variables together have 2048 bytes and some extra characters added by snprintf, this commit changed the size of decode to support the combination.

Changes since V1:
- Improve commit message

---
 tools/intel_reg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/intel_reg.c +1 -1
index ddff2794..15ebb86a 100644
@@ -180,7 +180,7 @@ static void to_binary(char *buf, size_t buflen, uint32_t val)
 
 static void dump_decode(struct config *config, struct reg *reg, uint32_t val)
 {
-	char decode[1024];
+	char decode[2060];
 	char tmp[1024];
 	char bin[1024];
 
Signature · 6 lines
2.17.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#3 lore raw

[igt-dev] ✓ Fi.CI.BAT: success for Fix some GCC warnings (rev2)

In reply to Rodrigo Siqueira
== Series Details ==

== Series Details ==

Series: Fix some GCC warnings (rev2)
URL : https://patchwork.freedesktop.org/series/43913/
State : success

== Summary ==

= CI Bug Log - changes from CI_DRM_4562 -> IGTPW_1670 =

== Summary - SUCCESS ==

No regressions found.

External URL: https://patchwork.freedesktop.org/api/1.0/series/43913/revisions/2/mbox/

== Known issues ==

Here are the changes found in IGTPW_1670 that come from known issues:

=== IGT changes ===

    ==== Issues hit ====

    igt@kms_chamelium@dp-hpd-fast:
      fi-skl-6700k2:      SKIP -> FAIL (fdo#103841) +4

    igt@kms_chamelium@hdmi-crc-fast:
      fi-skl-6700k2:      PASS -> FAIL (fdo#103841) +3

    
    ==== Possible fixes ====

    igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
      fi-ivb-3520m:       FAIL (fdo#103375) -> PASS +2

    igt@kms_pipe_crc_basic@suspend-read-crc-pipe-b:
      {fi-cfl-8109u}:     DMESG-WARN (fdo#107345) -> PASS +1

    igt@kms_pipe_crc_basic@suspend-read-crc-pipe-c:
      {fi-cfl-8109u}:     INCOMPLETE (fdo#106070) -> PASS

    {igt@kms_psr@primary_mmap_gtt}:
      fi-cnl-psr:         DMESG-WARN (fdo#107372) -> PASS

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

fdo#103375 https://bugs.freedesktop.org/show_bug.cgi?id=103375
fdo#103841 https://bugs.freedesktop.org/show_bug.cgi?id=103841
fdo#106070 https://bugs.freedesktop.org/show_bug.cgi?id=106070
fdo#107345 https://bugs.freedesktop.org/show_bug.cgi?id=107345
fdo#107372 https://bugs.freedesktop.org/show_bug.cgi?id=107372

== Participating hosts (53 -> 43) ==

Missing (10): fi-ilk-m540 fi-hsw-4200u fi-byt-j1900 fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-kbl-8809g fi-icl-u fi-byt-clapper fi-bdw-samus

== Build changes ==

* IGT: IGT_4579 -> IGTPW_1670

CI_DRM_4562: 99bbd80f75cdcf28699ffd3c93a714ca4a89b962 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_1670: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1670/
IGT_4579: a21999477545c2aed1e6a80dc93f87368614c7e5 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1670/issues.html
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#4 lore raw

[igt-dev] ✓ Fi.CI.IGT: success for Fix some GCC warnings (rev2)

In reply to Rodrigo Siqueira
== Series Details ==

== Series Details ==

Series: Fix some GCC warnings (rev2)
URL : https://patchwork.freedesktop.org/series/43913/
State : success

== Summary ==

= CI Bug Log - changes from IGT_4579_full -> IGTPW_1670_full =

== Summary - WARNING ==

Minor unknown changes coming with IGTPW_1670_full need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in IGTPW_1670_full, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://patchwork.freedesktop.org/api/1.0/series/43913/revisions/2/mbox/

== Possible new issues ==

Here are the unknown changes that may have been introduced in IGTPW_1670_full:

=== IGT changes ===

    ==== Warnings ====

    igt@kms_vblank@pipe-b-query-forked-hang:
      shard-snb:          PASS -> SKIP +2

== Known issues ==

Here are the changes found in IGTPW_1670_full that come from known issues:

=== IGT changes ===

    ==== Issues hit ====

    igt@gem_ppgtt@blt-vs-render-ctx0:
      shard-kbl:          PASS -> INCOMPLETE (fdo#106023, fdo#103665)

    igt@kms_cursor_crc@cursor-128x128-suspend:
      shard-kbl:          PASS -> INCOMPLETE (fdo#103665)

    igt@kms_cursor_legacy@2x-nonblocking-modeset-vs-cursor-atomic:
      shard-glk:          PASS -> FAIL (fdo#106509, fdo#105454)

    igt@kms_flip@flip-vs-expired-vblank-interruptible:
      shard-glk:          PASS -> FAIL (fdo#105363)

    igt@testdisplay:
      shard-glk:          PASS -> INCOMPLETE (fdo#107093, k.org#198133, fdo#103359)

    
    ==== Possible fixes ====

    igt@kms_flip@2x-flip-vs-expired-vblank-interruptible:
      shard-glk:          FAIL (fdo#105363) -> PASS

    igt@kms_frontbuffer_tracking@fbc-1p-primscrn-cur-indfb-draw-mmap-gtt:
      shard-snb:          DMESG-WARN -> PASS

    igt@kms_frontbuffer_tracking@psr-1p-primscrn-pri-indfb-draw-mmap-wc:
      shard-snb:          INCOMPLETE (fdo#105411) -> SKIP

    igt@kms_plane_multiple@atomic-pipe-a-tiling-x:
      shard-snb:          FAIL (fdo#103166) -> PASS

    igt@perf@blocking:
      shard-hsw:          FAIL (fdo#102252) -> PASS

    igt@pm_rpm@gem-execbuf:
      shard-glk:          FAIL (fdo#106539) -> PASS +4
      shard-apl:          FAIL (fdo#106539) -> PASS
      shard-kbl:          FAIL (fdo#106539) -> PASS
      shard-hsw:          FAIL (fdo#106539) -> PASS

    igt@pm_rpm@modeset-lpsp:
      shard-glk:          FAIL (fdo#106539) -> SKIP +1

fdo#102252 https://bugs.freedesktop.org/show_bug.cgi?id=102252
fdo#103166 https://bugs.freedesktop.org/show_bug.cgi?id=103166
fdo#103359 https://bugs.freedesktop.org/show_bug.cgi?id=103359
fdo#103665 https://bugs.freedesktop.org/show_bug.cgi?id=103665
fdo#105363 https://bugs.freedesktop.org/show_bug.cgi?id=105363
fdo#105411 https://bugs.freedesktop.org/show_bug.cgi?id=105411
fdo#105454 https://bugs.freedesktop.org/show_bug.cgi?id=105454
fdo#106023 https://bugs.freedesktop.org/show_bug.cgi?id=106023
fdo#106509 https://bugs.freedesktop.org/show_bug.cgi?id=106509
fdo#106539 https://bugs.freedesktop.org/show_bug.cgi?id=106539
fdo#107093 https://bugs.freedesktop.org/show_bug.cgi?id=107093
k.org#198133 https://bugzilla.kernel.org/show_bug.cgi?id=198133

== Participating hosts (5 -> 5) ==

No changes in participating hosts

== Build changes ==

* IGT: IGT_4579 -> IGTPW_1670
* Linux: CI_DRM_4560 -> CI_DRM_4562

CI_DRM_4560: b73c0ddef408783e556741ac9d3679b7d153e3e1 @ git://anongit.freedesktop.org/gfx-ci/linux
CI_DRM_4562: 99bbd80f75cdcf28699ffd3c93a714ca4a89b962 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_1670: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1670/
IGT_4579: a21999477545c2aed1e6a80dc93f87368614c7e5 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1670/shards.html
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#5 lore raw
In reply to Rodrigo Siqueira

Hi,

I would like to know if there is any improvement that I can do for this patchset.

Thanks

Quoted 20 lines · Rodrigo Siqueira

During the compilation, some GCC (8.1) warnings are shown. This patchset address some of the warnings problems.

Changes since v2:
- Reduce the total amount of bytes allocated during command handling operation
- Remove unnecessary memset operation
- Improved commit message

Rodrigo Siqueira (2):
Make string commands dynamic allocate
Fix truncate string in the snprintf

 tools/intel_gvtg_test.c | 25 ++++++++++++++++---------
 tools/intel_reg.c       |  2 +-
 2 files changed, 17 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.0
Signature · 9 lines
Rodrigo Siqueira
http://siqueira.tech
Graduate Student
Department of Computer Science
University of São Paulo
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev