From patchwork Wed Sep 25 14:56:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1167417 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gohgeEEO"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46dhxG0mfwz9sP3 for ; Thu, 26 Sep 2019 01:36:34 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A50EEC22147; Wed, 25 Sep 2019 15:19:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 542BAC22071; Wed, 25 Sep 2019 15:02:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3A11DC2217A; Wed, 25 Sep 2019 15:02:45 +0000 (UTC) Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by lists.denx.de (Postfix) with ESMTPS id A545AC22070 for ; Wed, 25 Sep 2019 14:58:36 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id v2so14591736iob.10 for ; Wed, 25 Sep 2019 07:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i8q+u2sPBBxlVDvfbJ6jdgnbSjG1MKrmu1RFpIG13wI=; b=gohgeEEOwC6Bx5XvSdT6ZwGJnSjCrlKdhuexojkyVsqwt70NeuPE0tl96K/RDE53oQ czHFFZr/YdYcTuPnthbp++/fQNyYRGO6mTFRwGgsZH1YwJPLjuRUYzU3V2lMYx5eNds4 D2HWKanbcpaxkZtOsLB2F61dw79QL124h40AU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i8q+u2sPBBxlVDvfbJ6jdgnbSjG1MKrmu1RFpIG13wI=; b=mmc/95USedxJjf/vIYN/jh0OZOwmOkCDAnuHfgN6vgXBavnRtt67AfMvl/vycmBH+Z kXrDbTpWawDToGDX60uEKlI3pfmqXSNMOfSlQ/wZEBBde0t4NLZwL4jeignQ3L3sQhQW U7qNbvvQRvb/KjKUm8ZD30sIUg6d3/TSDUyQQI4j3C4+dabbpg4LAFRH6t2V3VPNh/S5 ep+VJspP9m+Z8TD7XL9mNz0SFSd5fgCTaSUGdHtP9sXDdUpO9hqFQcPb3/B1elu6gJyy +DCpFMatzQbrxWj5TyFtfbriSEP8S6C/z2c0pg4C6M7jnSO0I//SKWqiTUA6su1VC4LQ 8XBw== X-Gm-Message-State: APjAAAUgbZy73NvSUPHtbMqKi3xXvmCCuOQahO5o3q9LxfZq8HjEssaT lMrL91hw7SFygrRXXjAfuZAkJSUS/HE= X-Google-Smtp-Source: APXvYqy3p8gv8CbmFwao5GaCTZInZ3UUZf/uQ+oEyx3h7e1XBSKr3tCQPXkTNoNtq4vSI4ejNXK15w== X-Received: by 2002:a5d:91da:: with SMTP id k26mr10223537ior.90.1569423515444; Wed, 25 Sep 2019 07:58:35 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id d9sm4254964ioq.9.2019.09.25.07.58.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2019 07:58:35 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Wed, 25 Sep 2019 08:56:23 -0600 Message-Id: <20190925145750.200592-40-sjg@chromium.org> X-Mailer: git-send-email 2.23.0.444.g18eeb5a265-goog In-Reply-To: <20190925145750.200592-1-sjg@chromium.org> References: <20190925145750.200592-1-sjg@chromium.org> MIME-Version: 1.0 Subject: [U-Boot] [PATCH 039/126] log: Add log_nop() to avoid unused-variable warnings X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" If a log statement includes a variable and logging is disabled, this can generate warnings about unused variables. Add a bit more complexity to the macros to avoid this for the common case. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- include/log.h | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/include/log.h b/include/log.h index 6d15e955d7e..d8f18a6afdf 100644 --- a/include/log.h +++ b/include/log.h @@ -76,6 +76,18 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, int line, const char *func, const char *fmt, ...) __attribute__ ((format (__printf__, 6, 7))); +static inline int _log_nop(enum log_category_t cat, enum log_level_t level, + const char *file, int line, const char *func, + const char *fmt, ...) + __attribute__ ((format (__printf__, 6, 7))); + +static inline int _log_nop(enum log_category_t cat, enum log_level_t level, + const char *file, int line, const char *func, + const char *fmt, ...) +{ + return 0; +} + /* Define this at the top of a file to add a prefix to debug messages */ #ifndef pr_fmt #define pr_fmt(fmt) fmt @@ -101,13 +113,14 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, #define log_io(_fmt...) log(LOG_CATEGORY, LOGL_DEBUG_IO, ##_fmt) #else #define _LOG_MAX_LEVEL LOGL_INFO -#define log_err(_fmt...) -#define log_warning(_fmt...) -#define log_notice(_fmt...) -#define log_info(_fmt...) -#define log_debug(_fmt...) -#define log_content(_fmt...) -#define log_io(_fmt...) +#define log_err(_fmt...) log_nop(LOG_CATEGORY, LOGL_ERR, ##_fmt) +#define log_warning(_fmt...) log_nop(LOG_CATEGORY, LOGL_WARNING, ##_fmt) +#define log_notice(_fmt...) log_nop(LOG_CATEGORY, LOGL_NOTICE, ##_fmt) +#define log_info(_fmt...) log_nop(LOG_CATEGORY, LOGL_INFO, ##_fmt) +#define log_debug(_fmt...) log_nop(LOG_CATEGORY, LOGL_DEBUG, ##_fmt) +#define log_content(_fmt...) log_nop(LOG_CATEGORY, \ + LOGL_DEBUG_CONTENT, ##_fmt) +#define log_io(_fmt...) log_nop(LOG_CATEGORY, LOGL_DEBUG_IO, ##_fmt) #endif #if CONFIG_IS_ENABLED(LOG) @@ -129,6 +142,12 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, #define log(_cat, _level, _fmt, _args...) #endif +#define log_nop(_cat, _level, _fmt, _args...) ({ \ + int _l = _level; \ + _log_nop((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \ + __func__, pr_fmt(_fmt), ##_args); \ +}) + #ifdef DEBUG #define _DEBUG 1 #else