ath3k: don't use stack memory for DMA
PATCH 1/1 ath3k: don't use stack memory for DMA
Memory allocated by vmalloc (including stack) can not be used for DMA, i.e. data pointer on usb_control_msg() should not point to stack memory.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=977558
--- drivers/bluetooth/ath3k.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-)
drivers/bluetooth/ath3k.c +29 -9
@@ -193,24 +193,44 @@ error:static int ath3k_get_state (struct usb_device *udev,unsigned char *state) { -int pipe =0 ; +int ret, pipe =0 ; +char *buf; + + buf =kmalloc (1 ,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; pipe =usb_rcvctrlpipe (udev,0 ); -return usb_control_msg (udev, pipe,ATH3K_GETSTATE , -USB_TYPE_VENDOR |USB_DIR_IN ,0 ,0 , - state,0x01 ,USB_CTRL_SET_TIMEOUT ); + ret =usb_control_msg (udev, pipe,ATH3K_GETSTATE , +USB_TYPE_VENDOR |USB_DIR_IN ,0 ,0 , + buf,1 ,USB_CTRL_SET_TIMEOUT ); + + *state = *buf; +kfree (buf); + +return ret; }static int ath3k_get_version (struct usb_device *udev,struct ath3k_version *version) { -int pipe =0 ; +int ret, pipe =0 ; +char *buf; +const int size =sizeof (struct ath3k_version ); + + buf =kmalloc (size,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; pipe =usb_rcvctrlpipe (udev,0 ); -return usb_control_msg (udev, pipe,ATH3K_GETVERSION , -USB_TYPE_VENDOR |USB_DIR_IN ,0 ,0 , version, -sizeof (struct ath3k_version ), -USB_CTRL_SET_TIMEOUT ); + ret =usb_control_msg (udev, pipe,ATH3K_GETVERSION , +USB_TYPE_VENDOR |USB_DIR_IN ,0 ,0 , + buf, size,USB_CTRL_SET_TIMEOUT ); + +memcpy (version, buf, size); +kfree (buf); + +return ret; } static int ath3k_load_fwfile(struct usb_device *udev,
Signature · 1 line
1.7.11.7
Hi Stanislaw,
Quoted 17 lines · Stanislaw Gruszka
Memory allocated by vmalloc (including stack) can not be used for DMA, i.e. data pointer on
usb_control_msg()should not point to stack memory.Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=977558Reported-and-tested-by Andy Lawrence <[email protected]>Signed-off-by Stanislaw Gruszka <[email protected]>--- drivers/bluetooth/ath3k.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-)drivers/bluetooth/ath3k.c +0
-0
drivers/bluetooth/ath3k.c error: · line 199
Quoted 8 lines
drivers/bluetooth/ath3k.c +4
-1@@ -193,24 +193,44 @@ error:static int ath3k_get_state (struct usb_device *udev,unsigned char *state) { -int pipe =0 ; +int ret, pipe =0 ; +char *buf; + + buf =kmalloc (1 ,GFP_KERNEL );
Can we make this:
buf = kmalloc(sizeof(*buf), GFP_KERNEL);
drivers/bluetooth/ath3k.c error: · line 206
Quoted 10 lines
drivers/bluetooth/ath3k.c +5
-3+if (!buf) +return -ENOMEM ; pipe =usb_rcvctrlpipe (udev,0 ); -return usb_control_msg (udev, pipe,ATH3K_GETSTATE , -USB_TYPE_VENDOR |USB_DIR_IN ,0 ,0 , - state,0x01 ,USB_CTRL_SET_TIMEOUT ); + ret =usb_control_msg (udev, pipe,ATH3K_GETSTATE , +USB_TYPE_VENDOR |USB_DIR_IN ,0 ,0 , + buf,1 ,USB_CTRL_SET_TIMEOUT );
sizeof(*buf) instead of "1"
drivers/bluetooth/ath3k.c error: · line 218
Quoted 13 lines
drivers/bluetooth/ath3k.c +7
-1+ + *state = *buf; +kfree (buf); + +return ret; }static int ath3k_get_version (struct usb_device *udev,struct ath3k_version *version) { -int pipe =0 ; +int ret, pipe =0 ; +char *buf;
this should be struct ath3k_version *buf;
drivers/bluetooth/ath3k.c error: · line 219
Quoted 1 line
drivers/bluetooth/ath3k.c +1
-0+const int size =sizeof (struct ath3k_version );
and here sizeof(*buf);
Gustavo
PATCH v2 1/1 ath3k: don't use stack memory for DMA
Memory allocated by vmalloc (including stack) can not be used for DMA, i.e. data pointer on usb_control_msg() should not point to stack memory.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=977558
--- drivers/bluetooth/ath3k.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-)
v1 -> v2 : use sizeof(*buf)
drivers/bluetooth/ath3k.c +29 -9
@@ -193,24 +193,44 @@ error:static int ath3k_get_state (struct usb_device *udev,unsigned char *state) { -int pipe =0 ; +int ret, pipe =0 ; +char *buf; + + buf =kmalloc (sizeof (*buf),GFP_KERNEL ); +if (!buf) +return -ENOMEM ; pipe =usb_rcvctrlpipe (udev,0 ); -return usb_control_msg (udev, pipe,ATH3K_GETSTATE , -USB_TYPE_VENDOR |USB_DIR_IN ,0 ,0 , - state,0x01 ,USB_CTRL_SET_TIMEOUT ); + ret =usb_control_msg (udev, pipe,ATH3K_GETSTATE , +USB_TYPE_VENDOR |USB_DIR_IN ,0 ,0 , + buf,sizeof (*buf),USB_CTRL_SET_TIMEOUT ); + + *state = *buf; +kfree (buf); + +return ret; }static int ath3k_get_version (struct usb_device *udev,struct ath3k_version *version) { -int pipe =0 ; +int ret, pipe =0 ; +struct ath3k_version *buf; +const int size =sizeof (*buf); + + buf =kmalloc (size,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; pipe =usb_rcvctrlpipe (udev,0 ); -return usb_control_msg (udev, pipe,ATH3K_GETVERSION , -USB_TYPE_VENDOR |USB_DIR_IN ,0 ,0 , version, -sizeof (struct ath3k_version ), -USB_CTRL_SET_TIMEOUT ); + ret =usb_control_msg (udev, pipe,ATH3K_GETVERSION , +USB_TYPE_VENDOR |USB_DIR_IN ,0 ,0 , + buf, size,USB_CTRL_SET_TIMEOUT ); + +memcpy (version, buf, size); +kfree (buf); + +return ret; } static int ath3k_load_fwfile(struct usb_device *udev,
Hi Stanislaw,
Quoted 11 lines · Stanislaw Gruszka
Memory allocated by vmalloc (including stack) can not be used for DMA, i.e. data pointer on
usb_control_msg()should not point to stack memory.Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=977558Reported-and-tested-by Andy Lawrence <[email protected]>Signed-off-by Stanislaw Gruszka <[email protected]>--- drivers/bluetooth/ath3k.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-)
Patch has been applied to bluetooth-next. Thanks.
Gustavo