All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Ard Biesheuvel <ardb@kernel.org>
Cc: linux-usb@vger.kernel.org, kernel@pengutronix.de
Subject: [PATCH 2/2] usb: host: u132-hcd: Drop if with an always true condition
Date: Tue, 21 Mar 2023 11:19:11 +0100	[thread overview]
Message-ID: <20230321101911.342538-3-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20230321101911.342538-1-u.kleine-koenig@pengutronix.de>

A platform device's .remove() callback is only ever called after
.probe() successfully completed. After such a successful call,
platform_get_drvdata() doesn't return NULL. Simplify accordingly.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/usb/host/u132-hcd.c | 66 +++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 32 deletions(-)

diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index f5433993c76e..45244c791bcb 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -2977,39 +2977,36 @@ static const struct hc_driver u132_hc_driver = {
 static int u132_remove(struct platform_device *pdev)
 {
 	struct usb_hcd *hcd = platform_get_drvdata(pdev);
-	if (hcd) {
-		struct u132 *u132 = hcd_to_u132(hcd);
-		if (u132->going++ > 1) {
-			dev_err(&u132->platform_dev->dev,
-				"already being removed\n");
-			return -ENODEV;
-		} else {
-			int rings = MAX_U132_RINGS;
-			int endps = MAX_U132_ENDPS;
-			dev_err(&u132->platform_dev->dev,
-				"removing device u132.%d\n",
-				u132->sequence_num);
-			msleep(100);
-			mutex_lock(&u132->sw_lock);
-			u132_monitor_cancel_work(u132);
-			while (rings-- > 0) {
-				struct u132_ring *ring = &u132->ring[rings];
-				u132_ring_cancel_work(u132, ring);
-			}
-			while (endps-- > 0) {
-				struct u132_endp *endp = u132->endp[endps];
-				if (endp)
-					u132_endp_cancel_work(u132, endp);
-			}
-			u132->going += 1;
-			printk(KERN_INFO "removing device u132.%d\n",
-				u132->sequence_num);
-			mutex_unlock(&u132->sw_lock);
-			usb_remove_hcd(hcd);
-			u132_u132_put_kref(u132);
-			return 0;
-		}
+	struct u132 *u132 = hcd_to_u132(hcd);
+
+	if (u132->going++ > 1) {
+		dev_err(&u132->platform_dev->dev,
+			"already being removed\n");
+		return -ENODEV;
 	} else {
+		int rings = MAX_U132_RINGS;
+		int endps = MAX_U132_ENDPS;
+		dev_err(&u132->platform_dev->dev,
+			"removing device u132.%d\n",
+			u132->sequence_num);
+		msleep(100);
+		mutex_lock(&u132->sw_lock);
+		u132_monitor_cancel_work(u132);
+		while (rings-- > 0) {
+			struct u132_ring *ring = &u132->ring[rings];
+			u132_ring_cancel_work(u132, ring);
+		}
+		while (endps-- > 0) {
+			struct u132_endp *endp = u132->endp[endps];
+			if (endp)
+				u132_endp_cancel_work(u132, endp);
+		}
+		u132->going += 1;
+		printk(KERN_INFO "removing device u132.%d\n",
+			u132->sequence_num);
+		mutex_unlock(&u132->sw_lock);
+		usb_remove_hcd(hcd);
+		u132_u132_put_kref(u132);
 		return 0;
 	}
 }
@@ -3092,6 +3089,11 @@ static int u132_probe(struct platform_device *pdev)
 	if (retval)
 		return retval;
 
+	/*
+	 * Note that after a successful call of usb_create_hcd(),
+	 * dev_set_drvdata() was called such that platform_get_drvdata(pdev)
+	 * returns hcd later on.
+	 */
 	hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, dev_name(&pdev->dev));
 	if (!hcd) {
 		printk(KERN_ERR "failed to create the usb hcd struct for U132\n");
-- 
2.39.2


      parent reply	other threads:[~2023-03-21 10:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21 10:19 [PATCH 0/2] usb: host: u132-hcd: Two cleanups Uwe Kleine-König
2023-03-21 10:19 ` [PATCH 1/2] usb: host: u132-hcd: Various style improvements Uwe Kleine-König
2023-03-21 10:19 ` Uwe Kleine-König [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230321101911.342538-3-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=ardb@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.