From patchwork Thu Feb 2 17:04:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 93117 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp191215obz; Thu, 2 Feb 2017 09:04:22 -0800 (PST) X-Received: by 10.84.218.133 with SMTP id r5mr14013948pli.90.1486055062918; Thu, 02 Feb 2017 09:04:22 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si22838538plj.152.2017.02.02.09.04.22; Thu, 02 Feb 2017 09:04:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752043AbdBBREU (ORCPT + 25 others); Thu, 2 Feb 2017 12:04:20 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:37936 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751308AbdBBRET (ORCPT ); Thu, 2 Feb 2017 12:04:19 -0500 Received: by mail-wm0-f44.google.com with SMTP id r141so98020556wmg.1 for ; Thu, 02 Feb 2017 09:04:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=e1/RSaZfNWAYX26VsocIKmdLi1gIDHipUJTbZTBxlqE=; b=VVKmvatgpA9NBxfHQeAyBdvzALhnk+VftE0Vk2WjZQ5DITZK0SCzGOKdHd31oit67D 4dUF+r/5/4H2kFZG4UGEXvzxYRF6Iz0M3ud+4vRBF6YkgMcsgJQB9w+vw806+f2MU3uM eoKhTd68WyasTSNgs+Nl8Ma2TCvBnMG5xG0tA= 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; bh=e1/RSaZfNWAYX26VsocIKmdLi1gIDHipUJTbZTBxlqE=; b=MtgwXHPLl/r6LVNHEnntdn2F3atoC7epQR5cXHYijuMMMUdxrNDd8Zw0Ec4cQn1l3e SfymxXO0s70BqBqlTqrzEsqOGYyaiuv2OVl5krNezjhP+5jW2v2mQ4nDzwyMTi27w3rr SU3OumDV1OWYjDXB0oXrIM9kNSXEL6QBgQE8yCKY8W00ATrbq9lPSowm6xwEw17Y/7JB DlLjbTd5TOM5wXh9/GK0PE8twWgMaZrKmE3oZW2WuHKMwdWTGdixUdi/0qj7mhSS9b85 xfcthpm6YWK1PpIefKUHhLl/MFiYVBWEGIKXF++8J0PzxgKo6aNjco3IEI6gXRa05OMf bcqQ== X-Gm-Message-State: AIkVDXIWpKQDWZcv+o+zFCYp+KKxGfBOllQsAVTZnNe1Vc/T1ZdAnCsEDwhw0IP7XvAbwOqg X-Received: by 10.28.103.69 with SMTP id b66mr8258895wmc.73.1486055058191; Thu, 02 Feb 2017 09:04:18 -0800 (PST) Received: from localhost.localdomain ([105.130.17.13]) by smtp.gmail.com with ESMTPSA id w99sm40918420wrb.5.2017.02.02.09.04.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Feb 2017 09:04:17 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, labbott@fedoraproject.org, will.deacon@arm.com, sboyd@codeaurora.org, gregory.clement@free-electrons.com, james.greenhalgh@arm.com, mingo@kernel.org, peterz@infradead.org, markus@trippelsdorf.de, akpm@linux-foundation.org Cc: linux-arm-kernel@lists.infradead.org, torvalds@linux-foundation.org, joe@perches.com, Ard Biesheuvel Subject: [PATCH] log2: make order_base_2() behave correctly on const input value zero Date: Thu, 2 Feb 2017 17:04:12 +0000 Message-Id: <1486055052-6442-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function order_base_2() is defined (according to the comment block) as returning zero on input zero, but subsequently passes the input into roundup_pow_of_two(), which is explicitly undefined for input zero. This has gone unnoticed until now, but optimization passes in GCC 7 may produce constant folded function instances where a constant value of zero is passed into order_base_2(), resulting in link errors against the deliberately undefined '____ilog2_NaN'. So update order_base_2() to adhere to its own documented interface. Signed-off-by: Ard Biesheuvel --- This is a followup to Will's message 'Build failure with v4.9-rc1 and GCC trunk -- compiler weirdness' which can be found here: http://marc.info/?l=linux-kernel&m=147672952517795&w=2 include/linux/log2.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/include/linux/log2.h b/include/linux/log2.h index fd7ff3d91e6a..d3fe63b12e96 100644 --- a/include/linux/log2.h +++ b/include/linux/log2.h @@ -203,6 +203,17 @@ unsigned long __rounddown_pow_of_two(unsigned long n) * ... and so on. */ -#define order_base_2(n) ilog2(roundup_pow_of_two(n)) +static inline __attribute_const__ +unsigned long __order_base_2(unsigned long n) +{ + return n > 1 ? ilog2(n - 1) + 1 : 0; +} +#define order_base_2(n) \ +( \ + __builtin_constant_p(n) ? ( \ + ((n) == 0 || (n) == 1) ? 0 : \ + ilog2((n) - 1) + 1) : \ + __order_base_2(n) \ +) #endif /* _LINUX_LOG2_H */