Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp762817rwe; Wed, 24 Aug 2022 08:35:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR41NSSqa1bTEmPiIbRgZBuSGRQvGT/MVlzOcSJ8LQ6mVxf/ko881wkylFge5MCMlywbzD4z X-Received: by 2002:a05:6402:2884:b0:447:9f63:f969 with SMTP id eg4-20020a056402288400b004479f63f969mr383006edb.407.1661355350013; Wed, 24 Aug 2022 08:35:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661355350; cv=none; d=google.com; s=arc-20160816; b=pQrlTJWmcubxQCrk0uSz7oUFhgNYxG/7Dt59j5paI/lVabvy8kin4O8mRfybhLdNTw JrS1/NMSNloP2FCQ3/NEJbZ4uPT7Rp1K00rHFOCfpf9Tztf9TThpAh/wSyhgAdC56kAV CiMYY2m2mGhj7xiog+QAx9LIvdo4u72atSxmRwPxZwsP17Wu7x6/rSoyNLJLsQ3x/Qfz lTLQOQwoVyZmYzLBpqMSiRvI1c0pa3VBf6GuiCtbHokWlkqglAaDcBtqtGRvFCtudEe9 Wf+tiaqdCHVl3DaCz6LdTkRGqbnbk0AfCrBF/wT9RzkqhlrmkAq7+QR1Hzb0dLsdWmUv js2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=5JHtQFea2GqDfIsrsALd4Z9NivnErqZlBklg7IOaBlQ=; b=FHhus6vdKkjeMuaiRRLFCneVomkpFz1FbT5gubq6wI9CqssjWKPo3p8v3raNAxjO+8 u5kaYVsdz9RIVFeuo4ReDVymu2LarW7O44tUovtv+z6tSZp+1inND/Lbwha7RhRjbXfl NzivrmtX//7iG3buu3BBiEQ9gFqwYvaZYKBBiYkIVLcOaWQrNDMjRcLNTZG9V3N2pDfG aYr2S/9hQDxy9NlwsBSPw4XwLHrWAZiYEGX6iMQsXLTsZrwV1qm7WuLIkQWRLfOFOG5c 6ATnMaW0N3mJZUzAaWDfKKN2Xblmn0YHMooFBAlffP2scZO8x+c/ueGJwhSCJIDBp68i xMkg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di16-20020a170906731000b00732f74ed931si2482407ejc.793.2022.08.24.08.35.22; Wed, 24 Aug 2022 08:35:50 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238336AbiHXOiG (ORCPT + 99 others); Wed, 24 Aug 2022 10:38:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237823AbiHXOiD (ORCPT ); Wed, 24 Aug 2022 10:38:03 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 806F171722 for ; Wed, 24 Aug 2022 07:38:01 -0700 (PDT) Received: (qmail 380905 invoked by uid 1000); 24 Aug 2022 10:38:00 -0400 Date: Wed, 24 Aug 2022 10:38:00 -0400 From: Alan Stern To: Khalid Masum Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, Linux Kernel Mailing List Subject: Re: [PATCH 1/2] usb: ehci: Prevent possible modulo by zero Message-ID: References: <20220823182758.13401-1-khalid.masum.92@gmail.com> <20220823182758.13401-2-khalid.masum.92@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Wed, Aug 24, 2022 at 05:15:47PM +0600, Khalid Masum wrote: > On Wed, Aug 24, 2022 at 2:21 AM Alan Stern wrote: > > > > if (!ep) { > > usb_free_urb(urb); > > return NULL; > > } > > > > Neither of these patches is needed. > > > > Alan Stern > > Thanks, I got you. In fact, Coverity wasn't completely wrong; there is a possible bug here. However the suggested fix is not the right approach. The usb_maxpacket() routine does a two-step computation. First, it looks up the endpoint number in the pipe to get a usb_host_endpoint pointer, and then it uses the pointer to get the maxpacket value. Coverity complained that the lookup in the first step can fail, and that is in fact true: If there is an interface or configuration change before usb_maxpacket() is called, the endpoint number table can change and the lookup may fail. But it turns out the first step isn't needed here at all, since the endpoint pointer is already stored in the URB (by the code in usb_submit_urb() that I pointed out earlier). So an appropriate way to fix the problem is to carry out just the second step: - maxpacket = usb_maxpacket(urb->dev, urb->pipe); + maxpacket = usb_endpoint_maxp(&urb->ep->desc); This holds for both of your patches. Alan Stern