.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /*************************************************************************** |
---|
2 | 3 | * |
---|
3 | 4 | * 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/>. |
---|
17 | 5 | * |
---|
18 | 6 | *****************************************************************************/ |
---|
19 | 7 | |
---|
.. | .. |
---|
102 | 90 | ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN |
---|
103 | 91 | | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
---|
104 | 92 | 0, index, &buf, 4); |
---|
105 | | - if (unlikely(ret < 0)) { |
---|
| 93 | + if (unlikely(ret < 4)) { |
---|
| 94 | + ret = ret < 0 ? ret : -ENODATA; |
---|
| 95 | + |
---|
106 | 96 | netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n", |
---|
107 | 97 | index, ret); |
---|
108 | 98 | return ret; |
---|
.. | .. |
---|
673 | 663 | return; |
---|
674 | 664 | } |
---|
675 | 665 | |
---|
676 | | - memcpy(&intdata, urb->transfer_buffer, 4); |
---|
677 | | - le32_to_cpus(&intdata); |
---|
| 666 | + intdata = get_unaligned_le32(urb->transfer_buffer); |
---|
678 | 667 | |
---|
679 | 668 | netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); |
---|
680 | 669 | |
---|
.. | .. |
---|
770 | 759 | |
---|
771 | 760 | static void smsc75xx_init_mac_address(struct usbnet *dev) |
---|
772 | 761 | { |
---|
773 | | - const u8 *mac_addr; |
---|
774 | | - |
---|
775 | 762 | /* 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 | + } |
---|
780 | 770 | } |
---|
781 | 771 | |
---|
782 | 772 | /* try reading mac address from EEPROM */ |
---|
.. | .. |
---|
2199 | 2189 | struct sk_buff *ax_skb; |
---|
2200 | 2190 | unsigned char *packet; |
---|
2201 | 2191 | |
---|
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); |
---|
2204 | 2193 | skb_pull(skb, 4); |
---|
2205 | 2194 | |
---|
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); |
---|
2208 | 2196 | skb_pull(skb, 4 + RXW_PADDING); |
---|
2209 | 2197 | |
---|
2210 | 2198 | packet = skb->data; |
---|
.. | .. |
---|
2212 | 2200 | /* get the packet length */ |
---|
2213 | 2201 | size = (rx_cmd_a & RX_CMD_A_LEN) - RXW_PADDING; |
---|
2214 | 2202 | 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 | + } |
---|
2215 | 2210 | |
---|
2216 | 2211 | if (unlikely(rx_cmd_a & RX_CMD_A_RED)) { |
---|
2217 | 2212 | netif_dbg(dev, rx_err, dev->net, |
---|
.. | .. |
---|
2276 | 2271 | struct sk_buff *skb, gfp_t flags) |
---|
2277 | 2272 | { |
---|
2278 | 2273 | u32 tx_cmd_a, tx_cmd_b; |
---|
| 2274 | + void *ptr; |
---|
2279 | 2275 | |
---|
2280 | 2276 | if (skb_cow_head(skb, SMSC75XX_TX_OVERHEAD)) { |
---|
2281 | 2277 | dev_kfree_skb_any(skb); |
---|
.. | .. |
---|
2296 | 2292 | tx_cmd_b = 0; |
---|
2297 | 2293 | } |
---|
2298 | 2294 | |
---|
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); |
---|
2306 | 2298 | |
---|
2307 | 2299 | return skb; |
---|
2308 | 2300 | } |
---|