Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp419386pxb; Thu, 30 Sep 2021 08:48:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5UH+cCyEw/Y/Y3YkJp5nJpQcJJr1rxU3ZNCzeP/5aN5C1aqbHMq7u27NNuE5TM4HhdHnI X-Received: by 2002:a17:906:1510:: with SMTP id b16mr7796321ejd.332.1633016920111; Thu, 30 Sep 2021 08:48:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633016920; cv=none; d=google.com; s=arc-20160816; b=GBIyetPKV0JP4StTIqXh/rShdslCzFCPoV2UYAhr6/EisR7DVdRaIvzcKsxWLvsfdH dZAQgd1RxRECmXfrxigIxbb7vPaWMw1p6KIfT3pt0Nj4PEFGOFzoRT583o0ebY5aYJhJ BSeND9WjVM68M9iSbGebc42jnGYyrzTRA3fqugNnc3sFw1gX2a53/kbOm7+T7DGjMw/7 ccGudncSNPafeA0Hgmp32IU2abBWd9WcS89cLIO+jNRUHk+btoHfoTLYdw9V3IeJQsBq +QQHqV4wOleDHX5ab2fga6+yYP2rZZlAjBeJvtWLdhPFyJ3ERvo2uB35MjkqxRYh4RdH hr5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=PIipoyxk8MYtoMPWqBFe3wGeerRXz5YN1FaqJnqgl/g=; b=dHdQypkze7v+8oNZHZXdeuRE4zKCQ1k0QvOi0h2WdSxL8pSf+LDWPB9tOQpuaMh0Hc LQrLtAz0v9U9TiCt9YMnq2abVpsFpCZPGF+grFR5BJjGF/fRP9oR8uG5bioGfx2XzApz 1EY4ACfj+NFSjAQzwGstHkCoi+wI6QC15wVe0kWDNFp/bek7VyoSnFfrVmwoKlTuyhN0 sXdzwMSOq6qF6+vWmgfZbNacHtKprCKUHUPBWAQ495C98BgdYwaeaL7N70kxT9G9QwQn 3goVffGM1JadqzdrLU+O8tc9c+aD2QzVqYwK45wetpMMlBUbkkiEXTcsxR6BnzRiWrG6 oSDQ== 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 kl17si3696362ejc.507.2021.09.30.08.48.13; Thu, 30 Sep 2021 08:48:40 -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 S1345877AbhI3PpB (ORCPT + 99 others); Thu, 30 Sep 2021 11:45:01 -0400 Received: from mga09.intel.com ([134.134.136.24]:13607 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344638AbhI3Po7 (ORCPT ); Thu, 30 Sep 2021 11:44:59 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10123"; a="225255777" X-IronPort-AV: E=Sophos;i="5.85,336,1624345200"; d="scan'208";a="225255777" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2021 08:43:16 -0700 X-IronPort-AV: E=Sophos;i="5.85,336,1624345200"; d="scan'208";a="709134016" Received: from kjepstei-mobl.amr.corp.intel.com (HELO ldmartin-desk2) ([10.212.192.243]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2021 08:43:15 -0700 Date: Thu, 30 Sep 2021 08:43:15 -0700 From: Lucas De Marchi To: Steven Price Cc: intel-gfx@lists.freedesktop.org, Daniel Vetter , dri-devel@lists.freedesktop.org, Masahiro Yamada , linux-kernel@vger.kernel.org, Jani Nikula Subject: Re: [PATCH v2 2/3] drm/i915/utils: do not depend on config being defined Message-ID: <20210930154315.xb43gowfhmxucsm4@ldmartin-desk2> X-Patchwork-Hint: comment References: <20210929183357.1490204-1-lucas.demarchi@intel.com> <20210929183357.1490204-3-lucas.demarchi@intel.com> <2dd723c8-6aed-857c-23f3-d0381fcb52c2@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <2dd723c8-6aed-857c-23f3-d0381fcb52c2@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 30, 2021 at 11:00:06AM +0100, Steven Price wrote: >On 29/09/2021 19:33, Lucas De Marchi wrote: >> 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') || \ > >Shouldn't this be "<= '9'". Otherwise numbers starting with a 9 are not >"non zero". yes! thanks for catching it. However from the other discussion it seems we can either a) just remove the macro, or b) use the simpler version that doesn't cover undefined values I will investigate those options. Lucas De Marchi