forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
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
....@@ -673,8 +661,7 @@
673661 return;
674662 }
675663
676
- memcpy(&intdata, urb->transfer_buffer, 4);
677
- le32_to_cpus(&intdata);
664
+ intdata = get_unaligned_le32(urb->transfer_buffer);
678665
679666 netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
680667
....@@ -770,13 +757,14 @@
770757
771758 static void smsc75xx_init_mac_address(struct usbnet *dev)
772759 {
773
- const u8 *mac_addr;
774
-
775760 /* 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;
761
+ if (!eth_platform_get_mac_address(&dev->udev->dev,
762
+ dev->net->dev_addr)) {
763
+ if (is_valid_ether_addr(dev->net->dev_addr)) {
764
+ /* device tree values are valid so use them */
765
+ netif_dbg(dev, ifup, dev->net, "MAC address read from the device tree\n");
766
+ return;
767
+ }
780768 }
781769
782770 /* try reading mac address from EEPROM */
....@@ -2199,12 +2187,10 @@
21992187 struct sk_buff *ax_skb;
22002188 unsigned char *packet;
22012189
2202
- memcpy(&rx_cmd_a, skb->data, sizeof(rx_cmd_a));
2203
- le32_to_cpus(&rx_cmd_a);
2190
+ rx_cmd_a = get_unaligned_le32(skb->data);
22042191 skb_pull(skb, 4);
22052192
2206
- memcpy(&rx_cmd_b, skb->data, sizeof(rx_cmd_b));
2207
- le32_to_cpus(&rx_cmd_b);
2193
+ rx_cmd_b = get_unaligned_le32(skb->data);
22082194 skb_pull(skb, 4 + RXW_PADDING);
22092195
22102196 packet = skb->data;
....@@ -2276,6 +2262,7 @@
22762262 struct sk_buff *skb, gfp_t flags)
22772263 {
22782264 u32 tx_cmd_a, tx_cmd_b;
2265
+ void *ptr;
22792266
22802267 if (skb_cow_head(skb, SMSC75XX_TX_OVERHEAD)) {
22812268 dev_kfree_skb_any(skb);
....@@ -2296,13 +2283,9 @@
22962283 tx_cmd_b = 0;
22972284 }
22982285
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);
2286
+ ptr = skb_push(skb, 8);
2287
+ put_unaligned_le32(tx_cmd_a, ptr);
2288
+ put_unaligned_le32(tx_cmd_b, ptr + 4);
23062289
23072290 return skb;
23082291 }