driverdev-devel.linuxdriverproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/5] staging: vt6656: limit reg output to block size
@ 2019-12-20 21:15 Malcolm Priestley
  2020-01-03 11:13 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Malcolm Priestley @ 2019-12-20 21:15 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel

vnt_control_out appears to fail when BBREG is greater than 64 writes.

Create new function that will relay an array in no larger than
the indicated block size.

It appears that this command has always failed but was ignored by
driver until the introduction of error checking.

Cc: stable <stable@vger.kernel.org> # v5.3+
Signed-off-by: Malcolm Priestley <tvboxspy@gmail.com>
---
 drivers/staging/vt6656/baseband.c |  4 ++--
 drivers/staging/vt6656/usbpipe.c  | 17 +++++++++++++++++
 drivers/staging/vt6656/usbpipe.h  |  5 +++++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c
index 8d19ae71e7cc..4e651b698617 100644
--- a/drivers/staging/vt6656/baseband.c
+++ b/drivers/staging/vt6656/baseband.c
@@ -449,8 +449,8 @@ int vnt_vt3184_init(struct vnt_private *priv)
 
 	memcpy(array, addr, length);
 
-	ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
-			      MESSAGE_REQUEST_BBREG, length, array);
+	ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE,
+				     MESSAGE_REQUEST_BBREG, length, array);
 	if (ret)
 		goto end;
 
diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c
index 488ebd98773d..d977d4777e4f 100644
--- a/drivers/staging/vt6656/usbpipe.c
+++ b/drivers/staging/vt6656/usbpipe.c
@@ -76,6 +76,23 @@ int vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 data)
 			       reg_off, reg, sizeof(u8), &data);
 }
 
+int vnt_control_out_blocks(struct vnt_private *priv,
+			   u16 block, u8 reg, u16 length, u8 *data)
+{
+	int ret = 0, i;
+
+	for (i = 0; i < length; i += block) {
+		u16 len = min_t(int, length - i, block);
+
+		ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE,
+				      i, reg, len, data + i);
+		if (ret)
+			goto end;
+	}
+end:
+	return ret;
+}
+
 int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
 		   u16 index, u16 length, u8 *buffer)
 {
diff --git a/drivers/staging/vt6656/usbpipe.h b/drivers/staging/vt6656/usbpipe.h
index 95147ec7b96a..b65d9c01a211 100644
--- a/drivers/staging/vt6656/usbpipe.h
+++ b/drivers/staging/vt6656/usbpipe.h
@@ -18,6 +18,8 @@
 
 #include "device.h"
 
+#define VNT_REG_BLOCK_SIZE	64
+
 int vnt_control_out(struct vnt_private *priv, u8 request, u16 value,
 		    u16 index, u16 length, u8 *buffer);
 int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
@@ -26,6 +28,9 @@ int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
 int vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 ref_off, u8 data);
 int vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data);
 
+int vnt_control_out_blocks(struct vnt_private *priv,
+			   u16 block, u8 reg, u16 len, u8 *data);
+
 int vnt_start_interrupt_urb(struct vnt_private *priv);
 int vnt_submit_rx_urb(struct vnt_private *priv, struct vnt_rcb *rcb);
 int vnt_tx_context(struct vnt_private *priv,
-- 
2.24.0
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH 3/5] staging: vt6656: limit reg output to block size
  2019-12-20 21:15 [PATCH 3/5] staging: vt6656: limit reg output to block size Malcolm Priestley
@ 2020-01-03 11:13 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2020-01-03 11:13 UTC (permalink / raw)
  To: Malcolm Priestley; +Cc: devel, Greg Kroah-Hartman

On Fri, Dec 20, 2019 at 09:15:24PM +0000, Malcolm Priestley wrote:
> vnt_control_out appears to fail when BBREG is greater than 64 writes.
> 
> Create new function that will relay an array in no larger than
> the indicated block size.
> 
> It appears that this command has always failed but was ignored by
> driver until the introduction of error checking.
> 
> Cc: stable <stable@vger.kernel.org> # v5.3+

Please add the Fixes tag.

> Signed-off-by: Malcolm Priestley <tvboxspy@gmail.com>
> ---
>  drivers/staging/vt6656/baseband.c |  4 ++--
>  drivers/staging/vt6656/usbpipe.c  | 17 +++++++++++++++++
>  drivers/staging/vt6656/usbpipe.h  |  5 +++++
>  3 files changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c
> index 8d19ae71e7cc..4e651b698617 100644
> --- a/drivers/staging/vt6656/baseband.c
> +++ b/drivers/staging/vt6656/baseband.c
> @@ -449,8 +449,8 @@ int vnt_vt3184_init(struct vnt_private *priv)
>  
>  	memcpy(array, addr, length);
>  
> -	ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
> -			      MESSAGE_REQUEST_BBREG, length, array);
> +	ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE,
> +				     MESSAGE_REQUEST_BBREG, length, array);
>  	if (ret)
>  		goto end;
>  
> diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c
> index 488ebd98773d..d977d4777e4f 100644
> --- a/drivers/staging/vt6656/usbpipe.c
> +++ b/drivers/staging/vt6656/usbpipe.c
> @@ -76,6 +76,23 @@ int vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 data)
>  			       reg_off, reg, sizeof(u8), &data);
>  }
>  
> +int vnt_control_out_blocks(struct vnt_private *priv,
> +			   u16 block, u8 reg, u16 length, u8 *data)
> +{
> +	int ret = 0, i;
> +
> +	for (i = 0; i < length; i += block) {
> +		u16 len = min_t(int, length - i, block);
> +
> +		ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE,
> +				      i, reg, len, data + i);
> +		if (ret)
> +			goto end;
> +	}
> +end:
> +	return ret;

Just do a direct return.  Goto end is pointless.  It hurts readability
because with direct returns we can immediately see that this returns
zero on success.

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

end of thread, other threads:[~2020-01-03 11:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-20 21:15 [PATCH 3/5] staging: vt6656: limit reg output to block size Malcolm Priestley
2020-01-03 11:13 ` Dan Carpenter

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