All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bastien Nocera <hadess@hadess.net>
To: linux-usb@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Bastien Nocera <hadess@hadess.net>,
	Alan Stern <stern@rowland.harvard.edu>
Subject: [PATCH v3 5/6] USB: Fallback to generic driver when specific driver fails
Date: Wed, 16 Oct 2019 11:39:32 +0200	[thread overview]
Message-ID: <20191016093933.693-6-hadess@hadess.net> (raw)
In-Reply-To: <20191016093933.693-1-hadess@hadess.net>

If ->probe fails for a device specific driver, ask the driver core to
reprobe us, after having flagged the device for the generic driver to be
forced.

Signed-off-by: Bastien Nocera <hadess@hadess.net>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
---
 drivers/usb/core/driver.c  | 5 ++++-
 drivers/usb/core/generic.c | 3 +++
 include/linux/usb.h        | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git drivers/usb/core/driver.c drivers/usb/core/driver.c
index 9d1502a9571d..f81606c6a35b 100644
--- drivers/usb/core/driver.c
+++ drivers/usb/core/driver.c
@@ -270,7 +270,10 @@ static int usb_probe_device(struct device *dev)
 		return error;
 
 	error = udriver->probe(udev);
-	/* TODO: fallback to generic driver in case of error */
+	if (error == -ENODEV && udriver != &usb_generic_driver) {
+		udev->use_generic_driver = 1;
+		return -EPROBE_DEFER;
+	}
 	return error;
 }
 
diff --git drivers/usb/core/generic.c drivers/usb/core/generic.c
index 84da85c13825..4626227a6dd2 100644
--- drivers/usb/core/generic.c
+++ drivers/usb/core/generic.c
@@ -213,6 +213,9 @@ static int __check_usb_generic(struct device_driver *drv, void *data)
 
 static bool usb_generic_driver_match(struct usb_device *udev)
 {
+	if (udev->use_generic_driver)
+		return true;
+
 	/*
 	 * If any other driver wants the device, leave the device to this other
 	 * driver.
diff --git include/linux/usb.h include/linux/usb.h
index 3663bd7b1fa4..ca1a5f1e1c5e 100644
--- include/linux/usb.h
+++ include/linux/usb.h
@@ -708,6 +708,7 @@ struct usb_device {
 	unsigned lpm_disable_count;
 
 	u16 hub_delay;
+	unsigned use_generic_driver:1;
 };
 #define	to_usb_device(d) container_of(d, struct usb_device, dev)
 
-- 
2.21.0


  parent reply	other threads:[~2019-10-16  9:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16  9:39 [PATCH v3 0/6] Add Apple MFi fastcharge USB device driver Bastien Nocera
2019-10-16  9:39 ` [PATCH v3 1/6] USB: Export generic USB device driver functions Bastien Nocera
2019-10-16  9:39 ` [PATCH v3 2/6] USB: Make it possible to "subclass" usb_device_driver Bastien Nocera
2019-10-16  9:39 ` [PATCH v3 3/6] USB: Implement usb_device_match_id() Bastien Nocera
2019-10-16  9:39 ` [PATCH v3 4/6] USB: Select better matching USB drivers when available Bastien Nocera
2019-10-16  9:39 ` Bastien Nocera [this message]
2019-10-16  9:39 ` [PATCH v3 6/6] USB: Add driver to control USB fast charge for iOS devices Bastien Nocera
2019-11-21 15:20 ` [PATCH v3 0/6] Add Apple MFi fastcharge USB device driver Bastien Nocera
2020-01-07  8:46   ` Bastien Nocera
2020-01-07  9:35     ` Greg Kroah-Hartman
2020-01-07  9:48       ` Bastien Nocera
2020-02-11  0:21       ` Bastien Nocera
2020-02-12 17:52         ` Greg Kroah-Hartman
2020-02-12 19:06 ` Greg Kroah-Hartman
2020-02-12 23:05   ` Bastien Nocera
2020-02-12 23:17     ` Greg Kroah-Hartman
2020-02-12 23:24       ` Bastien Nocera

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=20191016093933.693-6-hadess@hadess.net \
    --to=hadess@hadess.net \
    --cc=benjamin.tissoires@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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.