From patchwork Fri Oct 12 09:16:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10638141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F334913AD for ; Fri, 12 Oct 2018 09:17:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2D9E2BB68 for ; Fri, 12 Oct 2018 09:17:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6ABB2BB71; Fri, 12 Oct 2018 09:17:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A89D2BB68 for ; Fri, 12 Oct 2018 09:17:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728259AbeJLQs1 (ORCPT ); Fri, 12 Oct 2018 12:48:27 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:49443 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728099AbeJLQs0 (ORCPT ); Fri, 12 Oct 2018 12:48:26 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAtYz-0006u0-0F; Fri, 12 Oct 2018 10:16:53 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAtYy-0005YM-Ep; Fri, 12 Oct 2018 10:16:52 +0100 From: Ben Dooks To: davem@davemloft.net, netdev@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel@lists.codethink.co.uk, gregkh@linuxfoundation.org, bjorn@mork.no, steve.glendinning@shawell.net, Ben Dooks Subject: [PATCH 1/7] net: smsc75xx: add usbnet -> priv function Date: Fri, 12 Oct 2018 10:16:36 +0100 Message-Id: <20181012091642.21294-2-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012091642.21294-1-ben.dooks@codethink.co.uk> References: <20181012091642.21294-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are a number of places in the smsc75xx driver where it gets the private-data from the usbnet passed in. It would be sensible to have one inline function to convert it and change all points in the driver to use that. Signed-off-by: Ben Dooks Reviewed-by: Greg Kroah-Hartman --- drivers/net/usb/smsc75xx.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c index 05553d252446..6d12fcd9b4b0 100644 --- a/drivers/net/usb/smsc75xx.c +++ b/drivers/net/usb/smsc75xx.c @@ -73,6 +73,11 @@ struct smsc75xx_priv { u8 suspend_flags; }; +static inline struct smsc75xx_priv *usbnet_to_smsc(struct usbnet *dev) +{ + return (struct smsc75xx_priv *)dev->data[0]; +} + struct usb_context { struct usb_ctrlrequest req; struct usbnet *dev; @@ -469,7 +474,7 @@ static int smsc75xx_dataport_wait_not_busy(struct usbnet *dev) static int smsc75xx_dataport_write(struct usbnet *dev, u32 ram_select, u32 addr, u32 length, u32 *buf) { - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); u32 dp_sel; int i, ret; @@ -553,7 +558,7 @@ static void smsc75xx_deferred_multicast_write(struct work_struct *param) static void smsc75xx_set_multicast(struct net_device *netdev) { struct usbnet *dev = netdev_priv(netdev); - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); unsigned long flags; int i; @@ -718,7 +723,7 @@ static void smsc75xx_ethtool_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) { struct usbnet *dev = netdev_priv(net); - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); wolinfo->supported = SUPPORTED_WAKE; wolinfo->wolopts = pdata->wolopts; @@ -728,7 +733,7 @@ static int smsc75xx_ethtool_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) { struct usbnet *dev = netdev_priv(net); - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); int ret; pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE; @@ -945,7 +950,7 @@ static int smsc75xx_set_features(struct net_device *netdev, netdev_features_t features) { struct usbnet *dev = netdev_priv(netdev); - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); unsigned long flags; int ret; @@ -1051,7 +1056,7 @@ static int smsc75xx_phy_gig_workaround(struct usbnet *dev) static int smsc75xx_reset(struct usbnet *dev) { - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); u32 buf; int ret = 0, timeout; @@ -1515,7 +1520,7 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf) { - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); if (pdata) { netif_dbg(dev, ifdown, dev->net, "free pdata\n"); kfree(pdata); @@ -1571,7 +1576,7 @@ static int smsc75xx_write_wuff(struct usbnet *dev, int filter, u32 wuf_cfg, static int smsc75xx_enter_suspend0(struct usbnet *dev) { - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); u32 val; int ret; @@ -1597,7 +1602,7 @@ static int smsc75xx_enter_suspend0(struct usbnet *dev) static int smsc75xx_enter_suspend1(struct usbnet *dev) { - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); u32 val; int ret; @@ -1633,7 +1638,7 @@ static int smsc75xx_enter_suspend1(struct usbnet *dev) static int smsc75xx_enter_suspend2(struct usbnet *dev) { - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); u32 val; int ret; @@ -1659,7 +1664,7 @@ static int smsc75xx_enter_suspend2(struct usbnet *dev) static int smsc75xx_enter_suspend3(struct usbnet *dev) { - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); u32 val; int ret; @@ -1794,7 +1799,7 @@ static int smsc75xx_autosuspend(struct usbnet *dev, u32 link_up) static int smsc75xx_suspend(struct usb_interface *intf, pm_message_t message) { struct usbnet *dev = usb_get_intfdata(intf); - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); u32 val, link_up; int ret; @@ -2095,7 +2100,7 @@ static int smsc75xx_suspend(struct usb_interface *intf, pm_message_t message) static int smsc75xx_resume(struct usb_interface *intf) { struct usbnet *dev = usb_get_intfdata(intf); - struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); + struct smsc75xx_priv *pdata = usbnet_to_smsc(dev); u8 suspend_flags = pdata->suspend_flags; int ret; u32 val; From patchwork Fri Oct 12 09:16:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10638147 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65A6C933 for ; Fri, 12 Oct 2018 09:17:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55F892BB68 for ; Fri, 12 Oct 2018 09:17:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AB122BB71; Fri, 12 Oct 2018 09:17:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1AB92BB68 for ; Fri, 12 Oct 2018 09:17:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728188AbeJLQsZ (ORCPT ); Fri, 12 Oct 2018 12:48:25 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:49433 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728088AbeJLQsZ (ORCPT ); Fri, 12 Oct 2018 12:48:25 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAtYz-0006u1-A6; Fri, 12 Oct 2018 10:16:53 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAtYy-0005YP-G9; Fri, 12 Oct 2018 10:16:52 +0100 From: Ben Dooks To: davem@davemloft.net, netdev@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel@lists.codethink.co.uk, gregkh@linuxfoundation.org, bjorn@mork.no, steve.glendinning@shawell.net, Ben Dooks Subject: [PATCH 2/7] net: asix: add usbnet -> priv function Date: Fri, 12 Oct 2018 10:16:37 +0100 Message-Id: <20181012091642.21294-3-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012091642.21294-1-ben.dooks@codethink.co.uk> References: <20181012091642.21294-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are a number of places in the asix driver where it gets the private-data from the usbnet passed in. It would be sensible to have one inline function to convert it and change all points in the driver to use that. Signed-off-by: Ben Dooks Reviewed-by: Greg Kroah-Hartman --- drivers/net/usb/asix.h | 5 +++++ drivers/net/usb/asix_common.c | 4 ++-- drivers/net/usb/asix_devices.c | 16 ++++++++-------- drivers/net/usb/ax88172a.c | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h index 9a4171b90947..4bbb52669ac4 100644 --- a/drivers/net/usb/asix.h +++ b/drivers/net/usb/asix.h @@ -197,6 +197,11 @@ extern const struct driver_info ax88172a_info; /* ASIX specific flags */ #define FLAG_EEPROM_MAC (1UL << 0) /* init device MAC from eeprom */ +static inline struct asix_data *usbnet_to_asix(struct usbnet *usb) +{ + return (struct asix_data *)&usb->data; +} + int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, u16 size, void *data, int in_pm); diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c index e95dd12edec4..1fd650faca5b 100644 --- a/drivers/net/usb/asix_common.c +++ b/drivers/net/usb/asix_common.c @@ -418,7 +418,7 @@ int asix_write_gpio(struct usbnet *dev, u16 value, int sleep, int in_pm) void asix_set_multicast(struct net_device *net) { struct usbnet *dev = netdev_priv(net); - struct asix_data *data = (struct asix_data *)&dev->data; + struct asix_data *data = usbnet_to_asix(dev); u16 rx_ctl = AX_DEFAULT_RX_CTL; if (net->flags & IFF_PROMISC) { @@ -751,7 +751,7 @@ void asix_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info) int asix_set_mac_address(struct net_device *net, void *p) { struct usbnet *dev = netdev_priv(net); - struct asix_data *data = (struct asix_data *)&dev->data; + struct asix_data *data = usbnet_to_asix(dev); struct sockaddr *addr = p; if (netif_running(net)) diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c index b654f05b2ccd..8e387f06dccf 100644 --- a/drivers/net/usb/asix_devices.c +++ b/drivers/net/usb/asix_devices.c @@ -144,7 +144,7 @@ static const struct ethtool_ops ax88172_ethtool_ops = { static void ax88172_set_multicast(struct net_device *net) { struct usbnet *dev = netdev_priv(net); - struct asix_data *data = (struct asix_data *)&dev->data; + struct asix_data *data = usbnet_to_asix(dev); u8 rx_ctl = 0x8c; if (net->flags & IFF_PROMISC) { @@ -332,7 +332,7 @@ static int ax88772_link_reset(struct usbnet *dev) static int ax88772_reset(struct usbnet *dev) { - struct asix_data *data = (struct asix_data *)&dev->data; + struct asix_data *data = usbnet_to_asix(dev); int ret; /* Rewrite MAC address */ @@ -359,7 +359,7 @@ static int ax88772_reset(struct usbnet *dev) static int ax88772_hw_reset(struct usbnet *dev, int in_pm) { - struct asix_data *data = (struct asix_data *)&dev->data; + struct asix_data *data = usbnet_to_asix(dev); int ret, embd_phy; u16 rx_ctl; @@ -454,7 +454,7 @@ static int ax88772_hw_reset(struct usbnet *dev, int in_pm) static int ax88772a_hw_reset(struct usbnet *dev, int in_pm) { - struct asix_data *data = (struct asix_data *)&dev->data; + struct asix_data *data = usbnet_to_asix(dev); int ret, embd_phy; u16 rx_ctl, phy14h, phy15h, phy16h; u8 chipcode = 0; @@ -795,7 +795,7 @@ static const struct ethtool_ops ax88178_ethtool_ops = { static int marvell_phy_init(struct usbnet *dev) { - struct asix_data *data = (struct asix_data *)&dev->data; + struct asix_data *data = usbnet_to_asix(dev); u16 reg; netdev_dbg(dev->net, "marvell_phy_init()\n"); @@ -827,7 +827,7 @@ static int marvell_phy_init(struct usbnet *dev) static int rtl8211cl_phy_init(struct usbnet *dev) { - struct asix_data *data = (struct asix_data *)&dev->data; + struct asix_data *data = usbnet_to_asix(dev); netdev_dbg(dev->net, "rtl8211cl_phy_init()\n"); @@ -874,7 +874,7 @@ static int marvell_led_status(struct usbnet *dev, u16 speed) static int ax88178_reset(struct usbnet *dev) { - struct asix_data *data = (struct asix_data *)&dev->data; + struct asix_data *data = usbnet_to_asix(dev); int ret; __le16 eeprom; u8 status; @@ -962,7 +962,7 @@ static int ax88178_link_reset(struct usbnet *dev) { u16 mode; struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; - struct asix_data *data = (struct asix_data *)&dev->data; + struct asix_data *data = usbnet_to_asix(dev); u32 speed; netdev_dbg(dev->net, "ax88178_link_reset()\n"); diff --git a/drivers/net/usb/ax88172a.c b/drivers/net/usb/ax88172a.c index 501576f53854..08f33c89f002 100644 --- a/drivers/net/usb/ax88172a.c +++ b/drivers/net/usb/ax88172a.c @@ -289,7 +289,7 @@ static void ax88172a_unbind(struct usbnet *dev, struct usb_interface *intf) static int ax88172a_reset(struct usbnet *dev) { - struct asix_data *data = (struct asix_data *)&dev->data; + struct asix_data *data = usbnet_to_asix(dev); struct ax88172a_private *priv = dev->driver_priv; int ret; u16 rx_ctl; From patchwork Fri Oct 12 09:16:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10638145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6257213AD for ; Fri, 12 Oct 2018 09:17:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 528472BB68 for ; Fri, 12 Oct 2018 09:17:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46E8B2BB71; Fri, 12 Oct 2018 09:17:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8E842BB6D for ; Fri, 12 Oct 2018 09:17:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728215AbeJLQsZ (ORCPT ); Fri, 12 Oct 2018 12:48:25 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:49437 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728098AbeJLQsZ (ORCPT ); Fri, 12 Oct 2018 12:48:25 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAtYz-0006u2-CR; Fri, 12 Oct 2018 10:16:53 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAtYy-0005YS-HA; Fri, 12 Oct 2018 10:16:52 +0100 From: Ben Dooks To: davem@davemloft.net, netdev@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel@lists.codethink.co.uk, gregkh@linuxfoundation.org, bjorn@mork.no, steve.glendinning@shawell.net, Ben Dooks Subject: [PATCH 3/7] net: usb: asix88179_178a: add usbnet -> priv function Date: Fri, 12 Oct 2018 10:16:38 +0100 Message-Id: <20181012091642.21294-4-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012091642.21294-1-ben.dooks@codethink.co.uk> References: <20181012091642.21294-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are a number of places in the asix88179_178a driver where it gets the private-data from the usbnet passed in. It would be sensible to have one inline function to convert it and change all points in the driver to use that. Signed-off-by: Ben Dooks Reviewed-by: Greg Kroah-Hartman --- drivers/net/usb/ax88179_178a.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index 9e8ad372f419..f4b64e7e7706 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -196,6 +196,11 @@ static const struct { {7, 0xcc, 0x4c, 0x18, 8}, }; +static inline struct ax88179_data *usbnet_to_ax(struct usbnet *usb) +{ + return (struct ax88179_data *)usb->data; +} + static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, u16 size, void *data, int in_pm) { @@ -678,7 +683,7 @@ ax88179_ethtool_set_eee(struct usbnet *dev, struct ethtool_eee *data) static int ax88179_chk_eee(struct usbnet *dev) { struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; - struct ax88179_data *priv = (struct ax88179_data *)dev->data; + struct ax88179_data *priv = usbnet_to_ax(dev); mii_ethtool_gset(&dev->mii, &ecmd); @@ -781,7 +786,7 @@ static void ax88179_enable_eee(struct usbnet *dev) static int ax88179_get_eee(struct net_device *net, struct ethtool_eee *edata) { struct usbnet *dev = netdev_priv(net); - struct ax88179_data *priv = (struct ax88179_data *)dev->data; + struct ax88179_data *priv = usbnet_to_ax(dev); edata->eee_enabled = priv->eee_enabled; edata->eee_active = priv->eee_active; @@ -792,7 +797,7 @@ static int ax88179_get_eee(struct net_device *net, struct ethtool_eee *edata) static int ax88179_set_eee(struct net_device *net, struct ethtool_eee *edata) { struct usbnet *dev = netdev_priv(net); - struct ax88179_data *priv = (struct ax88179_data *)dev->data; + struct ax88179_data *priv = usbnet_to_ax(dev); int ret = -EOPNOTSUPP; priv->eee_enabled = edata->eee_enabled; @@ -841,7 +846,7 @@ static const struct ethtool_ops ax88179_ethtool_ops = { static void ax88179_set_multicast(struct net_device *net) { struct usbnet *dev = netdev_priv(net); - struct ax88179_data *data = (struct ax88179_data *)dev->data; + struct ax88179_data *data = usbnet_to_ax(dev); u8 *m_filter = ((u8 *)dev->data) + 12; data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE); @@ -1228,7 +1233,7 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) u8 buf[5]; u16 *tmp16; u8 *tmp; - struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; + struct ax88179_data *ax179_data = usbnet_to_ax(dev); struct ethtool_eee eee_data; usbnet_get_endpoints(dev, intf); @@ -1458,7 +1463,7 @@ ax88179_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) static int ax88179_link_reset(struct usbnet *dev) { - struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; + struct ax88179_data *ax179_data = usbnet_to_ax(dev); u8 tmp[5], link_sts; u16 mode, tmp16, delay = HZ / 10; u32 tmp32 = 0x40000000; @@ -1533,7 +1538,7 @@ static int ax88179_reset(struct usbnet *dev) u8 buf[5]; u16 *tmp16; u8 *tmp; - struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; + struct ax88179_data *ax179_data = usbnet_to_ax(dev); struct ethtool_eee eee_data; tmp16 = (u16 *)buf; From patchwork Fri Oct 12 09:16:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10638139 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59D10933 for ; Fri, 12 Oct 2018 09:17:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 494B82BB68 for ; Fri, 12 Oct 2018 09:17:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CAD72BB6D; Fri, 12 Oct 2018 09:17:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C2622BB73 for ; Fri, 12 Oct 2018 09:17:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728283AbeJLQs1 (ORCPT ); Fri, 12 Oct 2018 12:48:27 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:49442 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728104AbeJLQs0 (ORCPT ); Fri, 12 Oct 2018 12:48:26 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAtYz-0006u3-DB; Fri, 12 Oct 2018 10:16:53 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAtYy-0005YV-Hs; Fri, 12 Oct 2018 10:16:52 +0100 From: Ben Dooks To: davem@davemloft.net, netdev@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel@lists.codethink.co.uk, gregkh@linuxfoundation.org, bjorn@mork.no, steve.glendinning@shawell.net, Ben Dooks Subject: [PATCH 4/7] net: qmi_wwan: add usbnet -> priv function Date: Fri, 12 Oct 2018 10:16:39 +0100 Message-Id: <20181012091642.21294-5-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012091642.21294-1-ben.dooks@codethink.co.uk> References: <20181012091642.21294-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are a number of places in the qmi_wwan driver where it gets the private-data from the usbnet passed in. It would be sensible to have one inline function to convert it and change all points in the driver to use that. Signed-off-by: Ben Dooks Reviewed-by: Greg Kroah-Hartman --- drivers/net/usb/qmi_wwan.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c index 533b6fb8d923..45930758a945 100644 --- a/drivers/net/usb/qmi_wwan.c +++ b/drivers/net/usb/qmi_wwan.c @@ -76,6 +76,11 @@ struct qmimux_priv { u8 mux_id; }; +static inline struct qmi_wwan_state *usbnet_to_qmi(struct usbnet *usb) +{ + return (void *) &usb->data; +} + static int qmimux_open(struct net_device *dev) { struct qmimux_priv *priv = netdev_priv(dev); @@ -253,7 +258,7 @@ static void qmimux_unregister_device(struct net_device *dev) static void qmi_wwan_netdev_setup(struct net_device *net) { struct usbnet *dev = netdev_priv(net); - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); if (info->flags & QMI_WWAN_FLAG_RAWIP) { net->header_ops = NULL; /* No header */ @@ -276,7 +281,7 @@ static void qmi_wwan_netdev_setup(struct net_device *net) static ssize_t raw_ip_show(struct device *d, struct device_attribute *attr, char *buf) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); return sprintf(buf, "%c\n", info->flags & QMI_WWAN_FLAG_RAWIP ? 'Y' : 'N'); } @@ -284,7 +289,7 @@ static ssize_t raw_ip_show(struct device *d, struct device_attribute *attr, char static ssize_t raw_ip_store(struct device *d, struct device_attribute *attr, const char *buf, size_t len) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); bool enable; int ret; @@ -346,7 +351,7 @@ static ssize_t add_mux_show(struct device *d, struct device_attribute *attr, cha static ssize_t add_mux_store(struct device *d, struct device_attribute *attr, const char *buf, size_t len) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); u8 mux_id; int ret; @@ -391,7 +396,7 @@ static ssize_t del_mux_show(struct device *d, struct device_attribute *attr, cha static ssize_t del_mux_store(struct device *d, struct device_attribute *attr, const char *buf, size_t len) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); struct net_device *del_dev; u8 mux_id; int ret = 0; @@ -468,7 +473,7 @@ static const u8 buggy_fw_addr[ETH_ALEN] = {0x00, 0xa0, 0xc6, 0x00, 0x00, 0x00}; */ static int qmi_wwan_rx_fixup(struct usbnet *dev, struct sk_buff *skb) { - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); bool rawip = info->flags & QMI_WWAN_FLAG_RAWIP; __be16 proto; @@ -555,7 +560,7 @@ static const struct net_device_ops qmi_wwan_netdev_ops = { */ static int qmi_wwan_manage_power(struct usbnet *dev, int on) { - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); int rv; dev_dbg(&dev->intf->dev, "%s() pmcount=%d, on=%d\n", __func__, @@ -589,7 +594,7 @@ static int qmi_wwan_register_subdriver(struct usbnet *dev) { int rv; struct usb_driver *subdriver = NULL; - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); /* collect bulk endpoints */ rv = usbnet_get_endpoints(dev, info->data); @@ -651,7 +656,7 @@ static int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf) struct usb_cdc_union_desc *cdc_union; struct usb_cdc_ether_desc *cdc_ether; struct usb_driver *driver = driver_of(intf); - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); struct usb_cdc_parsed_header hdr; BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data) < @@ -746,7 +751,7 @@ static int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf) static void qmi_wwan_unbind(struct usbnet *dev, struct usb_interface *intf) { - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); struct usb_driver *driver = driver_of(intf); struct usb_interface *other; @@ -785,7 +790,7 @@ static void qmi_wwan_unbind(struct usbnet *dev, struct usb_interface *intf) static int qmi_wwan_suspend(struct usb_interface *intf, pm_message_t message) { struct usbnet *dev = usb_get_intfdata(intf); - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); int ret; /* Both usbnet_suspend() and subdriver->suspend() MUST return 0 @@ -808,7 +813,7 @@ static int qmi_wwan_suspend(struct usb_interface *intf, pm_message_t message) static int qmi_wwan_resume(struct usb_interface *intf) { struct usbnet *dev = usb_get_intfdata(intf); - struct qmi_wwan_state *info = (void *)&dev->data; + struct qmi_wwan_state *info = usbnet_to_qmi(dev); int ret = 0; bool callsub = (intf == info->control && info->subdriver && info->subdriver->resume); @@ -1406,7 +1411,7 @@ static void qmi_wwan_disconnect(struct usb_interface *intf) /* called twice if separate control and data intf */ if (!dev) return; - info = (void *)&dev->data; + info = usbnet_to_qmi(dev); if (info->flags & QMI_WWAN_FLAG_MUX) { if (!rtnl_trylock()) { restart_syscall(); From patchwork Fri Oct 12 09:16:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10638143 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B0EF713AD for ; Fri, 12 Oct 2018 09:17:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E7F32BB68 for ; Fri, 12 Oct 2018 09:17:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 925AE2BB71; Fri, 12 Oct 2018 09:17:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DCB52BB68 for ; Fri, 12 Oct 2018 09:17:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728248AbeJLQs1 (ORCPT ); Fri, 12 Oct 2018 12:48:27 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:49446 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728120AbeJLQs0 (ORCPT ); Fri, 12 Oct 2018 12:48:26 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAtYz-0006u4-Dy; Fri, 12 Oct 2018 10:16:53 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAtYy-0005YY-Iz; Fri, 12 Oct 2018 10:16:52 +0100 From: Ben Dooks To: davem@davemloft.net, netdev@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel@lists.codethink.co.uk, gregkh@linuxfoundation.org, bjorn@mork.no, steve.glendinning@shawell.net, Ben Dooks Subject: [PATCH 5/7] net: cdc_ether: add usbnet -> priv function Date: Fri, 12 Oct 2018 10:16:40 +0100 Message-Id: <20181012091642.21294-6-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012091642.21294-1-ben.dooks@codethink.co.uk> References: <20181012091642.21294-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are a number of places in the cdc drivers where it gets the private-data from the usbnet passed in. It would be sensible to have one inline function to convert it and change all points in the driver to use that. Signed-off-by: Ben Dooks Reviewed-by: Greg Kroah-Hartman --- drivers/net/usb/cdc_ether.c | 8 ++--- drivers/net/usb/cdc_mbim.c | 23 ++++++++------ drivers/net/usb/cdc_ncm.c | 61 +++++++++++++++++++----------------- drivers/net/usb/rndis_host.c | 6 ++-- include/linux/usb/usbnet.h | 5 +++ 5 files changed, 59 insertions(+), 44 deletions(-) diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c index 5c42cf81a08b..7fee0ebc1943 100644 --- a/drivers/net/usb/cdc_ether.c +++ b/drivers/net/usb/cdc_ether.c @@ -77,7 +77,7 @@ static const u8 mbm_guid[16] = { static void usbnet_cdc_update_filter(struct usbnet *dev) { - struct cdc_state *info = (void *) &dev->data; + struct cdc_state *info = usbnet_to_cdc(dev); struct usb_interface *intf = info->control; struct net_device *net = dev->net; @@ -115,7 +115,7 @@ int usbnet_generic_cdc_bind(struct usbnet *dev, struct usb_interface *intf) u8 *buf = intf->cur_altsetting->extra; int len = intf->cur_altsetting->extralen; struct usb_interface_descriptor *d; - struct cdc_state *info = (void *) &dev->data; + struct cdc_state *info = usbnet_to_cdc(dev); int status; int rndis; bool android_rndis_quirk = false; @@ -353,7 +353,7 @@ EXPORT_SYMBOL_GPL(usbnet_ether_cdc_bind); void usbnet_cdc_unbind(struct usbnet *dev, struct usb_interface *intf) { - struct cdc_state *info = (void *) &dev->data; + struct cdc_state *info = usbnet_to_cdc(dev); struct usb_driver *driver = driver_of(intf); /* combined interface - nothing to do */ @@ -438,7 +438,7 @@ EXPORT_SYMBOL_GPL(usbnet_cdc_status); int usbnet_cdc_bind(struct usbnet *dev, struct usb_interface *intf) { int status; - struct cdc_state *info = (void *) &dev->data; + struct cdc_state *info = usbnet_to_cdc(dev); BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data) < sizeof(struct cdc_state))); diff --git a/drivers/net/usb/cdc_mbim.c b/drivers/net/usb/cdc_mbim.c index 0362acd5cdca..aec8f8eb21a7 100644 --- a/drivers/net/usb/cdc_mbim.c +++ b/drivers/net/usb/cdc_mbim.c @@ -36,6 +36,11 @@ struct cdc_mbim_state { unsigned long flags; }; +static inline struct cdc_mbim_state *usbnet_to_mbim(struct usbnet *usb) +{ + return (void *)&usb->data; +} + /* flags for the cdc_mbim_state.flags field */ enum cdc_mbim_flags { FLAG_IPS0_VLAN = 1 << 0, /* IP session 0 is tagged */ @@ -44,7 +49,7 @@ enum cdc_mbim_flags { /* using a counter to merge subdriver requests with our own into a combined state */ static int cdc_mbim_manage_power(struct usbnet *dev, int on) { - struct cdc_mbim_state *info = (void *)&dev->data; + struct cdc_mbim_state *info = usbnet_to_mbim(dev); int rv = 0; dev_dbg(&dev->intf->dev, "%s() pmcount=%d, on=%d\n", __func__, atomic_read(&info->pmcount), on); @@ -73,7 +78,7 @@ static int cdc_mbim_wdm_manage_power(struct usb_interface *intf, int status) static int cdc_mbim_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid) { struct usbnet *dev = netdev_priv(netdev); - struct cdc_mbim_state *info = (void *)&dev->data; + struct cdc_mbim_state *info = usbnet_to_mbim(dev); /* creation of this VLAN is a request to tag IP session 0 */ if (vid == MBIM_IPS0_VID) @@ -87,7 +92,7 @@ static int cdc_mbim_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid) static int cdc_mbim_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid) { struct usbnet *dev = netdev_priv(netdev); - struct cdc_mbim_state *info = (void *)&dev->data; + struct cdc_mbim_state *info = usbnet_to_mbim(dev); /* this is a request for an untagged IP session 0 */ if (vid == MBIM_IPS0_VID) @@ -144,7 +149,7 @@ static int cdc_mbim_bind(struct usbnet *dev, struct usb_interface *intf) struct usb_driver *subdriver = ERR_PTR(-ENODEV); int ret = -ENODEV; u8 data_altsetting = 1; - struct cdc_mbim_state *info = (void *)&dev->data; + struct cdc_mbim_state *info = usbnet_to_mbim(dev); /* should we change control altsetting on a NCM/MBIM function? */ if (cdc_ncm_select_altsetting(intf) == CDC_NCM_COMM_ALTSETTING_MBIM) { @@ -195,7 +200,7 @@ static int cdc_mbim_bind(struct usbnet *dev, struct usb_interface *intf) static void cdc_mbim_unbind(struct usbnet *dev, struct usb_interface *intf) { - struct cdc_mbim_state *info = (void *)&dev->data; + struct cdc_mbim_state *info = usbnet_to_mbim(dev); struct cdc_ncm_ctx *ctx = info->ctx; /* disconnect subdriver from control interface */ @@ -221,7 +226,7 @@ static bool is_ip_proto(__be16 proto) static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) { struct sk_buff *skb_out; - struct cdc_mbim_state *info = (void *)&dev->data; + struct cdc_mbim_state *info = usbnet_to_mbim(dev); struct cdc_ncm_ctx *ctx = info->ctx; __le32 sign = cpu_to_le32(USB_CDC_MBIM_NDP16_IPS_SIGN); u16 tci = 0; @@ -411,7 +416,7 @@ static struct sk_buff *cdc_mbim_process_dgram(struct usbnet *dev, u8 *buf, size_ static int cdc_mbim_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in) { struct sk_buff *skb; - struct cdc_mbim_state *info = (void *)&dev->data; + struct cdc_mbim_state *info = usbnet_to_mbim(dev); struct cdc_ncm_ctx *ctx = info->ctx; int len; int nframes; @@ -506,7 +511,7 @@ static int cdc_mbim_suspend(struct usb_interface *intf, pm_message_t message) { int ret = -ENODEV; struct usbnet *dev = usb_get_intfdata(intf); - struct cdc_mbim_state *info = (void *)&dev->data; + struct cdc_mbim_state *info = usbnet_to_mbim(dev); struct cdc_ncm_ctx *ctx = info->ctx; if (!ctx) @@ -534,7 +539,7 @@ static int cdc_mbim_resume(struct usb_interface *intf) { int ret = 0; struct usbnet *dev = usb_get_intfdata(intf); - struct cdc_mbim_state *info = (void *)&dev->data; + struct cdc_mbim_state *info = usbnet_to_mbim(dev); struct cdc_ncm_ctx *ctx = info->ctx; bool callsub = (intf == ctx->control && info->subdriver && info->subdriver->resume); diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c index 1eaec648bd1f..0d722b326e1b 100644 --- a/drivers/net/usb/cdc_ncm.c +++ b/drivers/net/usb/cdc_ncm.c @@ -91,6 +91,11 @@ static const struct cdc_ncm_stats cdc_ncm_gstrings_stats[] = { #define CDC_NCM_LOW_MEM_MAX_CNT 10 +static inline struct cdc_ncm_ctx *usbnet_to_ncm(struct usbnet *net) +{ + return (struct cdc_ncm_ctx *)net->data[0]; +} + static int cdc_ncm_get_sset_count(struct net_device __always_unused *netdev, int sset) { switch (sset) { @@ -106,7 +111,7 @@ static void cdc_ncm_get_ethtool_stats(struct net_device *netdev, u64 *data) { struct usbnet *dev = netdev_priv(netdev); - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); int i; char *p = NULL; @@ -148,7 +153,7 @@ static const struct ethtool_ops cdc_ncm_ethtool_ops = { static u32 cdc_ncm_check_rx_max(struct usbnet *dev, u32 new_rx) { - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); u32 val, max, min; /* clamp new_rx to sane values */ @@ -171,7 +176,7 @@ static u32 cdc_ncm_check_rx_max(struct usbnet *dev, u32 new_rx) static u32 cdc_ncm_check_tx_max(struct usbnet *dev, u32 new_tx) { - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); u32 val, max, min; /* clamp new_tx to sane values */ @@ -191,7 +196,7 @@ static u32 cdc_ncm_check_tx_max(struct usbnet *dev, u32 new_tx) static ssize_t cdc_ncm_show_min_tx_pkt(struct device *d, struct device_attribute *attr, char *buf) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); return sprintf(buf, "%u\n", ctx->min_tx_pkt); } @@ -199,7 +204,7 @@ static ssize_t cdc_ncm_show_min_tx_pkt(struct device *d, struct device_attribute static ssize_t cdc_ncm_show_rx_max(struct device *d, struct device_attribute *attr, char *buf) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); return sprintf(buf, "%u\n", ctx->rx_max); } @@ -207,7 +212,7 @@ static ssize_t cdc_ncm_show_rx_max(struct device *d, struct device_attribute *at static ssize_t cdc_ncm_show_tx_max(struct device *d, struct device_attribute *attr, char *buf) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); return sprintf(buf, "%u\n", ctx->tx_max); } @@ -215,7 +220,7 @@ static ssize_t cdc_ncm_show_tx_max(struct device *d, struct device_attribute *at static ssize_t cdc_ncm_show_tx_timer_usecs(struct device *d, struct device_attribute *attr, char *buf) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); return sprintf(buf, "%u\n", ctx->timer_interval / (u32)NSEC_PER_USEC); } @@ -223,7 +228,7 @@ static ssize_t cdc_ncm_show_tx_timer_usecs(struct device *d, struct device_attri static ssize_t cdc_ncm_store_min_tx_pkt(struct device *d, struct device_attribute *attr, const char *buf, size_t len) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); unsigned long val; /* no need to restrict values - anything from 0 to infinity is OK */ @@ -237,7 +242,7 @@ static ssize_t cdc_ncm_store_min_tx_pkt(struct device *d, struct device_attribu static ssize_t cdc_ncm_store_rx_max(struct device *d, struct device_attribute *attr, const char *buf, size_t len) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); unsigned long val; if (kstrtoul(buf, 0, &val) || cdc_ncm_check_rx_max(dev, val) != val) @@ -250,7 +255,7 @@ static ssize_t cdc_ncm_store_rx_max(struct device *d, struct device_attribute * static ssize_t cdc_ncm_store_tx_max(struct device *d, struct device_attribute *attr, const char *buf, size_t len) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); unsigned long val; if (kstrtoul(buf, 0, &val) || cdc_ncm_check_tx_max(dev, val) != val) @@ -263,7 +268,7 @@ static ssize_t cdc_ncm_store_tx_max(struct device *d, struct device_attribute * static ssize_t cdc_ncm_store_tx_timer_usecs(struct device *d, struct device_attribute *attr, const char *buf, size_t len) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); ssize_t ret; unsigned long val; @@ -289,7 +294,7 @@ static DEVICE_ATTR(tx_timer_usecs, 0644, cdc_ncm_show_tx_timer_usecs, cdc_ncm_st static ssize_t ndp_to_end_show(struct device *d, struct device_attribute *attr, char *buf) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); return sprintf(buf, "%c\n", ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END ? 'Y' : 'N'); } @@ -297,7 +302,7 @@ static ssize_t ndp_to_end_show(struct device *d, struct device_attribute *attr, static ssize_t ndp_to_end_store(struct device *d, struct device_attribute *attr, const char *buf, size_t len) { struct usbnet *dev = netdev_priv(to_net_dev(d)); - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); bool enable; if (strtobool(buf, &enable)) @@ -332,7 +337,7 @@ static DEVICE_ATTR_RW(ndp_to_end); static ssize_t cdc_ncm_show_##name(struct device *d, struct device_attribute *attr, char *buf) \ { \ struct usbnet *dev = netdev_priv(to_net_dev(d)); \ - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; \ + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); \ return sprintf(buf, format "\n", tocpu(ctx->ncm_parm.name)); \ } \ static DEVICE_ATTR(name, 0444, cdc_ncm_show_##name, NULL) @@ -375,7 +380,7 @@ static const struct attribute_group cdc_ncm_sysfs_attr_group = { /* handle rx_max and tx_max changes */ static void cdc_ncm_update_rxtx_max(struct usbnet *dev, u32 new_rx, u32 new_tx) { - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); u8 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber; u32 val; @@ -447,7 +452,7 @@ static void cdc_ncm_update_rxtx_max(struct usbnet *dev, u32 new_rx, u32 new_tx) /* helpers for NCM and MBIM differences */ static u8 cdc_ncm_flags(struct usbnet *dev) { - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); if (cdc_ncm_comm_intf_is_mbim(dev->intf->cur_altsetting) && ctx->mbim_desc) return ctx->mbim_desc->bmNetworkCapabilities; @@ -472,7 +477,7 @@ static u32 cdc_ncm_min_dgram_size(struct usbnet *dev) static u32 cdc_ncm_max_dgram_size(struct usbnet *dev) { - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); if (cdc_ncm_comm_intf_is_mbim(dev->intf->cur_altsetting) && ctx->mbim_desc) return le16_to_cpu(ctx->mbim_desc->wMaxSegmentSize); @@ -486,7 +491,7 @@ static u32 cdc_ncm_max_dgram_size(struct usbnet *dev) */ static int cdc_ncm_init(struct usbnet *dev) { - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); u8 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber; int err; @@ -560,7 +565,7 @@ static int cdc_ncm_init(struct usbnet *dev) /* set a new max datagram size */ static void cdc_ncm_set_dgram_size(struct usbnet *dev, int new_size) { - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); u8 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber; __le16 max_datagram_size; u16 mbim_mtu; @@ -608,7 +613,7 @@ static void cdc_ncm_set_dgram_size(struct usbnet *dev, int new_size) static void cdc_ncm_fix_modulus(struct usbnet *dev) { - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); u32 val; /* @@ -652,7 +657,7 @@ static void cdc_ncm_fix_modulus(struct usbnet *dev) static int cdc_ncm_setup(struct usbnet *dev) { - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); u32 def_rx, def_tx; /* be conservative when selecting intial buffer size to @@ -950,7 +955,7 @@ int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_ if (ctx->data != ctx->control) usb_driver_release_interface(driver, ctx->data); error: - cdc_ncm_free((struct cdc_ncm_ctx *)dev->data[0]); + cdc_ncm_free(usbnet_to_ncm(dev)); dev->data[0] = 0; dev_info(&intf->dev, "bind() failure\n"); return -ENODEV; @@ -959,7 +964,7 @@ EXPORT_SYMBOL_GPL(cdc_ncm_bind_common); void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf) { - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); struct usb_driver *driver = driver_of(intf); if (ctx == NULL) @@ -1110,7 +1115,7 @@ static struct usb_cdc_ncm_ndp16 *cdc_ncm_ndp(struct cdc_ncm_ctx *ctx, struct sk_ struct sk_buff * cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign) { - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); struct usb_cdc_ncm_nth16 *nth16; struct usb_cdc_ncm_ndp16 *ndp16; struct sk_buff *skb_out; @@ -1360,7 +1365,7 @@ static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *timer) static void cdc_ncm_txpath_bh(unsigned long param) { struct usbnet *dev = (struct usbnet *)param; - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); spin_lock_bh(&ctx->mtx); if (ctx->tx_timer_pending != 0) { @@ -1382,7 +1387,7 @@ struct sk_buff * cdc_ncm_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) { struct sk_buff *skb_out; - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); /* * The Ethernet API we are using does not support transmitting @@ -1495,7 +1500,7 @@ EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_ndp16); int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in) { struct sk_buff *skb; - struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + struct cdc_ncm_ctx *ctx = usbnet_to_ncm(dev); int len; int nframes; int x; @@ -1604,7 +1609,7 @@ static void cdc_ncm_status(struct usbnet *dev, struct urb *urb) struct cdc_ncm_ctx *ctx; struct usb_cdc_notification *event; - ctx = (struct cdc_ncm_ctx *)dev->data[0]; + ctx = usbnet_to_ncm(dev); if (urb->actual_length < sizeof(*event)) return; diff --git a/drivers/net/usb/rndis_host.c b/drivers/net/usb/rndis_host.c index b807c91abe1d..a24af05a74fb 100644 --- a/drivers/net/usb/rndis_host.c +++ b/drivers/net/usb/rndis_host.c @@ -69,7 +69,7 @@ EXPORT_SYMBOL_GPL(rndis_status); static void rndis_msg_indicate(struct usbnet *dev, struct rndis_indicate *msg, int buflen) { - struct cdc_state *info = (void *)&dev->data; + struct cdc_state *info = usbnet_to_cdc(dev); struct device *udev = &info->control->dev; if (dev->driver_info->indication) { @@ -102,7 +102,7 @@ static void rndis_msg_indicate(struct usbnet *dev, struct rndis_indicate *msg, */ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen) { - struct cdc_state *info = (void *) &dev->data; + struct cdc_state *info = usbnet_to_cdc(dev); struct usb_cdc_notification notification; int master_ifnum; int retval; @@ -301,7 +301,7 @@ generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf, int flags) { int retval; struct net_device *net = dev->net; - struct cdc_state *info = (void *) &dev->data; + struct cdc_state *info = usbnet_to_cdc(dev); union { void *buf; struct rndis_msg_hdr *header; diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h index e2ec3582e549..cdb54dd3a4b4 100644 --- a/include/linux/usb/usbnet.h +++ b/include/linux/usb/usbnet.h @@ -207,6 +207,11 @@ struct cdc_state { struct usb_interface *data; }; +static inline struct cdc_state *usbnet_to_cdc(struct usbnet *net) +{ + return (void *) &net->data; +} + extern int usbnet_generic_cdc_bind(struct usbnet *, struct usb_interface *); extern int usbnet_ether_cdc_bind(struct usbnet *dev, struct usb_interface *intf); extern int usbnet_cdc_bind(struct usbnet *, struct usb_interface *); From patchwork Fri Oct 12 09:16:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10638149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72A6513AD for ; Fri, 12 Oct 2018 09:17:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56A812BB73 for ; Fri, 12 Oct 2018 09:17:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AFD62BB79; Fri, 12 Oct 2018 09:17:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 278392BB73 for ; Fri, 12 Oct 2018 09:17:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728327AbeJLQtC (ORCPT ); Fri, 12 Oct 2018 12:49:02 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:49435 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728102AbeJLQsZ (ORCPT ); Fri, 12 Oct 2018 12:48:25 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAtYz-0006u5-En; Fri, 12 Oct 2018 10:16:53 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAtYy-0005Yb-Jr; Fri, 12 Oct 2018 10:16:52 +0100 From: Ben Dooks To: davem@davemloft.net, netdev@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel@lists.codethink.co.uk, gregkh@linuxfoundation.org, bjorn@mork.no, steve.glendinning@shawell.net, Ben Dooks Subject: [PATCH 6/7] net: huawei_cdc_ncm: add usbnet -> priv function Date: Fri, 12 Oct 2018 10:16:41 +0100 Message-Id: <20181012091642.21294-7-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012091642.21294-1-ben.dooks@codethink.co.uk> References: <20181012091642.21294-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are a number of places in the huawei driver where it gets the private-data from the usbnet passed in. It would be sensible to have one inline function to convert it and change all points in the driver to use that. Signed-off-by: Ben Dooks Reviewed-by: Greg Kroah-Hartman --- --- drivers/net/usb/huawei_cdc_ncm.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/net/usb/huawei_cdc_ncm.c b/drivers/net/usb/huawei_cdc_ncm.c index 63f28908afda..d290b8c318be 100644 --- a/drivers/net/usb/huawei_cdc_ncm.c +++ b/drivers/net/usb/huawei_cdc_ncm.c @@ -38,9 +38,14 @@ struct huawei_cdc_ncm_state { struct usb_interface *data; }; +static inline struct huawei_cdc_ncm_state *usbnet_to_state(struct usbnet *usb) +{ + return (struct huawei_cdc_ncm_state *)&usb->data; +} + static int huawei_cdc_ncm_manage_power(struct usbnet *usbnet_dev, int on) { - struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data; + struct huawei_cdc_ncm_state *drvstate = usbnet_to_state(usbnet_dev); int rv; if ((on && atomic_add_return(1, &drvstate->pmcount) == 1) || @@ -72,7 +77,7 @@ static int huawei_cdc_ncm_bind(struct usbnet *usbnet_dev, struct cdc_ncm_ctx *ctx; struct usb_driver *subdriver = ERR_PTR(-ENODEV); int ret = -ENODEV; - struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data; + struct huawei_cdc_ncm_state *drvstate = usbnet_to_state(usbnet_dev); int drvflags = 0; /* altsetting should always be 1 for NCM devices - so we hard-coded @@ -119,7 +124,7 @@ static int huawei_cdc_ncm_bind(struct usbnet *usbnet_dev, static void huawei_cdc_ncm_unbind(struct usbnet *usbnet_dev, struct usb_interface *intf) { - struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data; + struct huawei_cdc_ncm_state *drvstate = usbnet_to_state(usbnet_dev); struct cdc_ncm_ctx *ctx = drvstate->ctx; if (drvstate->subdriver && drvstate->subdriver->disconnect) @@ -134,7 +139,7 @@ static int huawei_cdc_ncm_suspend(struct usb_interface *intf, { int ret = 0; struct usbnet *usbnet_dev = usb_get_intfdata(intf); - struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data; + struct huawei_cdc_ncm_state *drvstate = usbnet_to_state(usbnet_dev); struct cdc_ncm_ctx *ctx = drvstate->ctx; if (ctx == NULL) { @@ -161,7 +166,7 @@ static int huawei_cdc_ncm_resume(struct usb_interface *intf) { int ret = 0; struct usbnet *usbnet_dev = usb_get_intfdata(intf); - struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data; + struct huawei_cdc_ncm_state *drvstate = usbnet_to_state(usbnet_dev); bool callsub; struct cdc_ncm_ctx *ctx = drvstate->ctx; From patchwork Fri Oct 12 09:16:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10638151 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07E703CF1 for ; Fri, 12 Oct 2018 09:17:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8AE22BB73 for ; Fri, 12 Oct 2018 09:17:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB1B62BB79; Fri, 12 Oct 2018 09:17:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81E062BB73 for ; Fri, 12 Oct 2018 09:17:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728323AbeJLQtC (ORCPT ); Fri, 12 Oct 2018 12:49:02 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:49444 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728103AbeJLQsZ (ORCPT ); Fri, 12 Oct 2018 12:48:25 -0400 Received: from [148.252.241.226] (helo=rainbowdash) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1gAtYz-0006u6-FU; Fri, 12 Oct 2018 10:16:53 +0100 Received: from ben by rainbowdash with local (Exim 4.91) (envelope-from ) id 1gAtYy-0005Ye-Kt; Fri, 12 Oct 2018 10:16:52 +0100 From: Ben Dooks To: davem@davemloft.net, netdev@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel@lists.codethink.co.uk, gregkh@linuxfoundation.org, bjorn@mork.no, steve.glendinning@shawell.net, Ben Dooks Subject: [PATCH 7/7] net: usb: sr9800: add usbnet -> priv function Date: Fri, 12 Oct 2018 10:16:42 +0100 Message-Id: <20181012091642.21294-8-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181012091642.21294-1-ben.dooks@codethink.co.uk> References: <20181012091642.21294-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are a number of places in the sr8900 driver where it gets the private-data from the usbnet passed in. It would be sensible to have one inline function to convert it and change all points in the driver to use that. Signed-off-by: Ben Dooks Reviewed-by: Greg Kroah-Hartman --- drivers/net/usb/sr9800.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/net/usb/sr9800.c b/drivers/net/usb/sr9800.c index 9277a0f228df..2093ecfff5a5 100644 --- a/drivers/net/usb/sr9800.c +++ b/drivers/net/usb/sr9800.c @@ -25,6 +25,11 @@ #include "sr9800.h" +static inline struct sr_data *usbnet_to_sr(struct usbnet *usb) +{ + return (struct sr_data *)&usb->data; +} + static int sr_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, u16 size, void *data) { @@ -296,7 +301,7 @@ static int sr_write_gpio(struct usbnet *dev, u16 value, int sleep) static void sr_set_multicast(struct net_device *net) { struct usbnet *dev = netdev_priv(net); - struct sr_data *data = (struct sr_data *)&dev->data; + struct sr_data *data = usbnet_to_sr(dev); u16 rx_ctl = SR_DEFAULT_RX_CTL; if (net->flags & IFF_PROMISC) { @@ -436,7 +441,7 @@ sr_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) static int sr_get_eeprom_len(struct net_device *net) { struct usbnet *dev = netdev_priv(net); - struct sr_data *data = (struct sr_data *)&dev->data; + struct sr_data *data = usbnet_to_sr(dev); return data->eeprom_len; } @@ -493,7 +498,7 @@ static int sr_ioctl(struct net_device *net, struct ifreq *rq, int cmd) static int sr_set_mac_address(struct net_device *net, void *p) { struct usbnet *dev = netdev_priv(net); - struct sr_data *data = (struct sr_data *)&dev->data; + struct sr_data *data = usbnet_to_sr(dev); struct sockaddr *addr = p; if (netif_running(net)) @@ -595,7 +600,7 @@ static int sr9800_set_default_mode(struct usbnet *dev) static int sr9800_reset(struct usbnet *dev) { - struct sr_data *data = (struct sr_data *)&dev->data; + struct sr_data *data = usbnet_to_sr(dev); int ret, embd_phy; u16 rx_ctl; @@ -726,7 +731,7 @@ static int sr9800_phy_powerup(struct usbnet *dev) static int sr9800_bind(struct usbnet *dev, struct usb_interface *intf) { - struct sr_data *data = (struct sr_data *)&dev->data; + struct sr_data *data = usbnet_to_sr(dev); u16 led01_mux, led23_mux; int ret, embd_phy; u32 phyid;