Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp530117ybz; Wed, 22 Apr 2020 03:04:58 -0700 (PDT) X-Google-Smtp-Source: APiQypLxaImLbNKx8khjulTdNsbrNyWCdobnnsvkQl1R+DnOm0Hp6IQwYSSVcdQ4g4VyKFIaoX6w X-Received: by 2002:a17:906:1e47:: with SMTP id i7mr1141980ejj.61.1587549898564; Wed, 22 Apr 2020 03:04:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587549898; cv=none; d=google.com; s=arc-20160816; b=o4YDpE5Btfp9HO5+VdlsoW6xTOMdh5A0VpQsiySfvegn8gcLrxEOQsUtr+f/+dt1A0 JVg3Vdv2xCkWQuL0+5V1ptnVLxlOBMU5KLJojJVkJzTqyN8beGpsogOZWr9ZPTOdYYp3 kwwJtgFut73gznk+Va88BzsdG8KkBd1Qs7ucuS0fI26mOcyJnZkLmrPmpBQm/SRO/fnj 0RMiUFpjnnFd/56cZWUiMI3xDDZbuPw6rVG6LXd+YIzEYFpUcaPPN8mSzlpWV5FaFgJQ zYrZmJvbFDVGrK8tNxSuiow/YP22Ph9NXl6HO2qwdMNK1fQ/JyV0pgcd+vg1w/X/SJeF AAEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=b6YIv3xsLWf1E+7EyCZ1kBIGU/2CJOfVll09q3rmM9I=; b=FdwhsoXMARHfdPxhY3QSIJnIJO27Rm0kzBAKkzSXL5KJQEJuVi2UoYpyDDb9taz32c Oh21a67ndSYZDsXN2DgthuqzeSCT5/OqXSS4x10gK/VPWIsJZ5uw59Sgx3SDLXcw4h1V /mWpnLPtDHnUqLm6KgvUcPw4Nd9byvWGtIylQ6wDmo4sU3RVqLEEr4kUZnv77DjUwTEA 7BtH6/VvZPGD0FclIxh6MlN/A1WTKQVQc+qQn056AfJsuNUhjLXTBYfBgZfaQ/88ah3M p8eYVo3mpovF4Ts+hZyFyrk6pU5RLPvMyXl/eX1uj390hd1Ni+zIw/YRxsoORCXxYm1K fTQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AL7TBk1N; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w26si3226446ejs.63.2020.04.22.03.04.35; Wed, 22 Apr 2020 03:04:58 -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=@kernel.org header.s=default header.b=AL7TBk1N; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727016AbgDVKCf (ORCPT + 99 others); Wed, 22 Apr 2020 06:02:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:51510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726995AbgDVKC1 (ORCPT ); Wed, 22 Apr 2020 06:02:27 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AD98820735; Wed, 22 Apr 2020 10:02:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587549747; bh=aS6rCUp0LQwVhHJsV5uUa9qCEMgITqc2OzijRDMUb+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AL7TBk1NbBo081jAlILAgVrA9CaKCJlKcQjuUqFGdDx2eA3v5TiT/lF2TVjqdCpwt xfbw5UUNOBDJXkHlHIg2Yon8rx2Xt2cNm+3FPa2qOcuqtBtmyalzJMWNPiS0Hnj4El gWvDYeweegsQrQuszMSJBymGA4SHOkdsMSQS/0EA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vegard Nossum , Andrew Morton , Masahiro Yamada , Daniel Santos , Rasmus Villemoes , Ian Abbott , Joe Perches , Linus Torvalds , Sasha Levin Subject: [PATCH 4.4 089/100] compiler.h: fix error in BUILD_BUG_ON() reporting Date: Wed, 22 Apr 2020 11:56:59 +0200 Message-Id: <20200422095039.026259456@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200422095022.476101261@linuxfoundation.org> References: <20200422095022.476101261@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vegard Nossum [ Upstream commit af9c5d2e3b355854ff0e4acfbfbfadcd5198a349 ] compiletime_assert() uses __LINE__ to create a unique function name. This means that if you have more than one BUILD_BUG_ON() in the same source line (which can happen if they appear e.g. in a macro), then the error message from the compiler might output the wrong condition. For this source file: #include #define macro() \ BUILD_BUG_ON(1); \ BUILD_BUG_ON(0); void foo() { macro(); } gcc would output: ./include/linux/compiler.h:350:38: error: call to `__compiletime_assert_9' declared with attribute error: BUILD_BUG_ON failed: 0 _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) However, it was not the BUILD_BUG_ON(0) that failed, so it should say 1 instead of 0. With this patch, we use __COUNTER__ instead of __LINE__, so each BUILD_BUG_ON() gets a different function name and the correct condition is printed: ./include/linux/compiler.h:350:38: error: call to `__compiletime_assert_0' declared with attribute error: BUILD_BUG_ON failed: 1 _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) Signed-off-by: Vegard Nossum Signed-off-by: Andrew Morton Reviewed-by: Masahiro Yamada Reviewed-by: Daniel Santos Cc: Rasmus Villemoes Cc: Ian Abbott Cc: Joe Perches Link: http://lkml.kernel.org/r/20200331112637.25047-1-vegard.nossum@oracle.com Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/compiler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 5508011cc0c79..5f8749440c6af 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -502,7 +502,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s * compiler has support to do so. */ #define compiletime_assert(condition, msg) \ - _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) + _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) #define compiletime_assert_atomic_type(t) \ compiletime_assert(__native_word(t), \ -- 2.20.1