diff mbox series

imon_raw: respect DMA coherency

Message ID 20220512130321.30599-1-oneukum@suse.com
State New
Headers show
Series imon_raw: respect DMA coherency | expand

Commit Message

Oliver Neukum May 12, 2022, 1:03 p.m. UTC
No buffer can be embedded inside a descriptor, not even a simple be64.
Use a separate kmalloc()

Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/media/rc/imon_raw.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Sean Young May 13, 2022, 4:23 p.m. UTC | #1
On Thu, May 12, 2022 at 03:03:21PM +0200, Oliver Neukum wrote:
> No buffer can be embedded inside a descriptor, not even a simple be64.
> Use a separate kmalloc()

This patch needs a tiny change from be64_to_cpu() to be64_to_cpup(), I've
tested that change with the hardware.

Applied to my tree:

https://git.linuxtv.org/syoung/media_tree.git/log/?h=for-v5.20a

Thanks,

Sean

> 
> Signed-off-by: Oliver Neukum <oneukum@suse.com>
> ---
>  drivers/media/rc/imon_raw.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/rc/imon_raw.c b/drivers/media/rc/imon_raw.c
> index d41580f6e4c7..b7a0c0b34378 100644
> --- a/drivers/media/rc/imon_raw.c
> +++ b/drivers/media/rc/imon_raw.c
> @@ -14,7 +14,7 @@ struct imon {
>  	struct device *dev;
>  	struct urb *ir_urb;
>  	struct rc_dev *rcdev;
> -	__be64 ir_buf;
> +	__be64 *ir_buf;
>  	char phys[64];
>  };
>  
> @@ -137,10 +137,16 @@ static int imon_probe(struct usb_interface *intf,
>  	if (!imon->ir_urb)
>  		return -ENOMEM;
>  
> +	imon->ir_buf = kmalloc(sizeof(__be64), GFP_KERNEL);
> +	if (!imon->ir_buf) {
> +		ret = -ENOMEM;
> +		goto free_urb;
> +	}
> +
>  	imon->dev = &intf->dev;
>  	usb_fill_int_urb(imon->ir_urb, udev,
>  			 usb_rcvintpipe(udev, ir_ep->bEndpointAddress),
> -			 &imon->ir_buf, sizeof(imon->ir_buf),
> +			 imon->ir_buf, sizeof(__be64),
>  			 imon_ir_rx, imon, ir_ep->bInterval);
>  
>  	rcdev = devm_rc_allocate_device(&intf->dev, RC_DRIVER_IR_RAW);
> @@ -177,6 +183,7 @@ static int imon_probe(struct usb_interface *intf,
>  
>  free_urb:
>  	usb_free_urb(imon->ir_urb);
> +	kfree(imon->ir_buf);
>  	return ret;
>  }
>  
> @@ -186,6 +193,7 @@ static void imon_disconnect(struct usb_interface *intf)
>  
>  	usb_kill_urb(imon->ir_urb);
>  	usb_free_urb(imon->ir_urb);
> +	kfree(imon->ir_buf);
>  }
>  
>  static const struct usb_device_id imon_table[] = {
> -- 
> 2.35.3
Sean Young May 16, 2022, 4:40 p.m. UTC | #2
On Mon, May 16, 2022 at 01:00:30PM +0200, Oliver Neukum wrote:
> On 13.05.22 18:23, Sean Young wrote:
> Hi!
> > On Thu, May 12, 2022 at 03:03:21PM +0200, Oliver Neukum wrote:
> >> No buffer can be embedded inside a descriptor, not even a simple be64.
> >> Use a separate kmalloc()
> > This patch needs a tiny change from be64_to_cpu() to be64_to_cpup(), I've
> > tested that change with the hardware.
> Needs? It is certainly not wrong and the subsequent logging will be in the
> converted order, but need

It certainly is wrong, and it doesn't compile without it, so yes it does
need it. The kernel test robot also complained about.

Thanks

Sean
diff mbox series

Patch

diff --git a/drivers/media/rc/imon_raw.c b/drivers/media/rc/imon_raw.c
index d41580f6e4c7..b7a0c0b34378 100644
--- a/drivers/media/rc/imon_raw.c
+++ b/drivers/media/rc/imon_raw.c
@@ -14,7 +14,7 @@  struct imon {
 	struct device *dev;
 	struct urb *ir_urb;
 	struct rc_dev *rcdev;
-	__be64 ir_buf;
+	__be64 *ir_buf;
 	char phys[64];
 };
 
@@ -137,10 +137,16 @@  static int imon_probe(struct usb_interface *intf,
 	if (!imon->ir_urb)
 		return -ENOMEM;
 
+	imon->ir_buf = kmalloc(sizeof(__be64), GFP_KERNEL);
+	if (!imon->ir_buf) {
+		ret = -ENOMEM;
+		goto free_urb;
+	}
+
 	imon->dev = &intf->dev;
 	usb_fill_int_urb(imon->ir_urb, udev,
 			 usb_rcvintpipe(udev, ir_ep->bEndpointAddress),
-			 &imon->ir_buf, sizeof(imon->ir_buf),
+			 imon->ir_buf, sizeof(__be64),
 			 imon_ir_rx, imon, ir_ep->bInterval);
 
 	rcdev = devm_rc_allocate_device(&intf->dev, RC_DRIVER_IR_RAW);
@@ -177,6 +183,7 @@  static int imon_probe(struct usb_interface *intf,
 
 free_urb:
 	usb_free_urb(imon->ir_urb);
+	kfree(imon->ir_buf);
 	return ret;
 }
 
@@ -186,6 +193,7 @@  static void imon_disconnect(struct usb_interface *intf)
 
 	usb_kill_urb(imon->ir_urb);
 	usb_free_urb(imon->ir_urb);
+	kfree(imon->ir_buf);
 }
 
 static const struct usb_device_id imon_table[] = {