Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2251695pxp; Mon, 7 Mar 2022 11:19:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFiIA1L+Ao1JYXEjmmBtiW4alOO1KRyPScX/ONvTfc2zfLEJv/txko1OjpcKssdyfcxX8E X-Received: by 2002:a17:902:bb93:b0:14f:3c15:566f with SMTP id m19-20020a170902bb9300b0014f3c15566fmr13594081pls.6.1646680762347; Mon, 07 Mar 2022 11:19:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646680762; cv=none; d=google.com; s=arc-20160816; b=AngitMn8g0jqI63VTOg6bXNutstV3F2G0I6K1XkKxJ828i2rxJf5vusfjRh2ShAlqL dLa89LJLwLRMmOf6S9xSwV9r8O6WC+K3fQ7IdYyuY5n2JsXATrf/TGyvXu4Ma8wLg6fr 0Q5hGkFaRWHo7tmiEGRXcYzqOjnCyV4VVJFNOyqxqvEkPWfWxGRluFLK+gk4ffL83+0W YRy/uTLrfvmjxGCX+Hro9anUprAwz6UZNWfr6xFKSk4IqTggO6T/4DKpLKCpRCfStSuo UDs5MwNOL4ZWJcct/VeIkIUUEhzT1ZdWplFq/O0CtqJD2Y2oGVhcMqY9+nYU/KQ/FgNU u2gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=tKIMSKOmQczp0e6D3JRJ9osYjA5YlKV5jswL6vSd9pk=; b=tFZp+U1BsUcMP0H/42U0OPYVFqV8kMAdCjatSTl0y/p3ZlRhMywyeo1W0aCrg9L5RA NHgpaTdsY11rXV/ukimklGjNV3/Kj/jxTZEuUV99FntOoS6ML1/TBziYxxcEzNrkeOEr 56UNnMt/F/wvxNP22LqFdVUdutzgf/kas/GzyLolgGF2PQA6DwsbbHn2Ew+RzDgTUa/K y43+SrCHbAc4RKYvVjU/ZQsrUgusgsgt8TWSc8m+T6nZ+DyPSMq7YuV6F97a+y+M9FXn HVnenb1zkex3zYOLbihheX1dtqNdRmBjTifLlAkNf+zawoIetYLA6qX2uhTLbwOIaNNC WKTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZQi7BcyO; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q25-20020a635059000000b0036c231afb1dsi12943164pgl.733.2022.03.07.11.19.04; Mon, 07 Mar 2022 11:19:22 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZQi7BcyO; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243888AbiCGQdH (ORCPT + 99 others); Mon, 7 Mar 2022 11:33:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234814AbiCGQdH (ORCPT ); Mon, 7 Mar 2022 11:33:07 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88F3793999 for ; Mon, 7 Mar 2022 08:32:12 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id g20so20743802edw.6 for ; Mon, 07 Mar 2022 08:32:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tKIMSKOmQczp0e6D3JRJ9osYjA5YlKV5jswL6vSd9pk=; b=ZQi7BcyODgCaLpWI/kNli2EcnYEqbd8pRZdohi1haz2FUjxyyCk5U6OMre3VnDW9Tq 7xpDQtt0UZSpQk19GGPy3pCdMF03L+Ji9FQDHjooCGnS2K3CC5Le3RDjEPFLtrg6dKMq 6cuqAz5dhEHDcD5jBN/XA+0liSXvF1o80wpOfgsyUsAGY0OvPdXkXFFpa3dZacbCt3cb t4PnPCzfbq/hl5mkMe70tQY8rvTa1gVp3sO8ENYO28Z8o2Oy0H2hfAPyj+8ZvTn2UZqB iQV9VReyIv3jOXGc597NGm7+nlUi4d/TJGU5DDyVfLfKYao+oD6Vyj0ZYuwK8F3SqSI9 Zxuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tKIMSKOmQczp0e6D3JRJ9osYjA5YlKV5jswL6vSd9pk=; b=TSk4DNdvBTT8l0nBWYLfBJ1kt3fwXlMAmvLOgT9hS4KSlG657LBvWwhT5YhFue2dcg T4by0XlVb/452dXttu4vTNBsEq3O3ezPJkuKURvZt6XUNmpiGDJhPlMpTITRlyx3Oj64 nZQv5B/8SVQl3loKwvUo0qUT2dpH+C/+ugCNy0gp0d/69oQe4UxWPYiFOJ9IP3wTb0va WMk3YaIqIYPHQ1SV82O30+PAQy+dfF/nX6Tv9V+o4zhm4y5cDLqtany6o4lqGnZAhaX5 RBloKwKi/Mr15kNmEVYQnuhbEpk37A1oAOqGm3+wFFYKIO/6zP9wOY3J+dx/3+wGuDUt /y0g== X-Gm-Message-State: AOAM532HiLqYMAHZnTY2p/VGf98Hivj4G5o/wqW7X9uTAUKo5b2DDqJ2 Vr6e50D9NXhBIW//Pe8Vltk97Af1zq0jGdKkW2A= X-Received: by 2002:a05:6402:268a:b0:410:cc67:e792 with SMTP id w10-20020a056402268a00b00410cc67e792mr11879020edd.218.1646670731100; Mon, 07 Mar 2022 08:32:11 -0800 (PST) MIME-Version: 1.0 References: <20220304124416.1181029-1-mailhol.vincent@wanadoo.fr> <20220307105810.1747024-1-alexandr.lobakin@intel.com> <20220307150750.1762040-1-alexandr.lobakin@intel.com> In-Reply-To: <20220307150750.1762040-1-alexandr.lobakin@intel.com> From: Andy Shevchenko Date: Mon, 7 Mar 2022 18:30:53 +0200 Message-ID: Subject: Re: [PATCH] linux/bits.h: fix -Wtype-limits warnings in GENMASK_INPUT_CHECK() To: Alexander Lobakin Cc: Vincent MAILHOL , Arnd Bergmann , Rikard Falkeborn , Andrew Morton , Linux Kernel Mailing List , Kees Cook Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Mon, Mar 7, 2022 at 5:10 PM Alexander Lobakin wrote: > From: Vincent MAILHOL > Date: Mon, 7 Mar 2022 22:50:56 +0900 ... > For example, people tend to make the following mistake: > > unsigned int i; > > for (i = 0; i ...) { > ret = setup_something(array[i]); > if (ret) > goto unroll; > } > > unroll: > while (--i) > unroll_something(array[i]); > > The loop will never end as `i` was declared as unsigned. > -Wtype-limits catches this. This looks like a wrapping value issue, not sure if the type limits makes logical sense. What I'm saying is that the waning is controversial. It may help or it may make noise. > Not speaking of checking unsigned variables on < 0: > > unsigned int num; > > /* calculate_something() returns the number of something > * or -ERRNO in case of an error > */ > num = calculate_something(); > if (num < 0) > ... Depends on the context. Here is a mistake, but there are plenty of cases when it's okay to do so. And in the above the variable name is misleading with its semantics, The proper code should be unsigned int num; int ret; ret = ... if (ret < 0) ... num = ret; Again, the warning is controversial in my opinion. -- With Best Regards, Andy Shevchenko