Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp999411pxb; Wed, 29 Sep 2021 14:32:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyocVC6c01mgwlNt7+sMb+VSEyeV2Xet5RHrtQb7Hs3x0UJbpxXZRYgssV9KQMw0ngntI5+ X-Received: by 2002:a50:cf4c:: with SMTP id d12mr2662624edk.115.1632951144884; Wed, 29 Sep 2021 14:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632951144; cv=none; d=google.com; s=arc-20160816; b=K7uoTbNJTEd/CYM8G6U7azG7UPGrVU2szah+8MNILSb8QVOFkhn7ff3l3s18dD15Dj MSWkD9+8JZCtYLTvXjocbW8Q0aeP0xHosVHz7IWQ79WglQaYXYO+7P+chi5YCwSw/MOV sw6YVnrNkgCHnSDAUY7tlwZ+4e3K8SmbVkvVj9JkCAgixELHqaJuEjtP4Nx2lBGaI/sc Py7xgeXCNNp3uFP68aLUFnbnEBjHtSOtL5Afc6JMf1UNYLTONMkDRwpb40+yal2Rlx5n UKpfVqtHdupFhWuaWC5pa1Yh4IFJzxHD67hSWUnYvFGcejxQ0TOGFQ3/h7RqEllbc5BG kEEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :in-reply-to:from:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature:dkim-filter; bh=JeDKYp3j+cLtP10guMMLbCTqVUCBWHRZIj/Vin2I7wA=; b=UnDPR0cekdfxO8qpR+quZ2O2m9zDfKkIc/zK6zsj5y4ah2aoLt18+Sn2MncIGHlu4G /KFr0IGv3UQd34ZKqchEdeK0HCi7pHWTLZYxKzaTCWYbuFvo4dai1pdj6GBfBgohulY0 Hs42R1vTgUVnFHyjHgaPfTJTrQMiLeuLBCQsbI6t9lESwvTICkFYnmjpnKxlConxVnZs 81EUwf5JzXBUhYfDmKofFlgHIVpefXXX+GkpmmzX+jlNw77O0Ac7lr0gCG35BUMqUOOQ S0cUhgol0jSXoWipuzWdyLkQ6O9mCX/ejdg9X75GTjk3z0sFZui+M6pbXNmdHHV3IL4h PKbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=jOnF3U+b; 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=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e10si2087189edz.582.2021.09.29.14.32.01; Wed, 29 Sep 2021 14:32:24 -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; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=jOnF3U+b; 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=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346262AbhI2VKI (ORCPT + 99 others); Wed, 29 Sep 2021 17:10:08 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:60917 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346473AbhI2VKF (ORCPT ); Wed, 29 Sep 2021 17:10:05 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20210929210820euoutp012a46df20d4df2533bd13963b89af5fc5~pZxnrMYj_2293522935euoutp01h for ; Wed, 29 Sep 2021 21:08:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20210929210820euoutp012a46df20d4df2533bd13963b89af5fc5~pZxnrMYj_2293522935euoutp01h DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1632949700; bh=JeDKYp3j+cLtP10guMMLbCTqVUCBWHRZIj/Vin2I7wA=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=jOnF3U+bkEiKRKMGmpHeYhU93tmXUoxaQ4m7P1OdbQpvejinJRpuuc0tWcXq4qjLd RDCayWKPU8qnmT62xHVszJ17Z35k1NHk7k3ItKg/mOnpA050zVT6NBbZtVnc3PjYn0 kqEhXDdZMZYYI+yhkWmMLhyZ1b+bQF3Pdwh4Lx4Y= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20210929210820eucas1p1554a043127322d24d6f4dbb5a21b590e~pZxnJij3W2484424844eucas1p1E; Wed, 29 Sep 2021 21:08:20 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 47.7A.56448.4C5D4516; Wed, 29 Sep 2021 22:08:20 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20210929210819eucas1p2edb6fc892fbb9f87f025db20941ace98~pZxmQvOfS1126611266eucas1p2O; Wed, 29 Sep 2021 21:08:19 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20210929210819eusmtrp1a0be77aec665cf8a5061fad9e0a9b4d8~pZxmQDUd_1010310103eusmtrp1X; Wed, 29 Sep 2021 21:08:19 +0000 (GMT) X-AuditID: cbfec7f5-d3bff7000002dc80-3e-6154d5c40abe Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 45.09.31287.3C5D4516; Wed, 29 Sep 2021 22:08:19 +0100 (BST) Received: from [106.210.131.79] (unknown [106.210.131.79]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20210929210818eusmtip15d4b1b25d400e882d89e270b2fe0cf3b~pZxl2qkpQ2505825058eusmtip1W; Wed, 29 Sep 2021 21:08:18 +0000 (GMT) Message-ID: Date: Wed, 29 Sep 2021 23:08:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Thunderbird/93.0 Subject: Re: [PATCH v2 2/3] drm/i915/utils: do not depend on config being defined Content-Language: en-GB To: Lucas De Marchi , intel-gfx@lists.freedesktop.org Cc: Daniel Vetter , dri-devel@lists.freedesktop.org, Masahiro Yamada , linux-kernel@vger.kernel.org From: Andrzej Hajda In-Reply-To: <20210929183357.1490204-3-lucas.demarchi@intel.com> Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprKKsWRmVeSWpSXmKPExsWy7djPc7pHroYkGuzu5rBYfmYds8WVr+/Z LGZP2MxkcXnXHDaLp4+XsVk8fHCD1YHNY/Gel0wem1Z1snnc7z7O5PF5k1wASxSXTUpqTmZZ apG+XQJXxvWulSwFl0Qqjv09yNbAuEygi5GTQ0LARKK3u5mti5GLQ0hgBaPE/Qs/WCGcL4wS x18dZYRwPjNKTL05gwWmZcWZiUwQieWMEld2fGeGcN4zSix/1cQEUsUrYCdx4dkCRhCbRUBV ouf7ehaIuKDEyZlPwGxRgQSJ1/c2sYHYwgLBEp+P3QWLMwuISzR9WckKYosIBEr0bloGto1Z YBqjRGv3A7ChbAKaEn833wRr5hRwkDiw6BwTRLO8RPPW2WAXSQhc4JDY1NrJDnG3i0Tv41fM ELawxKvjW6DiMhKnJ/dA/VYvcX9FC1RzB6PE1g07oRqsJe6c+wW0jQNog6bE+l36EGFHiZYp JxlBwhICfBI33gpC3MAnMWnbdGaIMK9ER5sQRLWixP2zW6EGikssvfCVbQKj0iykYJmF5P1Z SL6ZhbB3ASPLKkbx1NLi3PTUYuO81HK94sTc4t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kwvtDPDhRiDclsbIqtSg/vqg0J7X4 EKMpMDQmMkuJJucD4zyvJN7QzMDU0MTM0sDU0sxYSZx369w18UIC6YklqdmpqQWpRTB9TByc Ug1MsQ6vTu3SNbsYeMa7/8uvl1efVZsJtn6saFZrrPxtwbdubcdcm43SVx4d5JHfGlSg27/j LvfDkON/mPyYrCt8IwW079rzzvJY/E/qSk9a0rNe6x2mspqLv7lb1VgcmewWvKiq/jHfgqnN fF43/j0xZNn9x3Bh9kytfudnX/luTBDXD01YZr5n8qEldrm9xttyntgeXOF1WeG3y3X1TZ+Y 56uL/Hn4tfvVjDuSeQtNVjH8kfZfomv9ycqWZ/qUjRtE6zXbV88P3mVa0Fcs257zXqi8PM01 5p7Ayo05JnpO2ioPj65cI7LLh+tYtV/uJA/tzQ4Va85M3rJhkyp/YHVKPM/zDN5C/p3zmszN 9VYrsRRnJBpqMRcVJwIAunBPmzsDAAA= X-CMS-MailID: 20210929210819eucas1p2edb6fc892fbb9f87f025db20941ace98 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20210929183439eucas1p1de30c3fb5681a8c8d250f482954f92ed X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20210929183439eucas1p1de30c3fb5681a8c8d250f482954f92ed References: <20210929183357.1490204-1-lucas.demarchi@intel.com> <20210929183357.1490204-3-lucas.demarchi@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org W dniu 29.09.2021 o 20:33, Lucas De Marchi pisze: > 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] == '-' \ > +) Quite clever trick, but I see two issues: - gcc < 8.1 treats expressions with string indices (ex. "abc"[0]) as non-constant expressions, so they cannot be used everywhere, for example in global variable initializations, - it does not work with hex (0x1) or octal values (01) It is probably OK for private macro, but it can hurt in kconfig.h, especially the 2nd issue Regards Andrzej > > #endif /* !__I915_UTILS_H */