staging: comedi: drivers: usbduxsigma.c: fix DMA buffers on stack
Subsystems (2)
PATCH v2 1/1 staging: comedi: drivers: usbduxsigma.c: fix DMA buffers on stack
This patch fixes an instance of DMA buffer on stack(being passed to usb_control_msg)for the USB-DUXsigma Board driver. Found using smatch.
--- drivers/staging/comedi/drivers/usbduxsigma.c | 27 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
drivers/staging/comedi/drivers/usbduxsigma.c +17 -10
@@ -681,7 +681,11 @@ static void usbduxsub_ao_IsocIrq(struct urb *urb)static int usbduxsub_start (struct usbduxsub *usbduxsub) {int errcode =0 ; -uint8_t local_transfer_buffer[16 ]; +uint8_t *local_transfer_buffer; + + local_transfer_buffer =kmalloc (16 ,GFP_KERNEL ); +if (!local_transfer_buffer) +return -ENOMEM ;/* 7f92 to zero */ local_transfer_buffer[0 ] =0 ;
@@ -702,19 +706,22 @@ static int usbduxsub_start(struct usbduxsub *usbduxsub)1 ,/* Timeout */ BULK_TIMEOUT); -if (errcode <0 ) { +if (errcode <0 )dev_err (&usbduxsub->interface->dev,"comedi_: control msg failed (start)\n" ); -return errcode; - } -return 0 ; + +kfree (local_transfer_buffer); +return errcode; }static int usbduxsub_stop (struct usbduxsub *usbduxsub) {int errcode =0 ; +uint8_t *local_transfer_buffer; -uint8_t local_transfer_buffer[16 ]; + local_transfer_buffer =kmalloc (16 ,GFP_KERNEL ); +if (!local_transfer_buffer) +return -ENOMEM ;/* 7f92 to one */ local_transfer_buffer[0 ] =1 ;
@@ -732,12 +739,12 @@ static int usbduxsub_stop(struct usbduxsub *usbduxsub)1 ,/* Timeout */ BULK_TIMEOUT); -if (errcode <0 ) { +if (errcode <0 )dev_err (&usbduxsub->interface->dev,"comedi_: control msg failed (stop)\n" ); -return errcode; - } -return 0 ; + +kfree (local_transfer_buffer); +return errcode; } static int usbduxsub_upload(struct usbduxsub *usbduxsub,
Signature · 1 line
1.7.9.5
Quoted 3 lines · Kumar Amit Mehta
This patch fixes an instance of DMA buffer on
stack(being passed to usb_control_msg)for the USB-DUXsigma Board driver. Found using smatch.
Looks good here too.
Would you mind doing the same for usbdux.c and usbduxfast.c?
Signature · 2 lines
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=- -=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-
Quoted 10 lines · Ian Abbott
Quoted 3 lines · Kumar Amit Mehta
This patch fixes an instance of DMA buffer on
stack(being passed to usb_control_msg)for the USB-DUXsigma Board driver. Found using smatch.Looks good here too.
Reviewed-by Ian Abbott <[email protected]>Would you mind doing the same for
usbdux.candusbduxfast.c?
Sure.
As pointed out by Dan, Do you really want the buffer to be of 16 bytes, as we are using only the first byte and passing the length as '1' in:usbduxsub_start, usbduxsub_stop, usbduxfastsub_start, usbduxfastsub_stop ?
~Amit
Quoted 8 lines · Kumar amit mehta
Quoted 7 lines · Ian Abbott
Quoted 3 lines · Kumar Amit Mehta
This patch fixes an instance of DMA buffer on
stack(being passed to usb_control_msg)for the USB-DUXsigma Board driver. Found using smatch.Looks good here too.
Quoted 7 lines
Quoted 3 lines
Reviewed-by Ian Abbott <[email protected]>Would you mind doing the same for
usbdux.candusbduxfast.c?Sure.
As pointed out by Dan, Do you really want the buffer to be of 16 bytes, as we are using only the first byte and passing the length as '1' in:usbduxsub_start,usbduxsub_stop,usbduxfastsub_start,usbduxfastsub_stop?
A buffer size of 1 should be fine.
Signature · 2 lines
-=( Ian Abbott @ MEV Ltd. E-mail: <[email protected]> )=- -=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-