Commit bc170f96 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'r8152-improve-the-code'

Hayes Wang says:

====================
r8152: improve the code

These are some minor improvements depending on commit ec51fbd1 ("r8152:
add USB device driver for config selection").
====================

Link: https://lore.kernel.org/r/20230119074043.10021-397-nic_swsd@realtek.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents b3c588cd 02767440
......@@ -8232,43 +8232,6 @@ static bool rtl_check_vendor_ok(struct usb_interface *intf)
return true;
}
static bool rtl_vendor_mode(struct usb_interface *intf)
{
struct usb_host_interface *alt = intf->cur_altsetting;
struct usb_device *udev;
struct usb_host_config *c;
int i, num_configs;
if (alt->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC)
return rtl_check_vendor_ok(intf);
/* The vendor mode is not always config #1, so to find it out. */
udev = interface_to_usbdev(intf);
c = udev->config;
num_configs = udev->descriptor.bNumConfigurations;
if (num_configs < 2)
return false;
for (i = 0; i < num_configs; (i++, c++)) {
struct usb_interface_descriptor *desc = NULL;
if (c->desc.bNumInterfaces > 0)
desc = &c->intf_cache[0]->altsetting->desc;
else
continue;
if (desc->bInterfaceClass == USB_CLASS_VENDOR_SPEC) {
usb_driver_set_configuration(udev, c->desc.bConfigurationValue);
break;
}
}
if (i == num_configs)
dev_err(&intf->dev, "Unexpected Device\n");
return false;
}
static int rtl8152_pre_reset(struct usb_interface *intf)
{
struct r8152 *tp = usb_get_intfdata(intf);
......@@ -9618,18 +9581,19 @@ static int rtl8152_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_device *udev = interface_to_usbdev(intf);
u8 version = rtl8152_get_version(intf);
struct r8152 *tp;
struct net_device *netdev;
u8 version;
int ret;
if (version == RTL_VER_UNKNOWN)
if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
return -ENODEV;
if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
if (!rtl_check_vendor_ok(intf))
return -ENODEV;
if (!rtl_vendor_mode(intf))
version = rtl8152_get_version(intf);
if (version == RTL_VER_UNKNOWN)
return -ENODEV;
usb_reset_device(udev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment