netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND v3 0/2] Use the new usb control message API.
       [not found] <20200923134348.23862-9-oneukum@suse.com>
@ 2020-09-27 12:49 ` Petko Manolov
  2020-09-27 12:49   ` [PATCH RESEND v3 1/2] net: pegasus: " Petko Manolov
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Petko Manolov @ 2020-09-27 12:49 UTC (permalink / raw)
  To: gregKH; +Cc: linux-usb, davem, netdev, Petko Manolov

Re-sending these, now CC-ing the folks at linux-netdev.

Open coding, occasional improper error handling by the caller of
usb_control_msg() and not flagging partial read as an error requires a new API
that takes care of these issues.  It took the form of
usb_control_msg_send/recv() and this patch series is converting Pegasus and
RTL8150 drivers to using the proper calls.

Petko Manolov (2):
  net: pegasus: Use the new usb control message API.
  net: rtl8150: Use the new usb control message API.

 drivers/net/usb/pegasus.c | 61 ++++++++++-----------------------------
 drivers/net/usb/rtl8150.c | 32 ++++----------------
 2 files changed, 21 insertions(+), 72 deletions(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH RESEND v3 1/2] net: pegasus: Use the new usb control message API.
  2020-09-27 12:49 ` [PATCH RESEND v3 0/2] Use the new usb control message API Petko Manolov
@ 2020-09-27 12:49   ` Petko Manolov
  2020-09-27 12:49   ` [PATCH RESEND v3 2/2] net: rtl8150: " Petko Manolov
  2020-09-28 23:00   ` [PATCH RESEND v3 0/2] " David Miller
  2 siblings, 0 replies; 7+ messages in thread
From: Petko Manolov @ 2020-09-27 12:49 UTC (permalink / raw)
  To: gregKH; +Cc: linux-usb, davem, netdev, Petko Manolov

The old usb_control_msg() let the caller handle the error and also did not
account for partial reads.  Since these are now considered harmful, move the
driver over to usb_control_msg_recv/send() calls.

Added small note about why set_registers() can't be used to substitute
set_register().

Signed-off-by: Petko Manolov <petko.manolov@konsulko.com>
---
 drivers/net/usb/pegasus.c | 61 ++++++++++-----------------------------
 1 file changed, 15 insertions(+), 46 deletions(-)

diff --git a/drivers/net/usb/pegasus.c b/drivers/net/usb/pegasus.c
index e92cb51a2c77..26b4e48bf91f 100644
--- a/drivers/net/usb/pegasus.c
+++ b/drivers/net/usb/pegasus.c
@@ -124,62 +124,31 @@ static void async_ctrl_callback(struct urb *urb)
 
 static int get_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data)
 {
-	u8 *buf;
-	int ret;
-
-	buf = kmalloc(size, GFP_NOIO);
-	if (!buf)
-		return -ENOMEM;
-
-	ret = usb_control_msg(pegasus->usb, usb_rcvctrlpipe(pegasus->usb, 0),
-			      PEGASUS_REQ_GET_REGS, PEGASUS_REQT_READ, 0,
-			      indx, buf, size, 1000);
-	if (ret < 0)
-		netif_dbg(pegasus, drv, pegasus->net,
-			  "%s returned %d\n", __func__, ret);
-	else if (ret <= size)
-		memcpy(data, buf, ret);
-	kfree(buf);
-	return ret;
+	return usb_control_msg_recv(pegasus->usb, 0, PEGASUS_REQ_GET_REGS,
+				   PEGASUS_REQT_READ, 0, indx, data, size,
+				   1000, GFP_NOIO);
 }
 
 static int set_registers(pegasus_t *pegasus, __u16 indx, __u16 size,
 			 const void *data)
 {
-	u8 *buf;
-	int ret;
-
-	buf = kmemdup(data, size, GFP_NOIO);
-	if (!buf)
-		return -ENOMEM;
-
-	ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0),
-			      PEGASUS_REQ_SET_REGS, PEGASUS_REQT_WRITE, 0,
-			      indx, buf, size, 100);
-	if (ret < 0)
-		netif_dbg(pegasus, drv, pegasus->net,
-			  "%s returned %d\n", __func__, ret);
-	kfree(buf);
-	return ret;
+	return usb_control_msg_send(pegasus->usb, 0, PEGASUS_REQ_SET_REGS,
+				    PEGASUS_REQT_WRITE, 0, indx, data, size,
+				    1000, GFP_NOIO);
 }
 
+/*
+ * There is only one way to write to a single ADM8511 register and this is via
+ * specific control request.  'data' is ignored by the device, but it is here to
+ * not break the API.
+ */
 static int set_register(pegasus_t *pegasus, __u16 indx, __u8 data)
 {
-	u8 *buf;
-	int ret;
-
-	buf = kmemdup(&data, 1, GFP_NOIO);
-	if (!buf)
-		return -ENOMEM;
+	void *buf = &data;
 
-	ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0),
-			      PEGASUS_REQ_SET_REG, PEGASUS_REQT_WRITE, data,
-			      indx, buf, 1, 1000);
-	if (ret < 0)
-		netif_dbg(pegasus, drv, pegasus->net,
-			  "%s returned %d\n", __func__, ret);
-	kfree(buf);
-	return ret;
+	return usb_control_msg_send(pegasus->usb, 0, PEGASUS_REQ_SET_REG,
+				    PEGASUS_REQT_WRITE, data, indx, buf, 1,
+				    1000, GFP_NOIO);
 }
 
 static int update_eth_regs_async(pegasus_t *pegasus)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH RESEND v3 2/2] net: rtl8150: Use the new usb control message API.
  2020-09-27 12:49 ` [PATCH RESEND v3 0/2] Use the new usb control message API Petko Manolov
  2020-09-27 12:49   ` [PATCH RESEND v3 1/2] net: pegasus: " Petko Manolov
@ 2020-09-27 12:49   ` Petko Manolov
  2020-09-28 23:00   ` [PATCH RESEND v3 0/2] " David Miller
  2 siblings, 0 replies; 7+ messages in thread
From: Petko Manolov @ 2020-09-27 12:49 UTC (permalink / raw)
  To: gregKH; +Cc: linux-usb, davem, netdev, Petko Manolov

The old usb_control_msg() let the caller handle the error and also did not
account for partial reads.  Since these are now considered harmful, move the
driver over to usb_control_msg_recv/send() calls.

Signed-off-by: Petko Manolov <petko.manolov@konsulko.com>
---
 drivers/net/usb/rtl8150.c | 32 ++++++--------------------------
 1 file changed, 6 insertions(+), 26 deletions(-)

diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index 733f120c852b..b3a0b188b1a1 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -152,36 +152,16 @@ static const char driver_name [] = "rtl8150";
 */
 static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
 {
-	void *buf;
-	int ret;
-
-	buf = kmalloc(size, GFP_NOIO);
-	if (!buf)
-		return -ENOMEM;
-
-	ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
-			      RTL8150_REQ_GET_REGS, RTL8150_REQT_READ,
-			      indx, 0, buf, size, 500);
-	if (ret > 0 && ret <= size)
-		memcpy(data, buf, ret);
-	kfree(buf);
-	return ret;
+	return usb_control_msg_recv(dev->udev, 0, RTL8150_REQ_GET_REGS,
+				    RTL8150_REQT_READ, indx, 0, data, size,
+				    1000, GFP_NOIO);
 }
 
 static int set_registers(rtl8150_t * dev, u16 indx, u16 size, const void *data)
 {
-	void *buf;
-	int ret;
-
-	buf = kmemdup(data, size, GFP_NOIO);
-	if (!buf)
-		return -ENOMEM;
-
-	ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
-			      RTL8150_REQ_SET_REGS, RTL8150_REQT_WRITE,
-			      indx, 0, buf, size, 500);
-	kfree(buf);
-	return ret;
+	return usb_control_msg_send(dev->udev, 0, RTL8150_REQ_SET_REGS,
+				    RTL8150_REQT_WRITE, indx, 0, data, size,
+				    1000, GFP_NOIO);
 }
 
 static void async_set_reg_cb(struct urb *urb)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND v3 0/2] Use the new usb control message API.
  2020-09-27 12:49 ` [PATCH RESEND v3 0/2] Use the new usb control message API Petko Manolov
  2020-09-27 12:49   ` [PATCH RESEND v3 1/2] net: pegasus: " Petko Manolov
  2020-09-27 12:49   ` [PATCH RESEND v3 2/2] net: rtl8150: " Petko Manolov
@ 2020-09-28 23:00   ` David Miller
  2020-09-29  4:59     ` Petko Manolov
  2 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2020-09-28 23:00 UTC (permalink / raw)
  To: petko.manolov; +Cc: gregKH, linux-usb, netdev

From: Petko Manolov <petko.manolov@konsulko.com>
Date: Sun, 27 Sep 2020 15:49:07 +0300

> Re-sending these, now CC-ing the folks at linux-netdev.

I can't apply these since the helpers do not exist in the
networking tree.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND v3 0/2] Use the new usb control message API.
  2020-09-28 23:00   ` [PATCH RESEND v3 0/2] " David Miller
@ 2020-09-29  4:59     ` Petko Manolov
  2020-09-29 19:58       ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Petko Manolov @ 2020-09-29  4:59 UTC (permalink / raw)
  To: David Miller; +Cc: gregKH, linux-usb, netdev

On 20-09-28 16:00:58, David Miller wrote:
> From: Petko Manolov <petko.manolov@konsulko.com> Date: Sun, 27 Sep 2020 
> 15:49:07 +0300
> 
> > Re-sending these, now CC-ing the folks at linux-netdev.
> 
> I can't apply these since the helpers do not exist in the networking tree.

Right, Greg was only asking for ack (or nack) from your side.


cheers,
Petko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND v3 0/2] Use the new usb control message API.
  2020-09-29  4:59     ` Petko Manolov
@ 2020-09-29 19:58       ` David Miller
  2020-09-30  6:23         ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2020-09-29 19:58 UTC (permalink / raw)
  To: petko.manolov; +Cc: gregKH, linux-usb, netdev

From: Petko Manolov <petko.manolov@konsulko.com>
Date: Tue, 29 Sep 2020 07:59:11 +0300

> On 20-09-28 16:00:58, David Miller wrote:
>> From: Petko Manolov <petko.manolov@konsulko.com> Date: Sun, 27 Sep 2020 
>> 15:49:07 +0300
>> 
>> > Re-sending these, now CC-ing the folks at linux-netdev.
>> 
>> I can't apply these since the helpers do not exist in the networking tree.
> 
> Right, Greg was only asking for ack (or nack) from your side.

Acked-by: David S. Miller <davem@davemloft.net>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND v3 0/2] Use the new usb control message API.
  2020-09-29 19:58       ` David Miller
@ 2020-09-30  6:23         ` Greg KH
  0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2020-09-30  6:23 UTC (permalink / raw)
  To: David Miller; +Cc: petko.manolov, linux-usb, netdev

On Tue, Sep 29, 2020 at 12:58:49PM -0700, David Miller wrote:
> From: Petko Manolov <petko.manolov@konsulko.com>
> Date: Tue, 29 Sep 2020 07:59:11 +0300
> 
> > On 20-09-28 16:00:58, David Miller wrote:
> >> From: Petko Manolov <petko.manolov@konsulko.com> Date: Sun, 27 Sep 2020 
> >> 15:49:07 +0300
> >> 
> >> > Re-sending these, now CC-ing the folks at linux-netdev.
> >> 
> >> I can't apply these since the helpers do not exist in the networking tree.
> > 
> > Right, Greg was only asking for ack (or nack) from your side.
> 
> Acked-by: David S. Miller <davem@davemloft.net>

Thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-09-30  6:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200923134348.23862-9-oneukum@suse.com>
2020-09-27 12:49 ` [PATCH RESEND v3 0/2] Use the new usb control message API Petko Manolov
2020-09-27 12:49   ` [PATCH RESEND v3 1/2] net: pegasus: " Petko Manolov
2020-09-27 12:49   ` [PATCH RESEND v3 2/2] net: rtl8150: " Petko Manolov
2020-09-28 23:00   ` [PATCH RESEND v3 0/2] " David Miller
2020-09-29  4:59     ` Petko Manolov
2020-09-29 19:58       ` David Miller
2020-09-30  6:23         ` Greg KH

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).