From: Hayes Wang <hayeswang@realtek.com> To: <netdev@vger.kernel.org> Cc: <nic_swsd@realtek.com>, <linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>, <pmalani@chromium.org>, <grundler@chromium.org>, Hayes Wang <hayeswang@realtek.com> Subject: [PATCH net v3 7/9] r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B Date: Wed, 22 Jan 2020 16:02:11 +0800 [thread overview] Message-ID: <1394712342-15778-365-Taiwan-albertk@realtek.com> (raw) In-Reply-To: <1394712342-15778-358-Taiwan-albertk@realtek.com> For certain platforms, it causes USB reset periodically. Signed-off-by: Hayes Wang <hayeswang@realtek.com> --- drivers/net/usb/r8152.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 7efeddad1fc8..b1a00f29455b 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -3391,7 +3391,8 @@ static void rtl8153b_runtime_enable(struct r8152 *tp, bool enable) r8153b_ups_en(tp, false); r8153_queue_wake(tp, false); rtl_runtime_suspend_enable(tp, false); - r8153b_u1u2en(tp, true); + if (tp->udev->speed != USB_SPEED_HIGH) + r8153b_u1u2en(tp, true); } } @@ -5024,7 +5025,9 @@ static void rtl8153b_up(struct r8152 *tp) ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data); r8153_aldps_en(tp, true); - r8153b_u1u2en(tp, true); + + if (tp->udev->speed != USB_SPEED_HIGH) + r8153b_u1u2en(tp, true); } static void rtl8153b_down(struct r8152 *tp) @@ -5527,7 +5530,9 @@ static void r8153b_init(struct r8152 *tp) ocp_data &= ~CUR_LINK_OK; ocp_data |= POLL_LINK_CHG; ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data); - r8153b_u1u2en(tp, true); + + if (tp->udev->speed != USB_SPEED_HIGH) + r8153b_u1u2en(tp, true); usb_enable_lpm(tp->udev); /* MAC clock speed down */ -- 2.21.0
WARNING: multiple messages have this Message-ID (diff)
From: Hayes Wang <hayeswang@realtek.com> To: <kuba@kernel.org>, <davem@davemloft.net> Cc: <netdev@vger.kernel.org>, <nic_swsd@realtek.com>, <linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>, Hayes Wang <hayeswang@realtek.com>, <syzbot+95afd23673f5dd295c57@syzkaller.appspotmail.com> Subject: [PATCH net v3] r8152: check the informaton of the device Date: Mon, 24 May 2021 14:49:42 +0800 [thread overview] Message-ID: <1394712342-15778-365-Taiwan-albertk@realtek.com> (raw) Message-ID: <20210524064942.pVguISmq0no8uvuHNlQOEIDnqtLeBY69CtGQQuLrXDY@z> (raw) In-Reply-To: <1394712342-15778-363-Taiwan-albertk@realtek.com> Verify some fields of the USB descriptor to make sure the driver could be used by the device. Besides, remove the check of endpoint number in rtl8152_probe(). usb_find_common_endpoints() includes it. BugLink: https://syzkaller.appspot.com/bug?id=912c9c373656996801b4de61f1e3cb326fe940aa Reported-by: syzbot+95afd23673f5dd295c57@syzkaller.appspotmail.com Fixes: c2198943e33b ("r8152: search the configuration of vendor mode") Signed-off-by: Hayes Wang <hayeswang@realtek.com> --- v3: Remove the check of endpoint number in rtl_check_vendor_ok(). Adjust the error message and ccommit message. v2: Use usb_find_common_endpoints() and usb_endpoint_num() to replace original code. remove the check of endpoint number in rtl8152_probe(). It has been done in rtl_check_vendor_ok(). drivers/net/usb/r8152.c | 42 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 136ea06540ff..f6abb2fbf972 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -8107,6 +8107,37 @@ static void r8156b_init(struct r8152 *tp) tp->coalesce = 15000; /* 15 us */ } +static bool rtl_check_vendor_ok(struct usb_interface *intf) +{ + struct usb_host_interface *alt = intf->cur_altsetting; + struct usb_endpoint_descriptor *in, *out, *intr; + + if (usb_find_common_endpoints(alt, &in, &out, &intr, NULL) < 0) { + dev_err(&intf->dev, "Expected endpoints are not found\n"); + return false; + } + + /* Check Rx endpoint address */ + if (usb_endpoint_num(in) != 1) { + dev_err(&intf->dev, "Invalid Rx endpoint address\n"); + return false; + } + + /* Check Tx endpoint address */ + if (usb_endpoint_num(out) != 2) { + dev_err(&intf->dev, "Invalid Tx endpoint address\n"); + return false; + } + + /* Check interrupt endpoint address */ + if (usb_endpoint_num(intr) != 3) { + dev_err(&intf->dev, "Invalid interrupt endpoint address\n"); + return false; + } + + return true; +} + static bool rtl_vendor_mode(struct usb_interface *intf) { struct usb_host_interface *alt = intf->cur_altsetting; @@ -8115,12 +8146,15 @@ static bool rtl_vendor_mode(struct usb_interface *intf) int i, num_configs; if (alt->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) - return true; + 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; @@ -8135,7 +8169,8 @@ static bool rtl_vendor_mode(struct usb_interface *intf) } } - WARN_ON_ONCE(i == num_configs); + if (i == num_configs) + dev_err(&intf->dev, "Unexpected Device\n"); return false; } @@ -9381,9 +9416,6 @@ static int rtl8152_probe(struct usb_interface *intf, if (!rtl_vendor_mode(intf)) return -ENODEV; - if (intf->cur_altsetting->desc.bNumEndpoints < 3) - return -ENODEV; - usb_reset_device(udev); netdev = alloc_etherdev(sizeof(struct r8152)); if (!netdev) { -- 2.26.3
next prev parent reply other threads:[~2020-01-22 8:04 UTC|newest] Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-01-21 12:40 [PATCH net 0/9] r8152: serial fixes Hayes Wang 2020-01-21 12:40 ` [PATCH net 1/9] r8152: fix runtime resume for linking change Hayes Wang 2020-01-22 9:47 ` Sergei Shtylyov 2020-01-21 12:40 ` [PATCH net 2/9] r8152: reset flow control patch when linking on for RTL8153B Hayes Wang 2020-01-21 12:54 ` David Miller 2020-01-21 13:01 ` Joe Perches 2020-01-21 13:19 ` Hayes Wang 2020-01-21 12:40 ` [PATCH net 3/9] r8152: get default setting of WOL before initializing Hayes Wang 2021-02-19 9:04 ` [PATCH net-next 0/4] r8152: minor adjustments Hayes Wang 2021-02-23 20:40 ` patchwork-bot+netdevbpf 2020-01-21 12:40 ` [PATCH net 4/9] r8152: disable U2P3 for RTL8153B Hayes Wang 2021-02-19 9:04 ` [PATCH net-next 1/4] r8152: enable U1/U2 for USB_SPEED_SUPER Hayes Wang 2020-01-21 12:40 ` [PATCH net 5/9] r8152: Disable PLA MCU clock speed down Hayes Wang 2021-02-19 9:04 ` [PATCH net-next 2/4] r8152: check if the pointer of the function exists Hayes Wang 2020-01-21 12:40 ` [PATCH net 6/9] r8152: disable test IO for RTL8153B Hayes Wang 2021-02-19 9:04 ` [PATCH net-next 3/4] r8152: replace netif_err with dev_err Hayes Wang 2020-01-21 12:40 ` [PATCH net 7/9] r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B Hayes Wang 2021-02-19 9:04 ` [PATCH net-next 4/4] r8152: spilt rtl_set_eee_plus and r8153b_green_en Hayes Wang 2020-01-21 12:40 ` [PATCH net 8/9] r8152: avoid the MCU to clear the lanwake Hayes Wang 2021-02-19 9:38 ` [PATCH net] r8152: move r8153_mac_clk_spd Hayes Wang 2021-02-19 18:22 ` Jakub Kicinski 2021-02-22 6:19 ` Hayes Wang 2020-01-21 12:40 ` [PATCH net 9/9] r8152: disable DelayPhyPwrChg Hayes Wang 2020-01-22 7:02 ` Grant Grundler 2020-01-22 7:50 ` Hayes Wang 2021-03-03 8:39 ` [PATCH net] Revert "r8152: adjust the settings about MAC clock speed down for RTL8153" Hayes Wang 2021-03-04 1:00 ` patchwork-bot+netdevbpf 2020-01-22 1:41 ` [PATCH net v2 0/9] r8152: serial fixes Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 1/9] r8152: fix runtime resume for linking change Hayes Wang 2021-03-19 7:37 ` [PATCH net] r8152: limit the RX buffer size of RTL8153A for USB 2.0 Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 2/9] r8152: reset flow control patch when linking on for RTL8153B Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 0/6] r8152: support new chips Hayes Wang 2021-04-16 22:40 ` patchwork-bot+netdevbpf 2020-01-22 1:41 ` [PATCH net v2 3/9] r8152: get default setting of WOL before initializing Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 1/6] r8152: set inter fram gap time depending on speed Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 4/9] r8152: disable U2P3 for RTL8153B Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 2/6] r8152: adjust rtl8152_check_firmware function Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 5/9] r8152: Disable PLA MCU clock speed down Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 3/6] r8152: add help function to change mtu Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 6/9] r8152: disable test IO for RTL8153B Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 4/6] r8152: support new chips Hayes Wang 2021-04-16 21:50 ` Jakub Kicinski 2021-04-20 7:00 ` Hayes Wang 2021-04-20 18:34 ` Jakub Kicinski 2021-04-21 2:23 ` Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 7/9] r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 5/6] r8152: support PHY firmware for RTL8156 series Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 8/9] r8152: avoid the MCU to clear the lanwake Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 6/6] r8152: search the configuration of vendor mode Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 9/9] r8152: disable DelayPhyPwrChg Hayes Wang 2021-03-05 9:34 ` [PATCH net] r8169: fix r8168fp_adjust_ocp_cmd function Hayes Wang 2021-03-05 11:48 ` Heiner Kallweit 2021-03-05 21:10 ` patchwork-bot+netdevbpf 2020-01-22 8:02 ` [PATCH net v3 0/9] r8152: serial fixes Hayes Wang 2020-01-22 8:02 ` [PATCH net v3 1/9] r8152: fix runtime resume for linking change Hayes Wang 2021-04-23 9:44 ` [PATCH net-next 0/2] r8152: adjust REALTEK_USB_DEVICE Hayes Wang 2021-04-23 21:00 ` patchwork-bot+netdevbpf 2020-01-22 8:02 ` [PATCH net v3 2/9] r8152: reset flow control patch when linking on for RTL8153B Hayes Wang 2021-04-23 9:44 ` [PATCH net-next 1/2] r8152: remove NCM mode from REALTEK_USB_DEVICE macro Hayes Wang 2020-01-22 8:02 ` [PATCH net v3 3/9] r8152: get default setting of WOL before initializing Hayes Wang 2021-04-23 9:44 ` [PATCH net-next 2/2] r8152: redefine REALTEK_USB_DEVICE macro Hayes Wang 2020-01-22 8:02 ` [PATCH net v3 4/9] r8152: disable U2P3 for RTL8153B Hayes Wang 2021-04-24 6:09 ` [PATCH net-next] r8152: remove some bit operations Hayes Wang 2021-04-26 1:30 ` patchwork-bot+netdevbpf 2020-01-22 8:02 ` [PATCH net v3 5/9] r8152: Disable PLA MCU clock speed down Hayes Wang 2021-05-21 9:07 ` [PATCH net] r8152: check the informaton of the device Hayes Wang 2021-05-21 9:42 ` Greg KH 2021-05-22 3:13 ` Hayes Wang 2020-01-22 8:02 ` [PATCH net v3 6/9] r8152: disable test IO for RTL8153B Hayes Wang 2021-05-22 5:24 ` [PATCH net v2] r8152: check the informaton of the device Hayes Wang 2021-05-22 7:32 ` Greg KH 2021-05-22 8:07 ` Johan Hovold 2021-05-24 1:49 ` Hayes Wang 2021-05-24 7:44 ` Johan Hovold 2020-01-22 8:02 ` Hayes Wang [this message] 2021-05-24 6:49 ` [PATCH net v3] " Hayes Wang 2021-05-24 8:00 ` Johan Hovold 2021-05-24 8:54 ` Hayes Wang 2021-05-24 9:13 ` Johan Hovold 2021-05-24 20:20 ` patchwork-bot+netdevbpf 2020-01-22 8:02 ` [PATCH net v3 8/9] r8152: avoid the MCU to clear the lanwake Hayes Wang 2021-06-01 7:37 ` [PATCH net-next] r8152: support pauseparam of ethtool_ops Hayes Wang 2021-06-01 22:30 ` patchwork-bot+netdevbpf 2020-01-22 8:02 ` [PATCH net v3 9/9] r8152: disable DelayPhyPwrChg Hayes Wang 2021-06-17 10:00 ` [PATCH net-next] r8152: store the information of the pipes Hayes Wang 2021-06-17 19:20 ` patchwork-bot+netdevbpf 2020-01-23 10:21 ` [PATCH net v3 0/9] r8152: serial fixes David Miller 2021-04-22 8:48 ` [PATCH net-next] r8152: replace return with break for ram code speedup mode timeout Hayes Wang 2021-04-22 21:20 ` patchwork-bot+netdevbpf
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=1394712342-15778-365-Taiwan-albertk@realtek.com \ --to=hayeswang@realtek.com \ --cc=grundler@chromium.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-usb@vger.kernel.org \ --cc=netdev@vger.kernel.org \ --cc=nic_swsd@realtek.com \ --cc=pmalani@chromium.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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).