Received: by 2002:ac8:71d8:0:b0:40f:fb00:664b with SMTP id i24csp209004qtp; Fri, 4 Aug 2023 08:38:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8orbWngwV1liFQnMlSQzhr0hkjSEU6RNzk/tLyYW9elaDQbWsdR7T69rS1gyT2bTH3+5M X-Received: by 2002:aa7:ccd2:0:b0:522:45db:48e1 with SMTP id y18-20020aa7ccd2000000b0052245db48e1mr1741350edt.31.1691163529422; Fri, 04 Aug 2023 08:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691163529; cv=none; d=google.com; s=arc-20160816; b=rx9qtA+VJOfb0YC7PzeXe3My9hVXe6l+b/2CCciXNO7Mz55Y64BO00wF8+ZspMm5nL W9ccdPTefgfZh/xGTV/BC29aQeNdmUswxGR5reHp1cLXNMZn3mHpzAlqPGiHcWBCXnxq Ns/Oh7U4LXIMYDvqnCs1T9aCBwDpbhfXUFticNchRi3B26KgDUMTGA0CR8KnMudMsJsJ wmMsnOKh20eRvIyL4PwBDaIkE+MPmT6Yhebg9NzV6rSmcxy5GiRfO+LtDRZzQTc4tdIJ qNCt+75PLcWScHhmMq7EqMTZ2EVQW+9tos2xUCiYWhH5450IzfWq5v83AJSBmH/P72bM Ca5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=Q89TgZP148tw3sGV2fMFd0xddZ+8fgGBWmVH3/UnPAk=; fh=MKPlzuQdHp+YF9ycqmOIFnjWVABlLBhjNIX562E1MRM=; b=V1f/NtE/sZyf2fkil8HNcAegl/cjudVqXwTV48d1Fv8WftU3f/UvxRkfwd/cRssZTD yaKwVVAI3TjZFxmjrrzeiNJyseZLEzWV8i6sezdmRs/3KqyPLBfWSDQQMC1r/Kb4NZh6 dXXQoIoMRasNcVHjv4S3+Sf2p419g7JHNwCqCoHe6/GkFp2JYk1uJhlIBehn5U2bnjj2 E0WvZD0rlYgYz0PZ5CJtBXwvFg1qRZT2Oe1EoG/GrAvwYNycz1lou47wSwe9zsouYPVO YaYijsjNZp080uzsu4ZPhLj/Zx7nwcDQV4XPEuhr5gXvCBca3J9QWiUevdUOY6VsR9aq d+CA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k3-20020a056402048300b0051e7235b2e8si1622069edv.542.2023.08.04.08.38.24; Fri, 04 Aug 2023 08:38:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229873AbjHDPMC convert rfc822-to-8bit (ORCPT + 99 others); Fri, 4 Aug 2023 11:12:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231811AbjHDPL4 (ORCPT ); Fri, 4 Aug 2023 11:11:56 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4602949F2 for ; Fri, 4 Aug 2023 08:11:53 -0700 (PDT) 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-69--ezDvafoOoC2ioaAAB2V4A-1; Fri, 04 Aug 2023 16:11:51 +0100 X-MC-Unique: -ezDvafoOoC2ioaAAB2V4A-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 4 Aug 2023 16:11:49 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Fri, 4 Aug 2023 16:11:49 +0100 From: David Laight To: 'Paul Moore' , =?iso-8859-1?Q?Christian_G=F6ttsche?= , "selinux@vger.kernel.org" CC: Stephen Smalley , Eric Paris , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v2 2/9] selinux: use u32 as bit type in ebitmap code Thread-Topic: [PATCH v2 2/9] selinux: use u32 as bit type in ebitmap code Thread-Index: AQHZxno7WAML9teEJUiVyNIDpo4Zsa/aOz6A Date: Fri, 4 Aug 2023 15:11:49 +0000 Message-ID: <52329f0195a549d1b7abb3417cb2c225@AcuMS.aculab.com> References: <20230728155501.39632-1-cgzones@googlemail.com> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] 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: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,PDS_BAD_THREAD_QP_64, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paul Moore > Sent: 04 August 2023 03:20 > > On Jul 28, 2023 =?UTF-8?q?Christian=20G=C3=B6ttsche?= wrote: .... > > + last_startbit = (u32)-1; > > I can't say I'm as current on all of the C standards and compilier > oddities as some other in the Linux kernel space, but my > understanding is that on assignment the right value is always > implicitly type cast to the type of the left variable, is that not > true? Assuming it is true, I think this explicit cast isn't > necessary and could actually be harmful if we need to change the > ebitmap types in the future. The only question is where any required sign extend happens. If you do: u64 val = -1; then the signed int is first sign extended to 64 bit and then converted to unsigned (which just copies the bit pattern on any sane system that Linux might run on). Whereas: u64 val = (u32)-1; Converts an (assumed) 32bit -1 to unsigned and then zero extends it. What you should really be using is a named constant that is (for the current implementation) (~0u) and doesn't ever need any casts and is always unsigned. If you are actually worried about 'int' being other than 32bits then there will be a lot more places that need fixing. But you could use ((u32)~(u32)0) if you really want to allow for 'u32' being both smaller and larger than 'int' and for non 2's compliment (eg 1's compliment and sign overpunch) systems. (Good luck on finding a working C compiler for either of those.) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)