Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1553791rdb; Mon, 8 Jan 2024 03:05:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPzvnUvvgIfH1tzpwufRQu6zFoeZ9CmQBhpUOy49L6VwhxGsRmIEMgkYentFympypbw9u1 X-Received: by 2002:a05:6512:2142:b0:50e:7bf5:5424 with SMTP id s2-20020a056512214200b0050e7bf55424mr1131054lfr.47.1704711900349; Mon, 08 Jan 2024 03:05:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704711900; cv=none; d=google.com; s=arc-20160816; b=L9e5JRqIawjmvszOqrwejQ/GEE6ldzVJwQtOAknOE5leyP/hq2UJ5Ah7xqEKcIKcsF +YIF4i0/4+Twy2rA752yK8d7iamwWv8TSYaeE+Zpf6eFZ5uljRXzawpMLnisa8XVbygV 2zVC5c5kFjFmgZLkixijf9W7nGwG064evx/sGQRpxZRtJSfUVWe2jMK74cD58pR8fQOJ oQUjZwNq5aMMuOh0HABn+CFdb1HFJQ5TEv9pkWzvCkBoxxsNCrmtm/d0LtKrRUCaCj3E /iSACjNFcLzAPCN9rrNafZJaD83XyZE4DyhmC8Qgz1pLRvXwlQM5wGEvRWVFVGBPKPkT kpHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=HoATBBUdvY9NOEsne0KnNvrU8i5G0LoJKMpVdqsDqIg=; fh=nJstDhpUUlsXSfN4JibI8UsM82q2trfXGvKhkgJ2KUs=; b=b/djNjbydEFIYqrRaIy69EwV9RunpUVpyAlq0tlaEZCmR7s4zBRWAep0Vup8mWXlUA yUQtdpioTuzJnsnCmzWRWe8bSV3pvGzzyBhNCC+XSmm9GQZT3Jf70PkDvY9j8kYhKoaq jZ40nHCjG+LCSxTyX6kl0LDqNh02dTbwxWVXFj5LYgbmm27IRYYchbaZs7AvODYo6Fg6 jshw3vmIo/hxp/4yG2eIBKH3zKKcfFoWuAF5je7ce+YnM+CflXk+LywsGc4X3K7f/UR3 g2QKb46tDCguBQyHuTZmqumoBgpnyJvDqotqWYS0n2D/83IMWZYHLlJhf+difYUNLp9o ES5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19372-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19372-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u5-20020a50a405000000b00554767dcb7bsi3190302edb.534.2024.01.08.03.05.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 03:05:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19372-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19372-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19372-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1A5451F225F0 for ; Mon, 8 Jan 2024 11:05:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E3E41429E; Mon, 8 Jan 2024 11:03:52 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) (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 D142E14292 for ; Mon, 8 Jan 2024 11:03:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-253-EyLyuJXtPwmi8cp329UFpQ-1; Mon, 08 Jan 2024 11:03:47 +0000 X-MC-Unique: EyLyuJXtPwmi8cp329UFpQ-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 8 Jan 2024 11:03:22 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 8 Jan 2024 11:03:22 +0000 From: David Laight To: 'Dmitry Torokhov' , Arnd Bergmann CC: "linux-arch@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Linus Torvalds Subject: RE: [PATCH] asm-generic: make sparse happy with odd-sized put_unaligned_*() Thread-Topic: [PATCH] asm-generic: make sparse happy with odd-sized put_unaligned_*() Thread-Index: AQHaQfo/rBE9iMqwLUOx80/L8Ll8bLDPvnqw Date: Mon, 8 Jan 2024 11:03:22 +0000 Message-ID: <12d88da48f6947ab86a845e8d02319ff@AcuMS.aculab.com> References: In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable From: Dmitry Torokhov > Sent: 08 January 2024 06:17 >=20 > __put_unaligned_be24() and friends use implicit casts to convert > larger-sized data to bytes, which trips sparse truncation warnings when > the argument is a constant: >=20 > CC [M] drivers/input/touchscreen/hynitron_cstxxx.o > CHECK drivers/input/touchscreen/hynitron_cstxxx.c > drivers/input/touchscreen/hynitron_cstxxx.c: note: in included file (thro= ugh > arch/x86/include/generated/asm/unaligned.h): > ./include/asm-generic/unaligned.h:119:16: warning: cast truncates bits fr= om constant value (aa01a0 > becomes a0) > ./include/asm-generic/unaligned.h:120:20: warning: cast truncates bits fr= om constant value (aa01 > becomes 1) > ./include/asm-generic/unaligned.h:119:16: warning: cast truncates bits fr= om constant value (ab00d0 > becomes d0) > ./include/asm-generic/unaligned.h:120:20: warning: cast truncates bits fr= om constant value (ab00 > becomes 0) >=20 > To avoid this let's mask off upper bits explicitly, the resulting code > should be exactly the same, but it will keep sparse happy. Maybe someone should fix sparse? I have seen a compiler generate two explicit masks with 0xff followed by a byte write for: =09*p =3D (char)(x & 0xff); but I expect modern gcc is ok. > Reported-by: kernel test robot > Suggested-by: Linus Torvalds > Closes: https://lore.kernel.org/oe-kbuild-all/202401070147.gqwVulOn-lkp@i= ntel.com/ > Signed-off-by: Dmitry Torokhov > --- > include/asm-generic/unaligned.h | 24 ++++++++++++------------ > 1 file changed, 12 insertions(+), 12 deletions(-) >=20 > diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unalig= ned.h > index 699650f81970..a84c64e5f11e 100644 > --- a/include/asm-generic/unaligned.h > +++ b/include/asm-generic/unaligned.h > @@ -104,9 +104,9 @@ static inline u32 get_unaligned_le24(const void *p) >=20 > static inline void __put_unaligned_be24(const u32 val, u8 *p) > { > -=09*p++ =3D val >> 16; > -=09*p++ =3D val >> 8; > -=09*p++ =3D val; > +=09*p++ =3D (val >> 16) & 0xff; > +=09*p++ =3D (val >> 8) & 0xff; > +=09*p++ =3D val & 0xff; > } What happens if you implement the as (eg): =09*p =3D val >> 16; =09put_unaligned_be16(p + 1, val); I think that should generate better code. And it may stop sparse bleating. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)