Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp977396pxb; Wed, 29 Sep 2021 14:00:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPU7E+H3eum1U63b0Wxj7Tt6I9oXs+wQLo422hKrrCXAo4nCER+7XEs3A45QquIolZhFzB X-Received: by 2002:a17:90a:4:: with SMTP id 4mr2087124pja.221.1632949250448; Wed, 29 Sep 2021 14:00:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632949250; cv=none; d=google.com; s=arc-20160816; b=07aRqEXTr3zQu7kayB9eE+e3iG1iMYidLv20o3mR8pjMdW8AtFFcY1nrxmz7TwOmG5 Y8K1fswx6GrezifnoLk89mrgOsyWeJzmka39LS9uh+1AXcABV+8FHqI7TjcmBmvQ2Ey3 MUotHHy/Z7OqZXJIUZYMfOoZZbtwf9rTbWfqEQd7h+ZTu07RK2CBPg/7pxAuDX63Rywt TAx0JLxQBU+7r/Lp1tT63hDwSL4L7jrq0Tb0w5abSmL3GGbDw2lZ5JGs/Mque1Ausvfj VEsSmfK0yutS0flrTdNtY1vepdfnhy6IaEZCUxMcSQ+yXjpnbE6HpMjYeZDBkAsPkWSt Xxog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/i4BxU/q1FDQvm2gtEkFQp1RdSz7T/4R4YwULFCu388=; b=ISBmbxBovy5B4vtWAzEdBcKsZnxROQeAIzZyXLdAZvuL0JKKAPDZfKLhxdgFkXFEHW 4v8M8DbS549sN3Mu7p/5SLIdqnTsIfzanczthE12ER859bYYuiX9nRSAHUvmj7eutJim PdvjtFM3KOu5wLr/yfzO3AG+mjDoBZf1zueUqA4ZT+W4wHi68rNwRmvK+Sq3gLQrgP4v vFcv2JalRQA8JtnnsAs2GBgNSwTO1Ea28SwiZsJ5sQ841PceZj211jy/vafQ9lH5fFMO yCOOrfYhMMCzdd9TRQCk+coi6gX3ma+4CjoLgVUH4g+zLeKoivmc+gIofwpwHENIQ5Un vDPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t27si1037804pga.217.2021.09.29.14.00.36; Wed, 29 Sep 2021 14:00:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346242AbhI2SgA (ORCPT + 99 others); Wed, 29 Sep 2021 14:36:00 -0400 Received: from mga18.intel.com ([134.134.136.126]:24845 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345901AbhI2Sf6 (ORCPT ); Wed, 29 Sep 2021 14:35:58 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10122"; a="212095103" X-IronPort-AV: E=Sophos;i="5.85,332,1624345200"; d="scan'208";a="212095103" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2021 11:34:16 -0700 X-IronPort-AV: E=Sophos;i="5.85,332,1624345200"; d="scan'208";a="520927754" Received: from lucas-s2600cw.jf.intel.com ([10.165.21.202]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2021 11:34:16 -0700 From: Lucas De Marchi To: intel-gfx@lists.freedesktop.org Cc: Daniel Vetter , dri-devel@lists.freedesktop.org, Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] drm/i915/utils: do not depend on config being defined Date: Wed, 29 Sep 2021 11:33:56 -0700 Message-Id: <20210929183357.1490204-3-lucas.demarchi@intel.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210929183357.1490204-1-lucas.demarchi@intel.com> References: <20210929183357.1490204-1-lucas.demarchi@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Like the IS_ENABLED() counterpart, we can make IS_CONFIG_NONZERO() to return the right thing when the config is not defined rather than a build error, with the limitation that it can't be used on preprocessor context. The trick here is that macro names can't start with a number or dash, so we stringify the argument and check that the first char is a number != 0 (or starting with a dash to cover negative numbers). Except for -O0 builds the strings are all eliminated. Taking CONFIG_DRM_I915_REQUEST_TIMEOUT in drivers/gpu/drm/i915/gem/i915_gem_context.c as example, we have the following output of the preprocessor: old: if (((20000) != 0) && new: if (( ("20000"[0] > '0' && "20000"[0] < '9') || "20000"[0] == '-' ) && New one looks worse, but is also eliminated from the object: $ size drivers/gpu/drm/i915/gem/i915_gem_context.o.* text data bss dec hex filename 52021 1070 232 53323 d04b drivers/gpu/drm/i915/gem/i915_gem_context.o.new 52021 1070 232 53323 d04b drivers/gpu/drm/i915/gem/i915_gem_context.o.old Signed-off-by: Lucas De Marchi --- drivers/gpu/drm/i915/i915_utils.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h index 02bbfa4d68d3..436ce612c46a 100644 --- a/drivers/gpu/drm/i915/i915_utils.h +++ b/drivers/gpu/drm/i915/i915_utils.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -469,6 +470,9 @@ static inline bool timer_expired(const struct timer_list *t) * * Returns 0 if @config is 0, 1 if set to any value. */ -#define IS_CONFIG_NONZERO(config) ((config) != 0) +#define IS_CONFIG_NONZERO(config) ( \ + (__stringify_1(config)[0] > '0' && __stringify_1(config)[0] < '9') || \ + __stringify_1(config)[0] == '-' \ +) #endif /* !__I915_UTILS_H */ -- 2.33.0