Re: [PATCH net-next 03/19] net: usb: aqc111: Add implementation of read and write commands

From: Oliver Neukum <oneukum@suse.com>
Date: 2018-10-08 13:44:39
Also in: linux-usb

On Fr, 2018-10-05 at 10:24 +0000, Igor Russkikh wrote:
quoted hunk
From: Dmitry Bezrukov <redacted>

Read/write command register defines and functions

Signed-off-by: Dmitry Bezrukov <redacted>
Signed-off-by: Igor Russkikh <redacted>
---
 drivers/net/usb/aqc111.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/usb/aqc111.h |  19 ++++++++
 2 files changed, 143 insertions(+)
 create mode 100644 drivers/net/usb/aqc111.h
diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c
index c914e19387f2..7f3e5a615750 100644
--- a/drivers/net/usb/aqc111.c
+++ b/drivers/net/usb/aqc111.c
@@ -14,6 +14,130 @@
 #include <linux/usb/cdc.h>
 #include <linux/usb/usbnet.h>
 
+#include "aqc111.h"
+
+static int __aqc111_read_cmd(struct usbnet *dev, u8 cmd, u16 value,
+			     u16 index, u16 size, void *data, int nopm)
+{
+	int ret;
+	int (*fn)(struct usbnet *dev, u8 cmd, u8 reqtype, u16 value,
+		  u16 index, void *data, u16 size);
+
+	if (nopm)
+		fn = usbnet_read_cmd_nopm;
+	else
+		fn = usbnet_read_cmd;
If you really want to do this, pass the function.
+
+	ret = fn(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+		 value, index, data, size);
+	if (size == 2)
+		le16_to_cpus(data);
That is incredibly dirty
+
+	if (unlikely(ret < 0))
+		netdev_warn(dev->net,
+			    "Failed to read(0x%x) reg index 0x%04x: %d\n",
+			    cmd, index, ret);
+	return ret;
+}
+
+static int aqc111_read_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
+				u16 index, u16 size, void *data)
+{
+	return __aqc111_read_cmd(dev, cmd, value, index, size, data, 1);
+}
+
+static int aqc111_read_cmd(struct usbnet *dev, u8 cmd, u16 value,
+			   u16 index, u16 size, void *data)
+{
+	return __aqc111_read_cmd(dev, cmd, value, index, size, data, 0);
+}
+
+static int __aq_write_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
+			  u16 value, u16 index, const void *data, u16 size)
+{
+	void *buf = NULL;
+	int err = -ENOMEM;
+
+	netdev_dbg(dev->net,
+		   "%s cmd=%#x reqtype=%#x value=%#x index=%#x size=%d\n",
+		   __func__, cmd, reqtype, value, index, size);
+
+	if (data) {
+		buf = kmemdup(data, size, GFP_KERNEL);
Under which contexts is this used?

	Regards
		Oliver
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help