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=-2.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 0E8E8C43461 for ; Mon, 17 May 2021 07:03:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E70C6610C9 for ; Mon, 17 May 2021 07:03:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235018AbhEQHEt (ORCPT ); Mon, 17 May 2021 03:04:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234274AbhEQHEr (ORCPT ); Mon, 17 May 2021 03:04:47 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB86FC061573; Mon, 17 May 2021 00:03:31 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id pi6-20020a17090b1e46b029015cec51d7cdso3145522pjb.5; Mon, 17 May 2021 00:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kso+u5oDEUI6hC/TpN6G+VEPeqtVt8JMKDkpe0hvQw4=; b=NEbHNwThWEj/g23crYRi7RqFA8QTN7P7vSE8qulvyTyQ6IEA61lbeLgBIMLxpkA5kZ ugEXfzy15FDU6bAn2yycy1il8SfAeERdmFfccsen7A2kODq5Zn/w4FvX3wlsdKrU+8u9 a5RfT7u8xCwzH96fptkWr3fGInei2PDt1l9JfMIdwsktQ2Tl149U+R07krzvwhkl/iY5 HAGionsDO3VG4dnaLIokeyFqrTBmQydqVgclx0qJUoLbm/BQycSSeAHfJF7YkxQPzVz1 IF4DXfGjlsuH2IOQ5ETXDc2Kia28lut6eHhyLpVZzQtXKD2MyEw8puW1psx4VfHsiJ13 SfBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kso+u5oDEUI6hC/TpN6G+VEPeqtVt8JMKDkpe0hvQw4=; b=AhHFJq6bxUM/lRkmY+mOBtlLQ9k/rNYWYJRA3970rlhd4CVjr1rSM5Ys6rdWG6uowf coPQO9t1pV6ZvBnNwvCcGk+UFhlKi8uyN1RP7Kgzks9cByS2oo14PpYt3cHCeVDEPl6R ljWaMGJn1crzJhxcOQt/GBFlUdcI91O/TMOY6cZQdj2e7uT6xriouBlYPSViEmIn7CyK P8ZBq+AoKTow40abOsKJECtPYS1Eyj9BhcT7vFtmGcMu8vToIK6YZ3wRgK9GSfCJAc0w b7p7uUnQ4PwX0EGqF7D+My8VQkAQ7qw2BdwUQ0IGPGP2Ibm5xCAs6d7vV8+Gk6QVQk4N yphw== X-Gm-Message-State: AOAM533G446OIKOH39jxCKjk31pU2vU/MHLxw3D1BN0po/TYaidLU2Wc o3CgxIbnYbgbRBQOAFnaVz61tuu/ebjGs3+oSZE= X-Google-Smtp-Source: ABdhPJzEYwkmCqhc0PcoCvbscW8cdar0csJ9Ro1rhG3jcTsBopXsi87oK+hq4MY+OFYFMaVphW4HofSxoxS8Snj4u4Q= X-Received: by 2002:a17:90a:d184:: with SMTP id fu4mr1421945pjb.129.1621235011120; Mon, 17 May 2021 00:03:31 -0700 (PDT) MIME-Version: 1.0 References: <20210513085227.54392-1-colin.king@canonical.com> In-Reply-To: <20210513085227.54392-1-colin.king@canonical.com> From: Andy Shevchenko Date: Mon, 17 May 2021 10:03:15 +0300 Message-ID: Subject: Re: [PATCH][next] gpio: xilinx: Fix potential integer overflow on shift of a u32 int To: Colin King Cc: Shubhrajyoti Datta , Srinivas Neeli , Michal Simek , Linus Walleij , Bartosz Golaszewski , Andy Shevchenko , "open list:GPIO SUBSYSTEM" , linux-arm Mailing List , kernel-janitors , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 13, 2021 at 12:12 PM Colin King wrote: > > From: Colin Ian King > > The left shift of the u32 integer v is evaluated using 32 bit > arithmetic and then assigned to a u64 integer. There are cases > where v will currently overflow on the shift. Avoid this by > casting it to unsigned long (same type as map[]) before shifting > it. > > Addresses-Coverity: ("Unintentional integer overflow") > Fixes: 02b3f84d9080 ("gpio: xilinx: Switch to use bitmap APIs") No, it is a false positive, > const unsigned long offset = (bit % BITS_PER_LONG) & BIT(5); See above, offset is 0 when BITS_PER_LONG == 32 and 32 when it's equal to 64. > - map[index] |= v << offset; > + map[index] |= (unsigned long)v << offset; -- With Best Regards, Andy Shevchenko