Re: [PATCH 5/7] net: usb: r8152: Convert to use struct sockaddr_storage internally

Gustavo A. R. Silva
2025-05-20T23:40:15Z

On 20/05/25 16:31, Kees Cook wrote:
> To support coming API type changes, switch to sockaddr_storage usage
> internally.
>
> Signed-off-by: Kees Cook <kees@kernel.org>

Acked-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks!
-Gustavo

> ---
> Cc: Andrew Lunn <andrew+netdev@lunn.ch>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Hayes Wang <hayeswang@realtek.com>
> Cc: Douglas Anderson <dianders@chromium.org>
> Cc: Grant Grundler <grundler@chromium.org>
> Cc: <linux-usb@vger.kernel.org>
> Cc: <netdev@vger.kernel.org>
> ---
> drivers/net/usb/r8152.c | 52 +++++++++++++++++++++--------------------
> 1 file changed, 27 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index 67f5d30ffcba..b18dee1b1bb3 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -1665,14 +1665,14 @@ static int
> rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
> u32 advertising);
>
> -static int __rtl8152_set_mac_address(struct net_device *netdev, void *p,
> +static int __rtl8152_set_mac_address(struct net_device *netdev,
> + struct sockaddr_storage *addr,
> bool in_resume)
> {
> struct r8152 *tp = netdev_priv(netdev);
> - struct sockaddr *addr = p;
> int ret = -EADDRNOTAVAIL;
>
> - if (!is_valid_ether_addr(addr->sa_data))
> + if (!is_valid_ether_addr(addr->__data))
> goto out1;
>
> if (!in_resume) {
> @@ -1683,10 +1683,10 @@ static int __rtl8152_set_mac_address(struct net_device *netdev, void *p,
>
> mutex_lock(&tp->control);
>
> - eth_hw_addr_set(netdev, addr->sa_data);
> + eth_hw_addr_set(netdev, addr->__data);
>
> ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG);
> - pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data);
> + pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->__data);
> ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
>
> mutex_unlock(&tp->control);
> @@ -1706,7 +1706,8 @@ static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
> * host system provided MAC address.
> * Examples of this are Dell TB15 and Dell WD15 docks
> */
> -static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
> +static int vendor_mac_passthru_addr_read(struct r8152 *tp,
> + struct sockaddr_storage *ss)
> {
> acpi_status status;
> struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
> @@ -1774,47 +1775,48 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
> ret = -EINVAL;
> goto amacout;
> }
> - memcpy(sa->sa_data, buf, 6);
> + memcpy(ss->__data, buf, 6);
> tp->netdev->addr_assign_type = NET_ADDR_STOLEN;
> netif_info(tp, probe, tp->netdev,
> - "Using pass-thru MAC addr %pM\n", sa->sa_data);
> + "Using pass-thru MAC addr %pM\n", ss->__data);
>
> amacout:
> kfree(obj);
> return ret;
> }
>
> -static int determine_ethernet_addr(struct r8152 *tp, struct sockaddr *sa)
> +static int determine_ethernet_addr(struct r8152 *tp,
> + struct sockaddr_storage *ss)
> {
> struct net_device *dev = tp->netdev;
> int ret;
>
> - sa->sa_family = dev->type;
> + ss->ss_family = dev->type;
>
> - ret = eth_platform_get_mac_address(&tp->udev->dev, sa->sa_data);
> + ret = eth_platform_get_mac_address(&tp->udev->dev, ss->__data);
> if (ret < 0) {
> if (tp->version == RTL_VER_01) {
> - ret = pla_ocp_read(tp, PLA_IDR, 8, sa->sa_data);
> + ret = pla_ocp_read(tp, PLA_IDR, 8, ss->__data);
> } else {
> /* if device doesn't support MAC pass through this will
> * be expected to be non-zero
> */
> - ret = vendor_mac_passthru_addr_read(tp, sa);
> + ret = vendor_mac_passthru_addr_read(tp, ss);
> if (ret < 0)
> ret = pla_ocp_read(tp, PLA_BACKUP, 8,
> - sa->sa_data);
> + ss->__data);
> }
> }
>
> if (ret < 0) {
> netif_err(tp, probe, dev, "Get ether addr fail\n");
> - } else if (!is_valid_ether_addr(sa->sa_data)) {
> + } else if (!is_valid_ether_addr(ss->__data)) {
> netif_err(tp, probe, dev, "Invalid ether addr %pM\n",
> - sa->sa_data);
> + ss->__data);
> eth_hw_addr_random(dev);
> - ether_addr_copy(sa->sa_data, dev->dev_addr);
> + ether_addr_copy(ss->__data, dev->dev_addr);
> netif_info(tp, probe, dev, "Random ether addr %pM\n",
> - sa->sa_data);
> + ss->__data);
> return 0;
> }
>
> @@ -1824,17 +1826,17 @@ static int determine_ethernet_addr(struct r8152 *tp, struct sockaddr *sa)
> static int set_ethernet_addr(struct r8152 *tp, bool in_resume)
> {
> struct net_device *dev = tp->netdev;
> - struct sockaddr sa;
> + struct sockaddr_storage ss;
> int ret;
>
> - ret = determine_ethernet_addr(tp, &sa);
> + ret = determine_ethernet_addr(tp, &ss);
> if (ret < 0)
> return ret;
>
> if (tp->version == RTL_VER_01)
> - eth_hw_addr_set(dev, sa.sa_data);
> + eth_hw_addr_set(dev, ss.__data);
> else
> - ret = __rtl8152_set_mac_address(dev, &sa, in_resume);
> + ret = __rtl8152_set_mac_address(dev, &ss, in_resume);
>
> return ret;
> }
> @@ -8421,7 +8423,7 @@ static int rtl8152_post_reset(struct usb_interface *intf)
> {
> struct r8152 *tp = usb_get_intfdata(intf);
> struct net_device *netdev;
> - struct sockaddr sa;
> + struct sockaddr_storage ss;
>
> if (!tp || !test_bit(PROBED_WITH_NO_ERRORS, &tp->flags))
> goto exit;
> @@ -8429,8 +8431,8 @@ static int rtl8152_post_reset(struct usb_interface *intf)
> rtl_set_accessible(tp);
>
> /* reset the MAC address in case of policy change */
> - if (determine_ethernet_addr(tp, &sa) >= 0)
> - dev_set_mac_address (tp->netdev, &sa, NULL);
> + if (determine_ethernet_addr(tp, &ss) >= 0)
> + dev_set_mac_address(tp->netdev, (struct sockaddr *)&ss, NULL);
>
> netdev = tp->netdev;
> if (!netif_running(netdev))