From patchwork Sat Apr 1 13:48:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danil Antonov X-Patchwork-Id: 745978 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vwKTZ3KBpz9ryv for ; Sun, 2 Apr 2017 00:48:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ff45Wb4C"; dkim-atps=neutral Received: from localhost ([::1]:51399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuJOa-00018o-1Y for incoming@patchwork.ozlabs.org; Sat, 01 Apr 2017 09:48:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cuJO7-00017O-Hq for qemu-devel@nongnu.org; Sat, 01 Apr 2017 09:48:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cuJO4-0000o3-If for qemu-devel@nongnu.org; Sat, 01 Apr 2017 09:48:19 -0400 Received: from mail-oi0-x241.google.com ([2607:f8b0:4003:c06::241]:36068) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cuJO4-0000nf-Bu for qemu-devel@nongnu.org; Sat, 01 Apr 2017 09:48:16 -0400 Received: by mail-oi0-x241.google.com with SMTP id b187so13194757oif.3 for ; Sat, 01 Apr 2017 06:48:16 -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=/aN9s4XW/pYv5nq/Y/ZDIDNrJAr5Y5HRLLs5SMKBwzM=; b=ff45Wb4C0uEL5Kh/KwtUs46T+YdfSkSe+igem4YKBDB0FebB794/fzcXdAH/QGecfk aVbUgemlrP6PPJjmEJsEjjgt1GAcgLqc68kD9+5ax55iHXupqOi2VHoEMk76P5WxSZdO f0ZhWCVK/c9vK/dpfsCF7bZTuuJ72TjgLTyte+4d9AVD6Jo19Fc6k6Eeci7y/Q5WeL84 bJ1kzwWwjCaf++uI6fkpdpLJhmRY+AncaoJdj4UqzISEcVJ/wb78m5UociTcRi28Lcrm G3M0L1A2QAcY0+s8MgxVZfhm7zTry0WXZ6/rtnL/51qJWxCmnuxn8twbynMB5UvqQENS x1fA== 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=/aN9s4XW/pYv5nq/Y/ZDIDNrJAr5Y5HRLLs5SMKBwzM=; b=gK7Y0v7DUDEKzWwpflpoH6/MDTu+sFeCVlbMqyC9wIoa8FdqjPZVD+xaV3HdRSIduH /LsEEE5Oh+9jiKF8Rqb1JBTIx7YXya2TOi3CYlAbm95QAsh4/VBBWWTIC5CO1Mh1G4zy l44p1uMbS5tkwKJX4YoG6JLLkJNux8sNcOubc5UgoqcVCaNNAz4l/AVv8VXGeVY2Ere2 4fC+VmwyM/XBg9snNwwdskmNbyaLmomRrQeAD9KTFkDMK5f5Xq+RRIOwPVrNJ1JC5wAn kjHY7arnJFwuTX6yDvqERk4LmJiuNwICXtfZsJnjxn9FxzxwqyreTDGAJ+HU6coCShNO 0Iww== X-Gm-Message-State: AFeK/H2qWZWSfVRrU58nBOLlKyxL59c0AxzdaxdZht7UWyg2GOZrK5YXPiqO4xkmllrD+zIN7XaIT79D//CsqQ== X-Received: by 10.157.43.182 with SMTP id u51mr5381512ota.5.1491054495363; Sat, 01 Apr 2017 06:48:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.32.234 with HTTP; Sat, 1 Apr 2017 06:48:15 -0700 (PDT) From: Danil Antonov Date: Sat, 1 Apr 2017 16:48:15 +0300 Message-ID: To: qemu-devel@nongnu.org, mst@redhat.com, marcel@redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c06::241 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: [Qemu-devel] [PATCH 13/43] pci: 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From 7ff1463852763cbe7b8260147aa0c19bf91c8cbb Mon Sep 17 00:00:00 2001 From: Danil Antonov Date: Wed, 29 Mar 2017 12:27:57 +0300 Subject: [PATCH 13/43] pci: 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/pci/msi.c | 17 +++++++++++------ hw/pci/pci.c | 16 +++++++++++----- hw/pci/pci_host.c | 16 ++++++++++------ hw/pci/pcie.c | 18 ++++++++++++------ hw/pci/pcie_aer.c | 18 ++++++++++++------ 5 files changed, 56 insertions(+), 29 deletions(-) + } while (0) + #define PCIE_DEV_PRINTF(dev, fmt, ...) \ PCIE_DPRINTF("%s:%x "fmt, (dev)->name, (dev)->devfn, ## __VA_ARGS__) diff --git a/hw/pci/msi.c b/hw/pci/msi.c index a87b227..b7cfa5c 100644 --- a/hw/pci/msi.c +++ b/hw/pci/msi.c @@ -72,12 +72,17 @@ static inline uint8_t msi_cap_sizeof(uint16_t flags) //#define MSI_DEBUG -#ifdef MSI_DEBUG -# define MSI_DPRINTF(fmt, ...) \ - fprintf(stderr, "%s:%d " fmt, __func__, __LINE__, ## __VA_ARGS__) -#else -# define MSI_DPRINTF(fmt, ...) do { } while (0) -#endif +#ifndef MSI_DEBUG +#define MSI_DEBUG 0 +#endif + +#define MSI_DPRINTF(fmt, ...) \ + do { \ + if (MSI_DEBUG) { \ + fprintf(stderr, "%s:%d " fmt, __func__, __LINE__, ## __VA_ARGS__); \ + } \ + } while (0) + #define MSI_DEV_PRINTF(dev, fmt, ...) \ MSI_DPRINTF("%s:%x " fmt, (dev)->name, (dev)->devfn, ## __VA_ARGS__) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index e6b08e1..80d08af 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -43,11 +43,17 @@ #include "qemu/cutils.h" //#define DEBUG_PCI -#ifdef DEBUG_PCI -# define PCI_DPRINTF(format, ...) printf(format, ## __VA_ARGS__) -#else -# define PCI_DPRINTF(format, ...) do { } while (0) -#endif +// +#ifndef DEBUG_PCI +#define DEBUG_PCI 0 +#endif + +#define PCI_DPRINTF(fmt, ...) \ + do { \ + if (DEBUG_PCI) { \ + fprintf(stderr, "pci: " fmt, ## __VA_ARGS__); \ + } \ + } while (0) static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent); static char *pcibus_get_dev_path(DeviceState *dev); diff --git a/hw/pci/pci_host.c b/hw/pci/pci_host.c index 5eaa935..83fde14 100644 --- a/hw/pci/pci_host.c +++ b/hw/pci/pci_host.c @@ -27,12 +27,16 @@ /* debug PCI */ //#define DEBUG_PCI -#ifdef DEBUG_PCI -#define PCI_DPRINTF(fmt, ...) \ -do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0) -#else -#define PCI_DPRINTF(fmt, ...) -#endif +#ifndef DEBUG_PCI +#define DEBUG_PCI 0 +#endif + +#define PCI_DPRINTF(fmt, ...) \ + do { \ + if (DEBUG_PCI) { \ + fprintf(stderr, "pci_host_data: " fmt, ## __VA_ARGS__); \ + } \ + } while (0) /* * PCI address diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 18e634f..5148f69 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -30,12 +30,18 @@ #include "qemu/range.h" //#define DEBUG_PCIE -#ifdef DEBUG_PCIE -# define PCIE_DPRINTF(fmt, ...) \ - fprintf(stderr, "%s:%d " fmt, __func__, __LINE__, ## __VA_ARGS__) -#else -# define PCIE_DPRINTF(fmt, ...) do {} while (0) -#endif + +#ifndef DEBUG_PCIE +#define DEBUG_PCIE 0 +#endif + +#define PCIE_DPRINTF(fmt, ...) \ + do { \ + if (DEBUG_PCIE) { \ + fprintf(stderr, "%s:%d " fmt, __func__, __LINE__, ## __VA_ARGS__); \ + } \ + } while (0) + #define PCIE_DEV_PRINTF(dev, fmt, ...) \ PCIE_DPRINTF("%s:%x "fmt, (dev)->name, (dev)->devfn, ## __VA_ARGS__) diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index a8c1820..5dfedda 100644 --- a/hw/pci/pcie_aer.c +++ b/hw/pci/pcie_aer.c @@ -32,12 +32,18 @@ #include "qapi/error.h" //#define DEBUG_PCIE -#ifdef DEBUG_PCIE -# define PCIE_DPRINTF(fmt, ...) \ - fprintf(stderr, "%s:%d " fmt, __func__, __LINE__, ## __VA_ARGS__) -#else -# define PCIE_DPRINTF(fmt, ...) do {} while (0) -#endif + +#ifndef DEBUG_PCIE +#define DEBUG_PCIE 0 +#endif + +#define PCIE_DPRINTF(fmt, ...) \ + do { \ + if (DEBUG_PCIE) { \ + fprintf(stderr, "%s:%d " fmt, __func__, __LINE__, ## __VA_ARGS__) \ + } \