Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp16619878ybl; Wed, 1 Jan 2020 09:24:51 -0800 (PST) X-Google-Smtp-Source: APXvYqxqJxBHZgMv0l+18dYYVPU9T6JVk33PMfB/4Hd911CQho1N+J1cLzfRo7P/PeeHme0cdkBc X-Received: by 2002:a9d:4706:: with SMTP id a6mr81325927otf.331.1577899491784; Wed, 01 Jan 2020 09:24:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577899491; cv=none; d=google.com; s=arc-20160816; b=hUoQyLg31xPwMvPZccTZGAAEQEQRXp+meVhuv9cWf/EUSOE/c7I0XCubArKDMossDX s3FNs3uQhChF9OWrJk6F6+GiwebP6s6RcDjBhsNP+tITLiQTF4Be8dmV9WIoJTIm2vL/ ZYdC+sjkwsVvRr9f8pt0FxiuCU0C5EjdJWCNdhvRCmchTwXeyJu7KlhQLn9rA1pzn+Ml ZyM+5Go0Mm6QUTIMHsR4NwYM8ltlpkugqmuCkaXdaDlP6UEpkP/vSFK7k5b5fo4n8H2R DXQcua2BEtTPJO4WayXvUg6CK63y9717YlV4Ndpqgm7QktWELPujIafmDHQi4mz7RhOa cloQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from; bh=+BXvQhYxHR/zrrOdO4tZ8II7Ve1Cq2L16/Z4icRGFV4=; b=oXZ08aJP9D/Z25uOR5/kamoqW9FGtVOhPtFpRZs7CWZEEavB6eOxpdZ3tRURDb6V5l e6vo1rwQNC13yXvGCTZNRr0yx7dkCzJF8xQZza/49pBC5rp4IT+9QIq9G+5/EeOjzHTt MmqDI5MzNBXAuvzPX9ylFB9+GnLBJHrTD/Bw+NM+cFe6cWaiad7lzoIzqCxrrjRGfVE2 FrtLQgbdYL2Y83Bn91yxeE7LwwhIDvDLHllfotjW2ZCK/mm34Kx4MDZaGy9aZMOZioxz dGbB8DmgjeUHzk6Oaru7HOuu/6rftLeKHD326leKNbnPJ/70LTmliHdGqAy1VHlXEB/n Jmow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w131si23448030oie.47.2020.01.01.09.24.18; Wed, 01 Jan 2020 09:24:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727352AbgAARWz (ORCPT + 99 others); Wed, 1 Jan 2020 12:22:55 -0500 Received: from lnfm1.sai.msu.ru ([93.180.26.255]:35309 "EHLO lnfm1.sai.msu.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727318AbgAARWx (ORCPT ); Wed, 1 Jan 2020 12:22:53 -0500 X-Greylist: delayed 3350 seconds by postgrey-1.27 at vger.kernel.org; Wed, 01 Jan 2020 12:22:39 EST Received: from dragon.sai.msu.ru (dragon.sai.msu.ru [93.180.26.172]) by lnfm1.sai.msu.ru (8.14.1/8.12.8) with ESMTP id 001GQJMZ001785; Wed, 1 Jan 2020 19:26:24 +0300 Received: from oak.local (unknown [188.123.231.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by dragon.sai.msu.ru (Postfix) with ESMTPSA id EEB09106D64; Wed, 1 Jan 2020 19:26:20 +0300 (MSK) From: "Matwey V. Kornilov" To: b-liu@ti.com, gregkh@linuxfoundation.org, stern@rowland.harvard.edu Cc: matwey.kornilov@gmail.com, "Matwey V. Kornilov" , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND v2 3/6] usb: musb: Introduce musb_qh_free() helper function Date: Wed, 1 Jan 2020 19:26:07 +0300 Message-Id: <20200101162610.15819-4-matwey@sai.msu.ru> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200101162610.15819-1-matwey@sai.msu.ru> References: <20200101162610.15819-1-matwey@sai.msu.ru> In-Reply-To: <20190403185310.8437-1-matwey@sai.msu.ru> References: <20190403185310.8437-1-matwey@sai.msu.ru> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reduce the following similar snippets by using musb_qh_free(). qh->hep->hcpriv = NULL; list_del(&qh->ring); kfree(qh); Signed-off-by: Matwey V. Kornilov --- drivers/usb/musb/musb_host.c | 66 +++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c index 37aa9f6155d9..5d23c950a21b 100644 --- a/drivers/usb/musb/musb_host.c +++ b/drivers/usb/musb/musb_host.c @@ -85,6 +85,21 @@ static bool musb_qh_empty(struct musb_qh *qh) return list_empty(&qh->hep->urb_list); } +static void musb_qh_unlink_hep(struct musb_qh *qh) +{ + if (!qh->hep) + return; + + qh->hep->hcpriv = NULL; +} + +static void musb_qh_free(struct musb_qh *qh) +{ + musb_qh_unlink_hep(qh); + list_del(&qh->ring); + kfree(qh); +} + /* * Clear TX fifo. Needed to avoid BABBLE errors. */ @@ -348,7 +363,7 @@ static void musb_advance_schedule(struct musb *musb, struct urb *urb, * invalidate qh as soon as list_empty(&hep->urb_list) */ if (musb_qh_empty(qh)) { - struct list_head *head; + struct list_head *head = NULL; struct dma_controller *dma = musb->dma_controller; if (is_in) { @@ -367,34 +382,22 @@ static void musb_advance_schedule(struct musb *musb, struct urb *urb, /* Clobber old pointers to this qh */ musb_ep_set_qh(ep, is_in, NULL); - qh->hep->hcpriv = NULL; - switch (qh->type) { + /* USB_ENDPOINT_XFER_CONTROL and USB_ENDPOINT_XFER_BULK: fifo + * policy for these lists, except that NAKing should rotate + * a qh to the end (for fairness). + * USB_ENDPOINT_XFER_ISOC and USB_ENDPOINT_XFER_INT: this is + * where periodic bandwidth should be de-allocated if it's + * tracked and allocated; and where we'd update the schedule + * tree... + */ + if (qh->mux == 1 + && (qh->type == USB_ENDPOINT_XFER_CONTROL || qh->type == USB_ENDPOINT_XFER_BULK)) + head = qh->ring.prev; - case USB_ENDPOINT_XFER_CONTROL: - case USB_ENDPOINT_XFER_BULK: - /* fifo policy for these lists, except that NAKing - * should rotate a qh to the end (for fairness). - */ - if (qh->mux == 1) { - head = qh->ring.prev; - list_del(&qh->ring); - kfree(qh); - qh = first_qh(head); - break; - } - /* fall through */ + musb_qh_free(qh); - case USB_ENDPOINT_XFER_ISOC: - case USB_ENDPOINT_XFER_INT: - /* this is where periodic bandwidth should be - * de-allocated if it's tracked and allocated; - * and where we'd update the schedule tree... - */ - kfree(qh); - qh = NULL; - break; - } + qh = head ? first_qh(head) : NULL; } if (qh != NULL && qh->is_ready) { @@ -2435,11 +2438,8 @@ static int musb_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) /* If nothing else (usually musb_giveback) is using it * and its URB list has emptied, recycle this qh. */ - if (ready && musb_qh_empty(qh)) { - qh->hep->hcpriv = NULL; - list_del(&qh->ring); - kfree(qh); - } + if (ready && musb_qh_empty(qh)) + musb_qh_free(qh); } else ret = musb_cleanup_urb(urb, qh); done: @@ -2493,9 +2493,7 @@ musb_h_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep) while (!musb_qh_empty(qh)) musb_giveback(musb, next_urb(qh), -ESHUTDOWN); - hep->hcpriv = NULL; - list_del(&qh->ring); - kfree(qh); + musb_qh_free(qh); } exit: spin_unlock_irqrestore(&musb->lock, flags); -- 2.16.4