From patchwork Sat Apr 1 13:57:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danil Antonov X-Patchwork-Id: 9657991 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BC09E60349 for ; Sat, 1 Apr 2017 13:58:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1F3D285C2 for ; Sat, 1 Apr 2017 13:58:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3BB828610; Sat, 1 Apr 2017 13:58:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5342D285C2 for ; Sat, 1 Apr 2017 13:58:48 +0000 (UTC) Received: from localhost ([::1]:51431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuJYF-0006iN-Dd for patchwork-qemu-devel@patchwork.kernel.org; Sat, 01 Apr 2017 09:58:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuJWf-00060S-2u for qemu-devel@nongnu.org; Sat, 01 Apr 2017 09:57:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cuJWd-0004Cy-VM for qemu-devel@nongnu.org; Sat, 01 Apr 2017 09:57:09 -0400 Received: from mail-oi0-x244.google.com ([2607:f8b0:4003:c06::244]:36566) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cuJWd-0004Ct-P4 for qemu-devel@nongnu.org; Sat, 01 Apr 2017 09:57:07 -0400 Received: by mail-oi0-x244.google.com with SMTP id b187so13214927oif.3 for ; Sat, 01 Apr 2017 06:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=o0TFMgUFwgj/2pxCqI775pGScS7bFLi6GjO8J+6S1PM=; b=bd78D8ZEF4phARa0tiPScJRb1WiUfJvXorUGMe/Jo163OMnvZG6QUA+O46700kJ8N3 k7IBTi99SN2AybVOW7q3pSZtb9CkLluR2zXGN5Chep4awPo26FQ/OBxuiP65BlHuzjI6 0vm45QYfJD/Ibmg0cgOvv5uYI0pv8NnsAuhCY5KRm2EkplsnpZjHQK6tuIg7/HijZgjh stKV10VgQib2SaPgf5Asq8stYIiCCTZemtFqbGqUg6ukiGhE1l1DuEgnQTews9ltOlh9 E7x9xSFPeRTMiRO+x9m8Y0LgxGA8ywGYAk41ZcsxR1XOsM07egATxMc9WAHWyE5NVtn+ zW6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=o0TFMgUFwgj/2pxCqI775pGScS7bFLi6GjO8J+6S1PM=; b=Zq8kZfg+pAjqIeJIdzexkcbisx6XAW9X4VSBvjXx0HvW/gndzqVgnaZns1EY34YToH mAcjg1LclZpzaOK47AJYZrmYt92ljonS7X3SfO4xbjN6Z3336gUQYtsZ9CdigIXWeXf+ yfDPCHMAjxitT+pLo+rX/gFnM+M0LirPc0tzeKA+zuLNQhyBKZYCVypzJ5JzkW/hdNSH guDeWQKdTTDEtO3ddSASAd/dUsILObcA8Gdb6B2ySIFMJ46bAggJgxu9drHjBuX5fpWU VX23nNbwsJvDXv6exAOTFz0fyD1YI+t/dZXnbfFa0BoAHSfuYmJLUsPSMox2gJ22sTUI hTXw== X-Gm-Message-State: AFeK/H015Oe6Fn9RZ6s7dRaP1O8eYOwISoldOclxX6pK3nPGHcTTggSKsD1iIUgVk1C59ViX7HhvvzQhSfsFqg== X-Received: by 10.157.43.182 with SMTP id u51mr5396371ota.5.1491055026857; Sat, 01 Apr 2017 06:57:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.32.234 with HTTP; Sat, 1 Apr 2017 06:57:06 -0700 (PDT) From: Danil Antonov Date: Sat, 1 Apr 2017 16:57:06 +0300 Message-ID: To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c06::244 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: [Qemu-devel] [PATCH 22/43] virtio: made printf always compile in debug output X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From 2e5d92b2d1955b3e85f1e93ad98469d00c47a658 Mon Sep 17 00:00:00 2001 From: Danil Antonov Date: Wed, 29 Mar 2017 12:33:29 +0300 Subject: [PATCH 22/43] virtio: made printf always compile in debug output Wrapped printf calls inside debug macros (DPRINTF) in `if` statement. This will ensure that printf function will always compile even if debug output is turned off and, in turn, will prevent bitrot of the format strings. Signed-off-by: Danil Antonov --- hw/virtio/virtio-bus.c | 15 ++++++++++----- hw/virtio/virtio-mmio.c | 17 ++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index 3042232..35cfef5 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -31,15 +31,20 @@ #include "hw/virtio/virtio.h" #include "exec/address-spaces.h" + /* #define DEBUG_VIRTIO_BUS */ -#ifdef DEBUG_VIRTIO_BUS -#define DPRINTF(fmt, ...) \ -do { printf("virtio_bus: " fmt , ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) do { } while (0) +#ifndef DEBUG_VIRTIO_BUS +#define DEBUG_VIRTIO_BUS 0 #endif +#define DPRINTF(fmt, ...) \ + do { \ + if (DEBUG_VIRTIO_BUS) { \ + fprintf(stderr, "virtio_bus: " fmt, ## __VA_ARGS__); \ + } \ + } while (0) + /* A VirtIODevice is being plugged */ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) { diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index 5807aa8..31e3094 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -30,13 +30,16 @@ /* #define DEBUG_VIRTIO_MMIO */ -#ifdef DEBUG_VIRTIO_MMIO - -#define DPRINTF(fmt, ...) \ -do { printf("virtio_mmio: " fmt , ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) do {} while (0) -#endif +#ifndef DEBUG_VIRTIO_MMIO +#define DEBUG_VIRTIO_MMIO 0 +#endif + +#define DPRINTF(fmt, ...) \ + do { \ + if (DEBUG_VIRTIO_MMIO) { \ + fprintf(stderr, "virtio_mmio: " fmt, ## __VA_ARGS__); \ + } \ + } while (0) /* QOM macros */ /* virtio-mmio-bus */