linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Dooks <ben.dooks@codethink.co.uk>
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 <ben.dooks@codethink.co.uk>
Subject: [PATCH 6/7] net: huawei_cdc_ncm: add usbnet -> priv function
Date: Fri, 12 Oct 2018 10:16:41 +0100	[thread overview]
Message-ID: <20181012091642.21294-7-ben.dooks@codethink.co.uk> (raw)
In-Reply-To: <20181012091642.21294-1-ben.dooks@codethink.co.uk>

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 <ben.dooks@codethink.co.uk>
---
---
 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;
 
-- 
2.19.1


  parent reply	other threads:[~2018-10-12  9:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-12  9:16 usbnet private-data accessor functions Ben Dooks
2018-10-12  9:16 ` [PATCH 1/7] net: smsc75xx: add usbnet -> priv function Ben Dooks
2018-10-12 10:19   ` Greg KH
2018-10-12  9:16 ` [PATCH 2/7] net: asix: " Ben Dooks
2018-10-12 10:20   ` Greg KH
2018-10-12  9:16 ` [PATCH 3/7] net: usb: asix88179_178a: " Ben Dooks
2018-10-12 10:20   ` Greg KH
2018-10-12  9:16 ` [PATCH 4/7] net: qmi_wwan: " Ben Dooks
2018-10-12 10:20   ` Greg KH
2018-10-12 10:44   ` Bjørn Mork
2018-10-12 13:22     ` Ben Dooks
2018-10-12  9:16 ` [PATCH 5/7] net: cdc_ether: " Ben Dooks
2018-10-12 10:20   ` Greg KH
2018-10-12  9:16 ` Ben Dooks [this message]
2018-10-12 10:20   ` [PATCH 6/7] net: huawei_cdc_ncm: " Greg KH
2018-10-12  9:16 ` [PATCH 7/7] net: usb: sr9800: " Ben Dooks
2018-10-12 10:20   ` Greg KH
2018-10-12 15:38 ` usbnet private-data accessor functions Oliver Neukum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181012091642.21294-7-ben.dooks@codethink.co.uk \
    --to=ben.dooks@codethink.co.uk \
    --cc=bjorn@mork.no \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@lists.codethink.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=steve.glendinning@shawell.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).