forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/net/usb/smsc75xx.c
....@@ -1,19 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /***************************************************************************
23 *
34 * Copyright (C) 2007-2010 SMSC
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License
7
- * as published by the Free Software Foundation; either version 2
8
- * of the License, or (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
175 *
186 *****************************************************************************/
197
....@@ -102,7 +90,9 @@
10290 ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
10391 | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
10492 0, index, &buf, 4);
105
- if (unlikely(ret < 0)) {
93
+ if (unlikely(ret < 4)) {
94
+ ret = ret < 0 ? ret : -ENODATA;
95
+
10696 netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n",
10797 index, ret);
10898 return ret;
....@@ -673,8 +663,7 @@
673663 return;
674664 }
675665
676
- memcpy(&intdata, urb->transfer_buffer, 4);
677
- le32_to_cpus(&intdata);
666
+ intdata = get_unaligned_le32(urb->transfer_buffer);
678667
679668 netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
680669
....@@ -770,13 +759,14 @@
770759
771760 static void smsc75xx_init_mac_address(struct usbnet *dev)
772761 {
773
- const u8 *mac_addr;
774
-
775762 /* maybe the boot loader passed the MAC address in devicetree */
776
- mac_addr = of_get_mac_address(dev->udev->dev.of_node);
777
- if (mac_addr) {
778
- memcpy(dev->net->dev_addr, mac_addr, ETH_ALEN);
779
- return;
763
+ if (!eth_platform_get_mac_address(&dev->udev->dev,
764
+ dev->net->dev_addr)) {
765
+ if (is_valid_ether_addr(dev->net->dev_addr)) {
766
+ /* device tree values are valid so use them */
767
+ netif_dbg(dev, ifup, dev->net, "MAC address read from the device tree\n");
768
+ return;
769
+ }
780770 }
781771
782772 /* try reading mac address from EEPROM */
....@@ -2199,12 +2189,10 @@
21992189 struct sk_buff *ax_skb;
22002190 unsigned char *packet;
22012191
2202
- memcpy(&rx_cmd_a, skb->data, sizeof(rx_cmd_a));
2203
- le32_to_cpus(&rx_cmd_a);
2192
+ rx_cmd_a = get_unaligned_le32(skb->data);
22042193 skb_pull(skb, 4);
22052194
2206
- memcpy(&rx_cmd_b, skb->data, sizeof(rx_cmd_b));
2207
- le32_to_cpus(&rx_cmd_b);
2195
+ rx_cmd_b = get_unaligned_le32(skb->data);
22082196 skb_pull(skb, 4 + RXW_PADDING);
22092197
22102198 packet = skb->data;
....@@ -2212,6 +2200,13 @@
22122200 /* get the packet length */
22132201 size = (rx_cmd_a & RX_CMD_A_LEN) - RXW_PADDING;
22142202 align_count = (4 - ((size + RXW_PADDING) % 4)) % 4;
2203
+
2204
+ if (unlikely(size > skb->len)) {
2205
+ netif_dbg(dev, rx_err, dev->net,
2206
+ "size err rx_cmd_a=0x%08x\n",
2207
+ rx_cmd_a);
2208
+ return 0;
2209
+ }
22152210
22162211 if (unlikely(rx_cmd_a & RX_CMD_A_RED)) {
22172212 netif_dbg(dev, rx_err, dev->net,
....@@ -2276,6 +2271,7 @@
22762271 struct sk_buff *skb, gfp_t flags)
22772272 {
22782273 u32 tx_cmd_a, tx_cmd_b;
2274
+ void *ptr;
22792275
22802276 if (skb_cow_head(skb, SMSC75XX_TX_OVERHEAD)) {
22812277 dev_kfree_skb_any(skb);
....@@ -2296,13 +2292,9 @@
22962292 tx_cmd_b = 0;
22972293 }
22982294
2299
- skb_push(skb, 4);
2300
- cpu_to_le32s(&tx_cmd_b);
2301
- memcpy(skb->data, &tx_cmd_b, 4);
2302
-
2303
- skb_push(skb, 4);
2304
- cpu_to_le32s(&tx_cmd_a);
2305
- memcpy(skb->data, &tx_cmd_a, 4);
2295
+ ptr = skb_push(skb, 8);
2296
+ put_unaligned_le32(tx_cmd_a, ptr);
2297
+ put_unaligned_le32(tx_cmd_b, ptr + 4);
23062298
23072299 return skb;
23082300 }