Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp474595yba; Wed, 3 Apr 2019 12:27:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBmdrIOwDFFkwHTSEuDKNl/gYPIRWyRHrXfY5AWPYxH9SceN65B2H0KngNs/pVyoT9f3Yg X-Received: by 2002:a62:b602:: with SMTP id j2mr1297909pff.68.1554319620188; Wed, 03 Apr 2019 12:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554319620; cv=none; d=google.com; s=arc-20160816; b=0W8KxADQw2OU8tBbEnqolA3M3h35NVdyL55jZIPyBIiUxv+FL7TivddsSFrWWWKRWI DZDx3I+fhwwgJ58QekvlYMR6td0N+9grvQcOSdEeBWBU9YtTRfhjDP9c5QhvmvhOiM8d ZzFCyK5vrGdhNTJfQfTMWVXY5O0CXPqY4RDuaQnS3rXpgC+LUOXJyGPz4he0AAy8PA/N prHGk+F+E5TsKR384hOOR1dDH0IB46OIqkDwhux7bRAkHx8dWlJfl+YA8Cp33CnJiTqE stojvRpuMVn8B8WMyw3fDYwhjpBUh5HYAN6lSJExwCjigevz9Rd7QtUn0qwv5RiFDkeo vVQw== 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:message-id:date :subject:cc:to:from; bh=+BXvQhYxHR/zrrOdO4tZ8II7Ve1Cq2L16/Z4icRGFV4=; b=TRYY1atjhZZQWnXUPzfDmjU9W2BcEHx271wPT08Ev5SgOI1BLaZM9lIrqKpHhVgFt6 lb5TjjQGhQD+lP1GVbdplCTlFneh5tgkA7oD5aaB8VZVOg6L+4DQVEpuaeR0mqMxVGoA zCubALi2roW+Mql3Lumjv0koP2ALVwptk4k7TkXG5NJUbJLvchi69lfen9JJFBNfZE+i a7npBO4KmiGPPkadOVHACDqRx59hKjYdfZqfrDs4fF1V41tGYV8pbJsAJyxcqetKevD7 9/6t7wEMpCmqYtWwTqhNEaGOzXRn1V3FGAnD03OqOggHxMELEzImY9nfP97vUtyPx41h P2vg== 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 a13si15281211pfn.70.2019.04.03.12.26.45; Wed, 03 Apr 2019 12:27:00 -0700 (PDT) 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 S1727025AbfDCT0D (ORCPT + 99 others); Wed, 3 Apr 2019 15:26:03 -0400 Received: from lnfm1.sai.msu.ru ([93.180.26.255]:49521 "EHLO lnfm1.sai.msu.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726930AbfDCT0A (ORCPT ); Wed, 3 Apr 2019 15:26:00 -0400 X-Greylist: delayed 1904 seconds by postgrey-1.27 at vger.kernel.org; Wed, 03 Apr 2019 15:25:44 EDT 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 x33IrXuD024073; Wed, 3 Apr 2019 21:53:38 +0300 Received: from oak.local (unknown [92.243.181.209]) (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 B4554F5B7; Wed, 3 Apr 2019 21:53:34 +0300 (MSK) From: "Matwey V. Kornilov" To: b-liu@ti.com, gregkh@linuxfoundation.org Cc: matwey.kornilov@gmail.com, "Matwey V. Kornilov" , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 3/6] usb: musb: Introduce musb_qh_free() helper function Date: Wed, 3 Apr 2019 21:53:07 +0300 Message-Id: <20190403185310.8437-4-matwey@sai.msu.ru> X-Mailer: git-send-email 2.16.4 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