Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp564173pxk; Sun, 30 Aug 2020 14:24:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS+yRC6UBe8T0TG/ax+oh9250Mdf+sY37cYojOAAytYXwHmfRAUbADJ385Xx6VwQ95X/Ra X-Received: by 2002:a17:906:b20c:: with SMTP id p12mr9069063ejz.300.1598822673892; Sun, 30 Aug 2020 14:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598822673; cv=none; d=google.com; s=arc-20160816; b=OOB4HsYdSnnOnE7bTMhYvms9qQZAOzQEGlBwm7yFBCvl45AgoklBKl/Y7M0QYUWuoe y/PBUo/RkBcp+XIqahaZiBi8IrydXAHu9tvtxeIrp5JGgUrl/VmslwNFgdBFh3k7Wjb+ oRfgZF3CPGurNkif9rGqmOD6kdWtTD37k792/f+Dxs/vYXokdvKbG30D9ZUcNF9G1/yp 7IYTprUqWTHZfbXbRvmSt//OO3NamRelKy75d+cLlPC1avpomrtDOpvqQ46WUYE+ebTI 243JdufqicPd6rO2KWwGqHX9U9b1WlT2ByZFw6Qf2eNcgHEGvV2faTXpd2oZ6yntOYXy fAHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=dfWTkuV/UhV1mRAic7sA4cEHWIpdMTK5VZSNYbrwpfY=; b=dFamltoklFnztOGEOC/IKJIJI8ZawjP4jNVBpMQnQA7gdCgldRY6LY/qmarnghfAix qc2kB85IYBRPd0qiaeB6L+kKubtgryWn3FePgysoXktNVG672xrw4cjdWnWaSz17zRfv YpHXXwxwGBlP/gSMmZdHixB6e+8d4iVWbAY37Gsx9KlYIbECKyR/BC9O1B+PdLUZcCDS Gk+xayAmDwBGDJ88QRx53CXOBEk0vjag4mObjxNP3O0NR2quSKc95BNWs12aVR3PFS0j EVfeEByB2nYBDAF2D/eRKaxcz1KuVuSw+0lYIb+4uxtd8WWJ8FHrgym/2+Cm+B4/QGHx NL7Q== 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 m7si3216510eds.286.2020.08.30.14.24.10; Sun, 30 Aug 2020 14: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 S1726150AbgH3VWv (ORCPT + 99 others); Sun, 30 Aug 2020 17:22:51 -0400 Received: from netrider.rowland.org ([192.131.102.5]:42775 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726179AbgH3VWv (ORCPT ); Sun, 30 Aug 2020 17:22:51 -0400 Received: (qmail 528317 invoked by uid 1000); 30 Aug 2020 17:22:49 -0400 Date: Sun, 30 Aug 2020 17:22:49 -0400 From: Alan Stern To: trix@redhat.com Cc: balbi@kernel.org, gregkh@linuxfoundation.org, natechancellor@gmail.com, ndesaulniers@google.com, christophe.jaillet@wanadoo.fr, peter.chen@nxp.com, b-liu@ti.com, chunfeng.yun@mediatek.com, novikov@ispras.ru, yanaijie@huawei.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: gadget: net2272: assert for a valid dma request Message-ID: <20200830212249.GA528080@rowland.harvard.edu> References: <20200830183646.24930-1-trix@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200830183646.24930-1-trix@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 30, 2020 at 11:36:46AM -0700, trix@redhat.com wrote: > From: Tom Rix > > clang static analysis flags this representive problem > > net2272.c:1541:8: warning: Dereference of null pointer > if ((req->req.length % ep->ep.maxpacket != 0) || > ^~~~~~~~~~~~~~~ > This is mostly not a problem. > > In net2272_handle_dma(), even though every path through > the routine dereferences req, it is set to NULL when the > ep->queue is empty. If the eq->queue was ever empty this > would have oops. > > So the else statement should not be needed. If it is, > flag it as a BUG. > > Signed-off-by: Tom Rix This patch really seems to be overkill. In particular, Linus Torvalds feels very strongly that people should not add BUG or BUG_ON calls except in extreme situations -- which this isn't. > --- > drivers/usb/gadget/udc/net2272.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/gadget/udc/net2272.c b/drivers/usb/gadget/udc/net2272.c > index 44d1ea2307bb..8301723a8b1a 100644 > --- a/drivers/usb/gadget/udc/net2272.c > +++ b/drivers/usb/gadget/udc/net2272.c > @@ -1506,17 +1506,16 @@ static int net2272_stop(struct usb_gadget *_gadget) > static void > net2272_handle_dma(struct net2272_ep *ep) > { > - struct net2272_request *req; > + struct net2272_request *req = NULL; > unsigned len; > int status; > > if (!list_empty(&ep->queue)) > req = list_entry(ep->queue.next, > struct net2272_request, queue); > - else > - req = NULL; > > dev_vdbg(ep->dev->dev, "handle_dma %s req %p\n", ep->ep.name, req); > + BUG_ON(!req); There's no point in adding this. If the function goes on to dereference a NULL pointer, you'll get the same effect in any case -- an oops. If you want to make the point that req had better not be NULL, just get rid of the "if" test entirely. You could even change the list_entry to list_first_entry. Alan Stern