Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp332453pxu; Thu, 3 Dec 2020 01:06:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzr99w1cKP6gPfZNtvbNdseMIqQNcOCG1JgTTyafANtqSgN0msqHn6BrF494QwLrHeg04M4 X-Received: by 2002:a17:906:38d6:: with SMTP id r22mr1554354ejd.149.1606986383597; Thu, 03 Dec 2020 01:06:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606986383; cv=none; d=google.com; s=arc-20160816; b=zkMcEms1wD9rL5Z/Ss19tbL7G1MresvMnZa7+mFabx63bKLen3AfjeFtCVZPXJ2icB /rlFvcTILip7MO3uAp7q/PGoTwpTo+IMJccng2Gp3lQVfC8Ny52TETInOX2uf4NPTHaA 4OqRXu9cO+Mf6A2clBC3glpvba/eyfbmBMyD6QZtMCocxKyedVCOu/C08mqRAui7SFL0 XfvA/DQ0EiIG4ExZHAasqT+z3OQPF5uQYZcZYAIZOhQ5N5PRUg7VxOos9J7qkoeMU+Md 0cF0fggcJvpW7PBWPGVS3KyrwgOH0l9HAaFWEwqfvA34mhdGegr0MJuNM4/pdk3sivZi 8HNg== 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=b8vPrErhs2SeNesKdqnrR0Y61VWgyx6uy7JYVlF36VM=; b=DImIgK29QWf+8U9Gt3G1cERIJvkfbQ1dRAgxAqVH2x9/liD9cTlrap4WxzTRvDfb8K rBezPOjKcTpE6YFEst2Awg4cx3/wqzXenbbFrsQ6JYREVKZuQx+nTjix1XUxym/JZzLW ZqHDW2YJJ1yeVXI0w9sb+7gZJekktmoH70P1QiopNEq9ekxLQv4iJGPwhf+s3wepEijd 5MWMFWDkBdbGDtBxNvlrDVtKSJaC+4bNAPw4my6vrCZ/hu78NzFtMpspcVCRQQ5en6Zr Df1gO9DlaHbL7arkAHzEzOHiaTPTfyN/XUsUyPnJCP9+yR5xIv2S/M9fk7dGZT2m4pPb pgUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=SXZC2srF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id co17si544519edb.518.2020.12.03.01.05.58; Thu, 03 Dec 2020 01:06:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=SXZC2srF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387518AbgLCJEe (ORCPT + 99 others); Thu, 3 Dec 2020 04:04:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730087AbgLCJEd (ORCPT ); Thu, 3 Dec 2020 04:04:33 -0500 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CF55C061A4E for ; Thu, 3 Dec 2020 01:03:53 -0800 (PST) Received: by mail-il1-x143.google.com with SMTP id x15so1236527ilq.1 for ; Thu, 03 Dec 2020 01:03:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=b8vPrErhs2SeNesKdqnrR0Y61VWgyx6uy7JYVlF36VM=; b=SXZC2srFWwAKsc0BkmzUe3oDyV1t88UJZrWOVbdvjiwhC4D0lH4PjkcaYSsSlsJcyJ GGwITeELhdiFbZrSHBTiMnuXopk8K0U/qW1KASBGSE4Oon13bAUqSDCauWT12xDV1sjb MckjM8hv7w4trjd2KTUlJWEfphZe6ifCygna/zvB97c69b36glBgLZkFXdx7Hsy2flDv b6ldEv2HlKt3aFnOANmTIR9UK1EOx7DvIfEbiCnqDbL9Uxhuv3tPxcXc+jIJ0Su/46Ov LFOiiQNeDnW/5zVx/acliomw6hF9gX4LXuSi2bKjNDhwNRvSasMGFE3pVtQW1JbJseAH Lysg== 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=b8vPrErhs2SeNesKdqnrR0Y61VWgyx6uy7JYVlF36VM=; b=t81NZ/LyGhz2RQ36ymRC75XbIHToJ1YWl6cwFjcJ1qK6GsN7o4wKxn73cztBV5aDM1 MpQ61Sd2UXA3E4ulXW0F5sMlxj9/IULyw7Hn0viD+PCpTrux9Ln6hSvm2NHaIeXQLU5K KH405K8ttTRv6Al6BQaBhi10RyjzrNYhCRzLruQyKjENzjZp08C0p6p372NzD9McckRn /O2VXdKNjVsab2th3d4hOzfMjOXzjDFSRtler1pfcyjfymJEUQFy00VWZ3512Ap/ip9c ogaPiqBolEC7MWnjTWMfeSKBYqJhn476rpK5XxeuDhthujy5S3M8LulJSpUmPG+o3/6g rvDw== X-Gm-Message-State: AOAM532dmRQ5y1L0IMTKhD0ZudE3lr+ewBnurVgjA1j5LJ+bGDHfftNl tup/911JB6rgxwhd+xbTRgXxt+tkkWLX+XyKrlH83g== X-Received: by 2002:a92:d1c9:: with SMTP id u9mr2157204ilg.189.1606986232418; Thu, 03 Dec 2020 01:03:52 -0800 (PST) MIME-Version: 1.0 References: <20201203073910.20113-1-biwen.li@oss.nxp.com> In-Reply-To: From: Bartosz Golaszewski Date: Thu, 3 Dec 2020 10:03:41 +0100 Message-ID: Subject: Re: [PATCH] gpio: mpc8xxx: resolve coverity warnings To: "Biwen Li (OSS)" Cc: Bartosz Golaszewski , Leo Li , Aisheng Dong , LKML , Jiafei Pan , linux-gpio Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 3, 2020 at 9:51 AM Biwen Li (OSS) wrote: > > > > > On Thu, Dec 3, 2020 at 9:07 AM Biwen Li (OSS) wrote: > > > > > > > On Thu, Dec 3, 2020 at 8:31 AM Biwen Li wrote: > > > > > > > > > > From: Biwen Li > > > > > > > > > > Resolve coverity warnings as follows, > > > > > cond_at_most: Checking gpio >= 28U implies that gpio may be up > > > > > to 27 on the false branch. > > > > > overrun-call: Overrunning callees array of size 3 by passing > > > > > argument gpio (which evaluates to 27) > > > > > in call to *mpc8xxx_gc->direction_output > > > > > > > > > > cond_at_least: Checking gpio <= 3U implies that gpio is at least 4 on > > > > > the false branch. > > > > > overrun-call: Overrunning callee's array of size 3 by passing argument > > > > > gpio (which evaluates to 4) in call to > > > > > *mpc8xxx_gc->direction_output > > > > > > > > > > Signed-off-by: Biwen Li > > > > > --- > > > > > drivers/gpio/gpio-mpc8xxx.c | 5 +++-- > > > > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > > > > > > > diff --git a/drivers/gpio/gpio-mpc8xxx.c > > > > > b/drivers/gpio/gpio-mpc8xxx.c index a6c2bbdcaa10..12c9a91d87b7 > > > > > 100644 > > > > > --- a/drivers/gpio/gpio-mpc8xxx.c > > > > > +++ b/drivers/gpio/gpio-mpc8xxx.c > > > > > @@ -3,6 +3,7 @@ > > > > > * > > > > > * Copyright (C) 2008 Peter Korsgaard > > > > > * Copyright (C) 2016 Freescale Semiconductor Inc. > > > > > + * Copyright 2020 NXP > > > > > > > > A copyright notice on a two-line change is a bit too much, don't you think? > > > Okay, got it. Will remove it in v2. > > > > > > > > > * > > > > > * This file is licensed under the terms of the GNU General Public License > > > > > * version 2. This program is licensed "as is" without any > > > > > warranty of any @@ -80,7 +81,7 @@ static int > > > > > mpc5121_gpio_dir_out(struct gpio_chip *gc, { > > > > > struct mpc8xxx_gpio_chip *mpc8xxx_gc = > > gpiochip_get_data(gc); > > > > > /* GPIO 28..31 are input only on MPC5121 */ > > > > > - if (gpio >= 28) > > > > > + if (gpio >= 28U) > > > > > return -EINVAL; > > > > > > > > I don't really understand the commit message but looking at the code > > > > is even more confusing. What are you fixing here actually? > > > Try to fix code warning that generated by coverity scan tool(static > > > code analysis tool) > > > > Please explain what benefit there is to using 28U over 28. No tool is perfect, > > that's why you should try to understand what it is it's trying to fix. I don't see any > > reason this code could fail. > This code couldn't fail. > The variable gpio is unsigned int type, prefer to append "U" for unsigned typed values, this makes is clearer also when comparing values and variables. > > This only makes sense if we're using large values that could potentially overflow a signed int. This is a small constant value so there's no reason for this churn. NAK Bartosz > > Bartosz > > > > > > > > > > Bartosz > > > > > > > > > > > > > > return mpc8xxx_gc->direction_output(gc, gpio, val); @@ > > > > > -91,7 > > > > > +92,7 @@ static int mpc5125_gpio_dir_out(struct gpio_chip *gc, { > > > > > struct mpc8xxx_gpio_chip *mpc8xxx_gc = > > gpiochip_get_data(gc); > > > > > /* GPIO 0..3 are input only on MPC5125 */ > > > > > - if (gpio <= 3) > > > > > + if (gpio <= 3U) > > > > > return -EINVAL; > > > > > > > > > > return mpc8xxx_gc->direction_output(gc, gpio, val); > > > > > -- > > > > > 2.17.1 > > > > >