Skip to content

Commit 0cb6866

Browse files
hadessgregkh
authored andcommitted
USB: apple-mfi-fastcharge: don't probe unhandled devices
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. Link: https://bugzilla.redhat.com/show_bug.cgi?id=1878347 Link: https://lore.kernel.org/linux-usb/CAE3RAxt0WhBEz8zkHrVO5RiyEOasayy1QUAjsv-pB0fAbY1GSw@mail.gmail.com/ Fixes: 249fa82 ("USB: Add driver to control USB fast charge for iOS devices") 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] Reported-by: Pany <pany@fedoraproject.org> Tested-by: Pan (Pany) YUAN <pany@fedoraproject.org> Tested-by: Bastien Nocera <hadess@hadess.net> Signed-off-by: Bastien Nocera <hadess@hadess.net> Signed-off-by: M. Vefa Bicakci <m.v.b@runbox.com> Link: https://lore.kernel.org/r/20201022135521.375211-3-m.v.b@runbox.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0942d59 commit 0cb6866

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

drivers/usb/misc/apple-mfi-fastcharge.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,23 @@ static const struct power_supply_desc apple_mfi_fc_desc = {
163163
.property_is_writeable = apple_mfi_fc_property_is_writeable
164164
};
165165

166+
static bool mfi_fc_match(struct usb_device *udev)
167+
{
168+
int idProduct;
169+
170+
idProduct = le16_to_cpu(udev->descriptor.idProduct);
171+
/* See comment above mfi_fc_id_table[] */
172+
return (idProduct >= 0x1200 && idProduct <= 0x12ff);
173+
}
174+
166175
static int mfi_fc_probe(struct usb_device *udev)
167176
{
168177
struct power_supply_config battery_cfg = {};
169178
struct mfi_device *mfi = NULL;
170-
int err, idProduct;
179+
int err;
171180

172-
idProduct = le16_to_cpu(udev->descriptor.idProduct);
173-
/* See comment above mfi_fc_id_table[] */
174-
if (idProduct < 0x1200 || idProduct > 0x12ff) {
181+
if (!mfi_fc_match(udev))
175182
return -ENODEV;
176-
}
177183

178184
mfi = kzalloc(sizeof(struct mfi_device), GFP_KERNEL);
179185
if (!mfi) {
@@ -220,6 +226,7 @@ static struct usb_device_driver mfi_fc_driver = {
220226
.probe = mfi_fc_probe,
221227
.disconnect = mfi_fc_disconnect,
222228
.id_table = mfi_fc_id_table,
229+
.match = mfi_fc_match,
223230
.generic_subclass = 1,
224231
};
225232

0 commit comments

Comments
 (0)