From patchwork Mon Nov 10 20:45:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 40536 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 24E8E203C0 for ; Mon, 10 Nov 2014 20:44:54 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id b13sf4482925wgh.2 for ; Mon, 10 Nov 2014 12:44:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :mime-version:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe:content-type; bh=GNAupIBt5FXjuvSO9lMuNI5C9oE9ytJDmLKg1vyTGPI=; b=js+KCSsL3uz2wUzuTU+0D57aOM9fomn55Ixs6DY7bA7p5vtBjUQ/gv59wKDiPbeYyx Toh7qJi+0CvbAympyOxeex+6VTc300qZnwgfp9lXD4BczchJtaUJkzXlEzL9wR8rizRz SnXqOQBLx5GpzcJz0uSmfRKNpHVPccahxy0nnGAgmfFqs40g4RcYyTfkhhmTKEt03V6r eT/I9ITnVxiUh+GH5h7fzi9W2puzsoq21bR+LaH7ZimbsSCq+Y5MZVJWXggoDaPMbTsd Ui3tGu1cbYQmyFbxf3XY7zr0jpjKID8TIXqZlHhnQQOh+A3AlvRaRPk+HeNx05Mv1f3h nICw== X-Gm-Message-State: ALoCoQmskanvRFfgZRlRvyE4GECxGcUE+I1nCvp2Ji/C6xVoTEHbSRbrfwTX72r44NqtliQy5jou X-Received: by 10.194.61.243 with SMTP id t19mr931779wjr.5.1415652291121; Mon, 10 Nov 2014 12:44:51 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.131 with SMTP id e3ls504814lam.31.gmail; Mon, 10 Nov 2014 12:44:50 -0800 (PST) X-Received: by 10.152.30.33 with SMTP id p1mr5364572lah.78.1415652290881; Mon, 10 Nov 2014 12:44:50 -0800 (PST) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id yf1si28838422lab.63.2014.11.10.12.44.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Nov 2014 12:44:49 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by mail-lb0-f180.google.com with SMTP id u10so6615495lbd.11 for ; Mon, 10 Nov 2014 12:44:49 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr31604607laz.27.1415652289216; Mon, 10 Nov 2014 12:44:49 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp161639lbc; Mon, 10 Nov 2014 12:44:48 -0800 (PST) X-Received: by 10.68.246.229 with SMTP id xz5mr7460012pbc.131.1415652287697; Mon, 10 Nov 2014 12:44:47 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mq7si17777169pdb.105.2014.11.10.12.44.46 for ; Mon, 10 Nov 2014 12:44:47 -0800 (PST) Received-SPF: none (google.com: linux-usb-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751976AbaKJUop (ORCPT + 3 others); Mon, 10 Nov 2014 15:44:45 -0500 Received: from bear.ext.ti.com ([192.94.94.41]:51480 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751594AbaKJUop (ORCPT ); Mon, 10 Nov 2014 15:44:45 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id sAAKigR2004747; Mon, 10 Nov 2014 14:44:42 -0600 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id sAAKigkp029625; Mon, 10 Nov 2014 14:44:42 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Mon, 10 Nov 2014 14:44:42 -0600 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id sAAKifKf029742; Mon, 10 Nov 2014 14:44:41 -0600 From: Felipe Balbi To: Linux USB Mailing List CC: Dave Jones , Felipe Balbi Subject: [PATCH] usb: dwc3: ep0: fix for dead code Date: Mon, 10 Nov 2014 14:45:09 -0600 Message-ID: <1415652309-30959-1-git-send-email-balbi@ti.com> X-Mailer: git-send-email 2.1.0.GIT MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: balbi@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , commit 6856d30 (usb: dwc3: ep0: return early on NULL requests) tried to fix a minor corner case where we could dereference a NULL pointer but it also ended up introducing some dead code. Unfortunately, that dead code, if reached, could end up starving the endpoint request list because a request would never be given back when it should. Fix this by moving the check for empty request list before its first use. Reported-by: Dave Jones Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/ep0.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 711b230..df38e7e 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -791,6 +791,10 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc, trb = dwc->ep0_trb; + r = next_request(&ep0->request_list); + if (!r) + return; + status = DWC3_TRB_SIZE_TRBSTS(trb->size); if (status == DWC3_TRBSTS_SETUP_PENDING) { dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); @@ -801,10 +805,6 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc, return; } - r = next_request(&ep0->request_list); - if (!r) - return; - ur = &r->request; length = trb->size & DWC3_TRB_SIZE_MASK;