From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5627C433E6 for ; Mon, 8 Feb 2021 14:38:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62BA564E75 for ; Mon, 8 Feb 2021 14:38:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232733AbhBHOhs (ORCPT ); Mon, 8 Feb 2021 09:37:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:40372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232098AbhBHOKK (ORCPT ); Mon, 8 Feb 2021 09:10:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 312E764E2E; Mon, 8 Feb 2021 14:09:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612793369; bh=pfuX+SzeabT/4QNFzcyDToqBwhJ8kDvzDqbqprBktCY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ICxPscZFkIdbaqA030bVRyjK2mIi2htQa+qCk4ekMu9LkQeo7dYvrzmhj+nWhApmg ykl2732A3kFCW8scyIudlIbKzvXSaT29U+uEikAeK9akVxBvmiL3hY1I9kvvWnOexR xFsuWx9/4FXpNyut/htwfv3hfaWUE808AFi4NaeI= Date: Mon, 8 Feb 2021 15:09:26 +0100 From: "gregkh@linuxfoundation.org" To: David Laight Cc: 'Sasha Levin' , "masahiroy@kernel.org" , "michal.lkml@markovi.net" , "linux-kbuild@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "torvalds@linux-foundation.org" Subject: Re: [PATCH 2/3] kbuild: clamp SUBLEVEL to 255 Message-ID: References: <20210206035033.2036180-1-sashal@kernel.org> <20210206035033.2036180-2-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 08, 2021 at 01:48:06PM +0000, David Laight wrote: > From: Sasha Levin > > Sent: 06 February 2021 03:51 > > > > Right now if SUBLEVEL becomes larger than 255 it will overflow into the > > territory of PATCHLEVEL, causing havoc in userspace that tests for > > specific kernel version. > > > > While userspace code tests for MAJOR and PATCHLEVEL, it doesn't test > > SUBLEVEL at any point as ABI changes don't happen in the context of > > stable tree. > > > > Thus, to avoid overflows, simply clamp SUBLEVEL to it's maximum value in > > the context of LINUX_VERSION_CODE. This does not affect "make > > kernelversion" and such. > > > > Signed-off-by: Sasha Levin > > --- > > Makefile | 12 +++++++++--- > > 1 file changed, 9 insertions(+), 3 deletions(-) > > > > diff --git a/Makefile b/Makefile > > index 49ac1b7fe8e99..157be50c691e5 100644 > > --- a/Makefile > > +++ b/Makefile > > @@ -1258,9 +1258,15 @@ define filechk_utsrelease.h > > endef > > > > define filechk_version.h > > - echo \#define LINUX_VERSION_CODE $(shell \ > > - expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ > > - echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' > > + if [ $(SUBLEVEL) -gt 255 ]; then \ > > + echo \#define LINUX_VERSION_CODE $(shell \ > > + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 255); \ > > + else \ > > + echo \#define LINUX_VERSION_CODE $(shell \ > > + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ > > + fi; \ > > + echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ > > + ((c) > 255 ? 255 : (c)))' > > endef > > Why not use KERNEL_VERSION to define LINUX_VERSION_CODE ? > Basically just: > echo '#define LINUX_VERSION_CODE KERNEL_VERSION($(VERSION), $(PATCHLEVEL)+0, $(SUBLEVEL)+0)' Because we are "clamping" LINUX_VERSION_CODE() at a x.y.255, while KERNEL_VERSION() continues on with the "real" minor number. thanks, greg k-h