Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1124740rdb; Sun, 7 Jan 2024 05:03:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWIB2hdboMRRYyjgIek1tY+bp8+XSlueGuPR1SYG2CNqXwCVVy5xvt5nWsHEWNMYoK4JbZ X-Received: by 2002:a05:620a:88a:b0:783:596:ca79 with SMTP id b10-20020a05620a088a00b007830596ca79mr1738368qka.69.1704632627427; Sun, 07 Jan 2024 05:03:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704632627; cv=none; d=google.com; s=arc-20160816; b=YHhTiXh16irtzDuSaoZoj+zkwKLUw4Oa8cLXLeAFndhub5jnlfhwMLpSIz56Bthk5H cIa+JTXuwTElRL8dola/GxG1erwuVdtQYERxzSWncFvNo+opXz1gOIV+7jJHlY1YL51H 7z5/WSNZuA0awf8IUM1rG9dTwIL2+18A2ypY/I2+XuhY5SdDyrZqWK3OH+gsh5FLVVqT FmQWxUv+BP5Vo0gs+FSBajQyNLRBjgLvswUVN8Sw0ASseUhDU8c7BrfIap/dBzAq3wyH h5ttfu0smqdqrfglXvuxXByD2q3tIlKOWaZXb8nv6D3E9boXo9NK+xkLRIPpr+MG6gl9 dzrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pIoiAUd5EHacoKar9ctxfTdqzibQzhULbJb4hbV1R+c=; fh=3FR2Onrp0dLtakmC1Br+hwfUoAZ8jbsu664tR32J+Ls=; b=S0Te7MNuvB0/ZgIfkenPo5vFsBeAIFJupI5ecyDIY2HWnAScVI19HcTsw52c+6wc9k DDij0LUASbzFZTJkJfGPJCCut2Z2Myuhej5YttZHZaR8lmJE8wX05a1XVaBYtHM0xeM+ YhKOpEl+Uf7ggs1TsBadEbgWSBOFhw3H3WdSrj0FxA31qofEHOfoW2v03m7Gu3I7U1gc xD7yX42R0joy6U28v8YY8a6vY58fMkuZsSb3ZQE4VApB8eWByqOGX21QMxpzOFv28cFq pgeLmngwgUuVuHlZimOON8epU4k6FQ/2ZcmMq/+bjzEwhQbew/yEdM/D4F5OwI77C6KY ahBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Nmaaoaaf; spf=pass (google.com: domain of linux-kernel+bounces-18864-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18864-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w3-20020a05620a444300b007831b4b1bbdsi1226742qkp.369.2024.01.07.05.03.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 05:03:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18864-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Nmaaoaaf; spf=pass (google.com: domain of linux-kernel+bounces-18864-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18864-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2D5FB1C210A4 for ; Sun, 7 Jan 2024 13:03:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF591134A6; Sun, 7 Jan 2024 13:03:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Nmaaoaaf" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2847B134A0; Sun, 7 Jan 2024 13:03:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14C9AC433C7; Sun, 7 Jan 2024 13:03:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704632621; bh=JQUOkY7pGDbzmZACx5v6FcY10tfDTJxeBz0eqhJQOFs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Nmaaoaafir2w9oojohBMa85RUSZbLgmAllYnvNNYv0+Np2+VC9N/d3ZttJgPVWDAE dFzbnpajB+dddDJlZCexo5udEEO9NPlipCYB4V3r43urL7OhUPIxSJQHsNMjmAfjpI lWN0emjSK+u0hVC4BKO28l7MJm+VjfODV5R0osjPIO7z0FDDlJhMRh79mQlKPAhpP9 uoOkk8we9HA+CTZqXVEvMjqxbUkeUkbRYeLrCRnkeoU5yLr5OwSX/mCuVLe5vw+UbN 20ge22SMMNKGhNMWFoINKRsTSoSMySj5TwrovqSKgIILqM2pat4eMQk2jovNxps12q cwczWkwcdXkxw== Date: Sun, 7 Jan 2024 14:03:32 +0100 From: Luc Van Oostenryck To: Linus Torvalds Cc: Dmitry Torokhov , kernel test robot , Arnd Bergmann , linux-sparse@vger.kernel.org, Chris Morgan , oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: include/asm-generic/unaligned.h:119:16: sparse: sparse: cast truncates bits from constant value (aa01a0 becomes a0) Message-ID: <7yxju53lhprhihayiue3dp4xnmzpugygl47tt4w56pyscsf6tx@2w3eytgeav7u> References: <202401070147.gqwVulOn-lkp@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Sat, Jan 06, 2024 at 09:54:05PM -0800, Linus Torvalds wrote: > On Sat, 6 Jan 2024 at 16:42, Dmitry Torokhov wrote: > > > > This is not really a kernel/driver bug, just sparse being over-eager > > with truncation detection. I wonder if we could make sparse skip this > > check on forced casts like this: > > No, please don't. > > Just face the fact that using integer casts to mask bits off is a bad idea. > > ... > > The *natural* thing to do is to simply make the masking itself be > explicit - not the cast. IOW, just write it as > > *p++ = (val >> 16) & 0xff; > *p++ = (val >> 8) & 0xff; > *p++ = val & 0xff; > > ... > > And while the code is a bit more to read, I think it is actually to > some degree more obvious to a human too what is going on. I fully agree. It's kinda sad is that there is more than 800 occurrences of this "cast truncates bits from constant value" warning and almost all of them are of the kind: "a 32bit constant must be written in 2 steps via 16bit IO registers" In these cases, no bits are lost, they're just written in the other write, and real problems, when present, are drown/lost into these 800 harmless ones. It's in fact the 4th most common warning in the kernel, the top 10 being: 2858 incorrect type in assignment (different base types) 2715 cast to restricted type 923 incorrect type in argument (different address spaces) 818 cast truncates bits from constant value 739 restricted type degrades to integer 549 context imbalance - unexpected unlock 500 symbol was not declared. Should it be static? 407 cast removes address space '__iomem' of expression 344 incompatible types in comparison expression (different address spaces) 323 context imbalance - different lock contexts for basic block -- Luc