Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1371093ybk; Thu, 14 May 2020 07:24:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPrYTT30D3QZox27r/mjhl5JXVZMFK0NLnqcJ+QWY8BRKnsG5rrZeIfTqH8xVzxKwt9BUH X-Received: by 2002:a17:906:f90d:: with SMTP id lc13mr3817814ejb.367.1589466273831; Thu, 14 May 2020 07:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589466273; cv=none; d=google.com; s=arc-20160816; b=B4GOHN8uS5zW3m2QR/8nUNGbNwIoM0kLWjzhRI5rEWEQI5eWw3TtpPARQvJMqrpBBg KHocNMCSUQA/6gb4mTjbPbCIyGCbl3pwURfn+UY3uZmpi8YfmPyQ75nKwItqZdvD2ljd 0Bau7gMPvov2SUQJI1SVBN+gD0+4XXj+qF9QBYwui0+T8NAdgKdB+haQVC6K9B26YIHH ZzszjFcpumscqR3TZwWssloyZGzEcWBK/8AehuVxrZ7T0NetqgXp6MxDvF1XJilfBPjg OpJCMx9Pxc/0Ofai9OM6uqZkiwTR2EODMIebS7ZhniysFpEghLKe+6LzfFWQv5rN7r4w vcSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ludZDgOU4F3zR3MLwlT9R4c6B5eLJ+sZbjWXJo+3gnI=; b=ECwOtiM93CdJppFkuLeikUwqVU7ZXcEmdJJWKEAKgNtYU8Zsra3f+dzFUM95P07/Z+ DGn67E8fXR28SJPjGMcoPbsGGyxm7zRYaq3LdBLeR+4BaP+pseSrdwz8wsq+d9Bi540U 1ZwWKyaa0auGXk+NFTR8LCD9h7u3lbbe9MSBp+3XK8Q4fikb9ElrJxNAEv4qAQ3wHhUu H+G2F+8MrLKWW5+ZN2wfIgOSvlDWPmYnbS4aIR+se1bsoPB6MUjkc8g0o3aocLeCdcV3 OvcHCwK1qnPQTS9H5ZSuQw45vEng4xi7lVYmuwWJn1b7XRPyGoWIWV7gufoOnhiHsqvr GwjA== ARC-Authentication-Results: i=1; mx.google.com; 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 n5si1828248ejd.88.2020.05.14.07.24.10; Thu, 14 May 2020 07:24:33 -0700 (PDT) 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; 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 S1727119AbgENOWj (ORCPT + 99 others); Thu, 14 May 2020 10:22:39 -0400 Received: from netrider.rowland.org ([192.131.102.5]:36393 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1727033AbgENOWi (ORCPT ); Thu, 14 May 2020 10:22:38 -0400 Received: (qmail 14203 invoked by uid 500); 14 May 2020 10:22:37 -0400 Date: Thu, 14 May 2020 10:22:37 -0400 From: Alan Stern To: Macpaul Lin Cc: Felipe Balbi , Greg Kroah-Hartman , Matthias Brugger , =?utf-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Sergey Organov , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Mediatek WSD Upstream , Macpaul Lin , Stan Lu Subject: Re: [PATCH] usb: gadget: u_serial: fix coverity warning: negative index at array Message-ID: <20200514142237.GB12181@rowland.harvard.edu> References: <1589443500-3990-1-git-send-email-macpaul.lin@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1589443500-3990-1-git-send-email-macpaul.lin@mediatek.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 14, 2020 at 04:05:00PM +0800, Macpaul Lin wrote: > This issue has been reported by coverity scanner. > Replace "int portnum" by "unsigned int", this void negative index at > array. Can you please explain this more fully? Why does coverity think the code might use a negative array index? Is there some possibility that the portnum value might actually be negative? It's noticeable that your patch doesn't actually change any values, only the type. This means that if the code was buggy before, it's still buggy. Alternatively, if the code wasn't buggy before then coverity got a false positive, so no change should be needed. Alan Stern > Signed-off-by: Stan Lu > Signed-off-by: Macpaul Lin > --- > drivers/usb/gadget/function/u_serial.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c > index 8167d37..53951f2 100644 > --- a/drivers/usb/gadget/function/u_serial.c > +++ b/drivers/usb/gadget/function/u_serial.c > @@ -587,7 +587,7 @@ static int gs_start_io(struct gs_port *port) > */ > static int gs_open(struct tty_struct *tty, struct file *file) > { > - int port_num = tty->index; > + unsigned int port_num = tty->index; > struct gs_port *port; > int status = 0; > > @@ -1211,7 +1211,7 @@ int gserial_alloc_line_no_console(unsigned char *line_num) > struct gs_port *port; > struct device *tty_dev; > int ret; > - int port_num; > + unsigned int port_num; > > coding.dwDTERate = cpu_to_le32(9600); > coding.bCharFormat = 8; > -- > 1.7.9.5