Re: [PATCH 2/3] Staging: most: fix doing DMA on stack

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jul 30, 2015 at 03:31:38PM +0200, Christian Gromm wrote:
> This patch fixes error "doing DMA on the stack" by using kzalloc
> for buffer allocation.
> 
> Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
> Signed-off-by: Christian Gromm <christian.gromm@xxxxxxxxxxxxx>
> ---
>  drivers/staging/most/hdm-usb/hdm_usb.c |   39 +++++++++++++++++++++-----------
>  1 file changed, 26 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/staging/most/hdm-usb/hdm_usb.c b/drivers/staging/most/hdm-usb/hdm_usb.c
> index a4a3e26..9db31a2 100644
> --- a/drivers/staging/most/hdm-usb/hdm_usb.c
> +++ b/drivers/staging/most/hdm-usb/hdm_usb.c
> @@ -45,6 +45,7 @@
>  #define USB_VENDOR_ID_SMSC	0x0424  /* VID: SMSC */
>  #define USB_DEV_ID_BRDG		0xC001  /* PID: USB Bridge */
>  #define USB_DEV_ID_INIC		0xCF18  /* PID: USB INIC */
> +#define HW_RESYNC		0x0000
>  /* DRCI Addresses */
>  #define DRCI_REG_NI_STATE	0x0100
>  #define DRCI_REG_PACKET_BW	0x0101
> @@ -139,21 +140,33 @@ static void wq_netinfo(struct work_struct *wq_obj);
>   * trigger_resync_vr - Vendor request to trigger HW re-sync mechanism
>   * @dev: usb device
>   *
> + * Since some architectures don't allow DMA to the stack, we use
> + * kzalloc for buffer allocation.

No need to say this, it's a requirement for all USB drivers in Linux.

> + *
>   */
> -static inline void trigger_resync_vr(struct usb_device *dev)
> +static void trigger_resync_vr(struct usb_device *dev)
>  {
> -	int data = 0;
> -
> -	if (0 > usb_control_msg(dev,
> -				usb_sndctrlpipe(dev, 0),
> -				0,
> -				USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
> -				0,
> -				0,
> -				&data,
> -				0,
> -				5 * HZ))
> -		pr_info("Vendor request \"stall\" failed\n");
> +	int retval;
> +	u8 request_type = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
> +	int *data = kzalloc(sizeof(*data), GFP_KERNEL);
> +
> +	if (!data)
> +		goto error;
> +	*data = HW_RESYNC;
> +	retval = usb_control_msg(dev,
> +				 usb_sndctrlpipe(dev, 0),
> +				 0,
> +				 request_type,
> +				 0,
> +				 0,
> +				 data,
> +				 0,
> +				 5 * HZ);
> +	kfree(data);
> +	if (retval >= 0)
> +		return;
> +error:
> +	pr_info("Vendor request \"stall\" failed\n");

You have a device, so use 'dev_*' instead of pr_*.  And as this is an
error, use the *_err() version, so this should be a dev_err() call, not
pr_info().

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux