* [PATCH] ath3k: don't use stack memory for DMA
@ 2013-06-27 9:48 Stanislaw Gruszka
2013-07-07 19:40 ` Gustavo Padovan
0 siblings, 1 reply; 4+ messages in thread
From: Stanislaw Gruszka @ 2013-06-27 9:48 UTC (permalink / raw)
To: linux-bluetooth
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
Reported-and-tested-by: Andy Lawrence <dr.diesel@gmail.com>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
drivers/bluetooth/ath3k.c | 38 +++++++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 9 deletions(-)
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index 11f467c..81b636c 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -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,
--
1.7.11.7
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] ath3k: don't use stack memory for DMA
2013-06-27 9:48 [PATCH] ath3k: don't use stack memory for DMA Stanislaw Gruszka
@ 2013-07-07 19:40 ` Gustavo Padovan
2013-07-08 8:27 ` [PATCH v2] " Stanislaw Gruszka
0 siblings, 1 reply; 4+ messages in thread
From: Gustavo Padovan @ 2013-07-07 19:40 UTC (permalink / raw)
To: Stanislaw Gruszka; +Cc: linux-bluetooth
Hi Stanislaw,
* Stanislaw Gruszka <sgruszka@redhat.com> [2013-06-27 11:48:41 +0200]:
> 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
>
> Reported-and-tested-by: Andy Lawrence <dr.diesel@gmail.com>
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
> drivers/bluetooth/ath3k.c | 38 +++++++++++++++++++++++++++++---------
> 1 file changed, 29 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
> index 11f467c..81b636c 100644
> --- a/drivers/bluetooth/ath3k.c
> +++ b/drivers/bluetooth/ath3k.c
> @@ -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);
> + 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"
> +
> + *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;
> + const int size = sizeof(struct ath3k_version);
and here sizeof(*buf);
Gustavo
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2] ath3k: don't use stack memory for DMA
2013-07-07 19:40 ` Gustavo Padovan
@ 2013-07-08 8:27 ` Stanislaw Gruszka
2013-07-09 15:25 ` Gustavo Padovan
0 siblings, 1 reply; 4+ messages in thread
From: Stanislaw Gruszka @ 2013-07-08 8:27 UTC (permalink / raw)
To: Gustavo Padovan, linux-bluetooth
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
Reported-and-tested-by: Andy Lawrence <dr.diesel@gmail.com>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
drivers/bluetooth/ath3k.c | 38 +++++++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 9 deletions(-)
v1 -> v2 : use sizeof(*buf)
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index 11f467c..5e3a86f 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -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,
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] ath3k: don't use stack memory for DMA
2013-07-08 8:27 ` [PATCH v2] " Stanislaw Gruszka
@ 2013-07-09 15:25 ` Gustavo Padovan
0 siblings, 0 replies; 4+ messages in thread
From: Gustavo Padovan @ 2013-07-09 15:25 UTC (permalink / raw)
To: Stanislaw Gruszka; +Cc: linux-bluetooth
Hi Stanislaw,
* Stanislaw Gruszka <sgruszka@redhat.com> [2013-07-08 10:27:23 +0200]:
> 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
>
> Reported-and-tested-by: Andy Lawrence <dr.diesel@gmail.com>
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
> drivers/bluetooth/ath3k.c | 38 +++++++++++++++++++++++++++++---------
> 1 file changed, 29 insertions(+), 9 deletions(-)
Patch has been applied to bluetooth-next. Thanks.
Gustavo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-07-09 15:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-27 9:48 [PATCH] ath3k: don't use stack memory for DMA Stanislaw Gruszka
2013-07-07 19:40 ` Gustavo Padovan
2013-07-08 8:27 ` [PATCH v2] " Stanislaw Gruszka
2013-07-09 15:25 ` Gustavo Padovan
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).