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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 365DBC433DF for ; Thu, 4 Jun 2020 16:49:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E5082072E for ; Thu, 4 Jun 2020 16:49:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729986AbgFDQtz (ORCPT ); Thu, 4 Jun 2020 12:49:55 -0400 Received: from smtprelay0196.hostedemail.com ([216.40.44.196]:39834 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729115AbgFDQtx (ORCPT ); Thu, 4 Jun 2020 12:49:53 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay02.hostedemail.com (Postfix) with ESMTP id 5E9B0503E9; Thu, 4 Jun 2020 16:49:51 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: field18_4511ff726d98 X-Filterd-Recvd-Size: 2054 Received: from XPS-9350.home (unknown [47.151.136.130]) (Authenticated sender: joe@perches.com) by omf12.hostedemail.com (Postfix) with ESMTPA; Thu, 4 Jun 2020 16:49:49 +0000 (UTC) Message-ID: <28b33db24b1dbd15cd6711cd473f1c0e5f801e74.camel@perches.com> Subject: Re: [PATCH] linux/bits.h: fix unsigned less than zero warnings From: Joe Perches To: Andy Shevchenko , Rikard Falkeborn Cc: Andrew Morton , Arnd Bergmann , emil.l.velikov@gmail.com, Kees Cook , Linus Walleij , Linux-Arch , Linux Kernel Mailing List , Syed Nayyar Waris , William Breathitt Gray , Masahiro Yamada , kbuild test robot Date: Thu, 04 Jun 2020 09:49:46 -0700 In-Reply-To: References: <20200603215314.GA916134@rikard> <20200603220226.916269-1-rikard.falkeborn@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.36.2-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2020-06-04 at 09:41 +0300, Andy Shevchenko wrote: > I think there is still a possibility to improve (as I mentioned there > are test cases that are absent right now). > What if we will have unsigned long value 0x100000001? Would it be 1 > after casting? > > Maybe cast to (long) or (long long) more appropriate? Another good mechanism would be to compile-time check the use of constants in BITS and BITS_ULL and verify that: range of BITS is: >= 0 && < (BITS_PER_BYTE * sizeof(unsigned int)) range of BITS_ULL is: >= 0 && < (BITS_PER_BYTE * sizeof(unsigned long long)) There would be duplication similar to the GENMASK_INPUT_CHECK macros.