diff mbox series

[2/2] USB: apple-mfi-fastcharge: don't probe unhandled devices

Message ID 20201022135521.375211-3-m.v.b@runbox.com
State New
Headers show
Series Patches to prevent re-probing all Apple USB devices on apple-mfi-fastcharge load | expand

Commit Message

M. Vefa Bicakci Oct. 22, 2020, 1:55 p.m. UTC
From: Bastien Nocera <hadess@hadess.net>

From: Bastien Nocera <hadess@hadess.net>

Contrary to the comment above the id table, we didn't implement a match
function. This meant that every single Apple device that was already
plugged in to the computer would have its device driver reprobed
when the apple-mfi-fastcharge driver was loaded, eg. the SD card reader
could be reprobed when the apple-mfi-fastcharge after pivoting root
during boot up and the module became available.

Make sure that the driver probe isn't being run for unsupported
devices by adding a match function that checks the product ID, in
addition to the id_table checking the vendor ID.

Fixes: 249fa8217b84 ("USB: Add driver to control USB fast charge for iOS devices")
Signed-off-by: Bastien Nocera <hadess@hadess.net>
Reported-by: Pany <pany@fedoraproject.org>
Link: https://bugzilla.redhat.com/show_bug.cgi?id=1878347
Link: https://lore.kernel.org/linux-usb/CAE3RAxt0WhBEz8zkHrVO5RiyEOasayy1QUAjsv-pB0fAbY1GSw@mail.gmail.com/
Cc: <stable@vger.kernel.org> # 5.8
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
[m.v.b: Add Link and Reported-by tags to the commit message]
Signed-off-by: M. Vefa Bicakci <m.v.b@runbox.com>
---
 drivers/usb/misc/apple-mfi-fastcharge.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Comments

Bastien Nocera Oct. 27, 2020, 2:02 p.m. UTC | #1
On Thu, 2020-10-22 at 09:55 -0400, M. Vefa Bicakci wrote:
> From: Bastien Nocera <hadess@hadess.net>
> 
> From: Bastien Nocera <hadess@hadess.net>
> 
> Contrary to the comment above the id table, we didn't implement a
> match
> function. This meant that every single Apple device that was already
> plugged in to the computer would have its device driver reprobed
> when the apple-mfi-fastcharge driver was loaded, eg. the SD card
> reader
> could be reprobed when the apple-mfi-fastcharge after pivoting root
> during boot up and the module became available.
> 
> Make sure that the driver probe isn't being run for unsupported
> devices by adding a match function that checks the product ID, in
> addition to the id_table checking the vendor ID.
> 
> Fixes: 249fa8217b84 ("USB: Add driver to control USB fast charge for
> iOS devices")
> Signed-off-by: Bastien Nocera <hadess@hadess.net>
> Reported-by: Pany <pany@fedoraproject.org>
> Link: https://bugzilla.redhat.com/show_bug.cgi?id=1878347
> Link: 
> https://lore.kernel.org/linux-usb/CAE3RAxt0WhBEz8zkHrVO5RiyEOasayy1QUAjsv-pB0fAbY1GSw@mail.gmail.com/
> Cc: <stable@vger.kernel.org> # 5.8
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Alan Stern <stern@rowland.harvard.edu>
> [m.v.b: Add Link and Reported-by tags to the commit message]
> Signed-off-by: M. Vefa Bicakci <m.v.b@runbox.com>

And along with the 1/2 patch:
Tested-by: Bastien Nocera <hadess@hadess.net>
Pany Oct. 28, 2020, 4:01 a.m. UTC | #2
On Tue, Oct 27, 2020 at 2:03 PM Bastien Nocera <hadess@hadess.net> wrote:
>
> On Thu, 2020-10-22 at 09:55 -0400, M. Vefa Bicakci wrote:
> > From: Bastien Nocera <hadess@hadess.net>
> >
> > From: Bastien Nocera <hadess@hadess.net>
> >
> > Contrary to the comment above the id table, we didn't implement a
> > match
> > function. This meant that every single Apple device that was already
> > plugged in to the computer would have its device driver reprobed
> > when the apple-mfi-fastcharge driver was loaded, eg. the SD card
> > reader
> > could be reprobed when the apple-mfi-fastcharge after pivoting root
> > during boot up and the module became available.
> >
> > Make sure that the driver probe isn't being run for unsupported
> > devices by adding a match function that checks the product ID, in
> > addition to the id_table checking the vendor ID.
> >
> > Fixes: 249fa8217b84 ("USB: Add driver to control USB fast charge for
> > iOS devices")
> > Signed-off-by: Bastien Nocera <hadess@hadess.net>
> > Reported-by: Pany <pany@fedoraproject.org>
> > Link: https://bugzilla.redhat.com/show_bug.cgi?id=1878347
> > Link:
> > https://lore.kernel.org/linux-usb/CAE3RAxt0WhBEz8zkHrVO5RiyEOasayy1QUAjsv-pB0fAbY1GSw@mail.gmail.com/
> > Cc: <stable@vger.kernel.org> # 5.8
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Alan Stern <stern@rowland.harvard.edu>
> > [m.v.b: Add Link and Reported-by tags to the commit message]
> > Signed-off-by: M. Vefa Bicakci <m.v.b@runbox.com>
>
> And along with the 1/2 patch:
> Tested-by: Bastien Nocera <hadess@hadess.net>
>

This patch works well for me.
Tested-by: Pan (Pany) YUAN <pany@fedoraproject.org>
diff mbox series

Patch

diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
index b403094a6b3a..579d8c84de42 100644
--- a/drivers/usb/misc/apple-mfi-fastcharge.c
+++ b/drivers/usb/misc/apple-mfi-fastcharge.c
@@ -163,17 +163,23 @@  static const struct power_supply_desc apple_mfi_fc_desc = {
 	.property_is_writeable  = apple_mfi_fc_property_is_writeable
 };
 
+static bool mfi_fc_match(struct usb_device *udev)
+{
+	int idProduct;
+
+	idProduct = le16_to_cpu(udev->descriptor.idProduct);
+	/* See comment above mfi_fc_id_table[] */
+	return (idProduct >= 0x1200 && idProduct <= 0x12ff);
+}
+
 static int mfi_fc_probe(struct usb_device *udev)
 {
 	struct power_supply_config battery_cfg = {};
 	struct mfi_device *mfi = NULL;
-	int err, idProduct;
+	int err;
 
-	idProduct = le16_to_cpu(udev->descriptor.idProduct);
-	/* See comment above mfi_fc_id_table[] */
-	if (idProduct < 0x1200 || idProduct > 0x12ff) {
+	if (!mfi_fc_match(udev))
 		return -ENODEV;
-	}
 
 	mfi = kzalloc(sizeof(struct mfi_device), GFP_KERNEL);
 	if (!mfi) {
@@ -220,6 +226,7 @@  static struct usb_device_driver mfi_fc_driver = {
 	.probe =	mfi_fc_probe,
 	.disconnect =	mfi_fc_disconnect,
 	.id_table =	mfi_fc_id_table,
+	.match =	mfi_fc_match,
 	.generic_subclass = 1,
 };