* [PATCH] staging: gdm724x: Fix DMA from stack
@ 2021-02-09 14:54 ameynarkhede03
2021-02-09 17:22 ` kernel test robot
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: ameynarkhede03 @ 2021-02-09 14:54 UTC (permalink / raw)
To: gregkh; +Cc: devel, linux-kernel, Amey Narkhede
From: Amey Narkhede <ameynarkhede03@gmail.com>
Stack allocated buffers cannot be used for DMA
on all architectures so allocate usbdev buffer
using kmalloc().
Signed-off-by: Amey Narkhede <ameynarkhede03@gmail.com>
---
drivers/staging/gdm724x/gdm_usb.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/gdm724x/gdm_usb.c b/drivers/staging/gdm724x/gdm_usb.c
index dc4da66c3..50dc463d4 100644
--- a/drivers/staging/gdm724x/gdm_usb.c
+++ b/drivers/staging/gdm724x/gdm_usb.c
@@ -56,7 +56,7 @@ static int gdm_usb_recv(void *priv_dev,
static int request_mac_address(struct lte_udev *udev)
{
- u8 buf[16] = {0,};
+ u8 *buf;
struct hci_packet *hci = (struct hci_packet *)buf;
struct usb_device *usbdev = udev->usbdev;
int actual;
@@ -66,6 +66,10 @@ static int request_mac_address(struct lte_udev *udev)
hci->len = gdm_cpu_to_dev16(udev->gdm_ed, 1);
hci->data[0] = MAC_ADDRESS;
+ buf = kmalloc(16, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
ret = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 2), buf, 5,
&actual, 1000);
--
2.30.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: gdm724x: Fix DMA from stack
2021-02-09 14:54 [PATCH] staging: gdm724x: Fix DMA from stack ameynarkhede03
@ 2021-02-09 17:22 ` kernel test robot
2021-02-09 17:40 ` Greg KH
2021-02-09 18:19 ` Dan Carpenter
2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-02-09 17:22 UTC (permalink / raw)
To: ameynarkhede03, gregkh; +Cc: kbuild-all, devel, Amey Narkhede, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 4848 bytes --]
Hi,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on staging/staging-testing]
url: https://github.com/0day-ci/linux/commits/ameynarkhede03-gmail-com/staging-gdm724x-Fix-DMA-from-stack/20210209-225530
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 06b0c0dce88e2aa2f01343db0f26d214d7f264a0
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/d793f4f05736924fc2207a0f8c338115523930da
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review ameynarkhede03-gmail-com/staging-gdm724x-Fix-DMA-from-stack/20210209-225530
git checkout d793f4f05736924fc2207a0f8c338115523930da
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
In file included from include/linux/kernel.h:10,
from include/linux/list.h:9,
from include/linux/module.h:12,
from drivers/staging/gdm724x/gdm_usb.c:6:
include/linux/scatterlist.h: In function 'sg_set_buf':
arch/m68k/include/asm/page_mm.h:174:49: warning: ordered comparison of pointer with null pointer [-Wextra]
174 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:137:2: note: in expansion of macro 'BUG_ON'
137 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:137:10: note: in expansion of macro 'virt_addr_valid'
137 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
drivers/staging/gdm724x/gdm_usb.c: In function 'request_mac_address':
>> drivers/staging/gdm724x/gdm_usb.c:60:21: warning: 'buf' is used uninitialized in this function [-Wuninitialized]
60 | struct hci_packet *hci = (struct hci_packet *)buf;
| ^~~
vim +/buf +60 drivers/staging/gdm724x/gdm_usb.c
61e12104764512 Won Kang 2013-07-25 50
61e12104764512 Won Kang 2013-07-25 51 static int gdm_usb_recv(void *priv_dev,
35db0350c5ef0d Aybuke Ozdemir 2014-03-14 52 int (*cb)(void *cb_data,
35db0350c5ef0d Aybuke Ozdemir 2014-03-14 53 void *data, int len, int context),
61e12104764512 Won Kang 2013-07-25 54 void *cb_data,
61e12104764512 Won Kang 2013-07-25 55 int context);
61e12104764512 Won Kang 2013-07-25 56
61e12104764512 Won Kang 2013-07-25 57 static int request_mac_address(struct lte_udev *udev)
61e12104764512 Won Kang 2013-07-25 58 {
d793f4f0573692 Amey Narkhede 2021-02-09 59 u8 *buf;
61e12104764512 Won Kang 2013-07-25 @60 struct hci_packet *hci = (struct hci_packet *)buf;
61e12104764512 Won Kang 2013-07-25 61 struct usb_device *usbdev = udev->usbdev;
61e12104764512 Won Kang 2013-07-25 62 int actual;
61e12104764512 Won Kang 2013-07-25 63 int ret = -1;
61e12104764512 Won Kang 2013-07-25 64
1b5e56ece3f501 Quytelda Kahja 2018-02-22 65 hci->cmd_evt = gdm_cpu_to_dev16(udev->gdm_ed, LTE_GET_INFORMATION);
1b5e56ece3f501 Quytelda Kahja 2018-02-22 66 hci->len = gdm_cpu_to_dev16(udev->gdm_ed, 1);
61e12104764512 Won Kang 2013-07-25 67 hci->data[0] = MAC_ADDRESS;
61e12104764512 Won Kang 2013-07-25 68
d793f4f0573692 Amey Narkhede 2021-02-09 69 buf = kmalloc(16, GFP_KERNEL);
d793f4f0573692 Amey Narkhede 2021-02-09 70 if (!buf)
d793f4f0573692 Amey Narkhede 2021-02-09 71 return -ENOMEM;
d793f4f0573692 Amey Narkhede 2021-02-09 72
61e12104764512 Won Kang 2013-07-25 73 ret = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 2), buf, 5,
61e12104764512 Won Kang 2013-07-25 74 &actual, 1000);
61e12104764512 Won Kang 2013-07-25 75
61e12104764512 Won Kang 2013-07-25 76 udev->request_mac_addr = 1;
61e12104764512 Won Kang 2013-07-25 77
61e12104764512 Won Kang 2013-07-25 78 return ret;
61e12104764512 Won Kang 2013-07-25 79 }
61e12104764512 Won Kang 2013-07-25 80
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 59644 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: gdm724x: Fix DMA from stack
2021-02-09 14:54 [PATCH] staging: gdm724x: Fix DMA from stack ameynarkhede03
2021-02-09 17:22 ` kernel test robot
@ 2021-02-09 17:40 ` Greg KH
2021-02-09 19:35 ` Amey Narkhede
2021-02-09 18:19 ` Dan Carpenter
2 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2021-02-09 17:40 UTC (permalink / raw)
To: ameynarkhede03; +Cc: devel, linux-kernel
On Tue, Feb 09, 2021 at 08:24:15PM +0530, ameynarkhede03@gmail.com wrote:
> From: Amey Narkhede <ameynarkhede03@gmail.com>
>
> Stack allocated buffers cannot be used for DMA
> on all architectures so allocate usbdev buffer
> using kmalloc().
>
> Signed-off-by: Amey Narkhede <ameynarkhede03@gmail.com>
> ---
> drivers/staging/gdm724x/gdm_usb.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/gdm724x/gdm_usb.c b/drivers/staging/gdm724x/gdm_usb.c
> index dc4da66c3..50dc463d4 100644
> --- a/drivers/staging/gdm724x/gdm_usb.c
> +++ b/drivers/staging/gdm724x/gdm_usb.c
> @@ -56,7 +56,7 @@ static int gdm_usb_recv(void *priv_dev,
>
> static int request_mac_address(struct lte_udev *udev)
> {
> - u8 buf[16] = {0,};
> + u8 *buf;
> struct hci_packet *hci = (struct hci_packet *)buf;
> struct usb_device *usbdev = udev->usbdev;
> int actual;
> @@ -66,6 +66,10 @@ static int request_mac_address(struct lte_udev *udev)
> hci->len = gdm_cpu_to_dev16(udev->gdm_ed, 1);
> hci->data[0] = MAC_ADDRESS;
>
> + buf = kmalloc(16, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
This is great, but you just added a build warning, which implies that
the patch is incorrect.
You also have a memory leak here, which is not acceptable :(
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: gdm724x: Fix DMA from stack
2021-02-09 14:54 [PATCH] staging: gdm724x: Fix DMA from stack ameynarkhede03
2021-02-09 17:22 ` kernel test robot
2021-02-09 17:40 ` Greg KH
@ 2021-02-09 18:19 ` Dan Carpenter
2 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2021-02-09 18:19 UTC (permalink / raw)
To: ameynarkhede03; +Cc: gregkh, devel, linux-kernel
On Tue, Feb 09, 2021 at 08:24:15PM +0530, ameynarkhede03@gmail.com wrote:
> From: Amey Narkhede <ameynarkhede03@gmail.com>
>
> Stack allocated buffers cannot be used for DMA
> on all architectures so allocate usbdev buffer
> using kmalloc().
>
> Signed-off-by: Amey Narkhede <ameynarkhede03@gmail.com>
> ---
> drivers/staging/gdm724x/gdm_usb.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/gdm724x/gdm_usb.c b/drivers/staging/gdm724x/gdm_usb.c
> index dc4da66c3..50dc463d4 100644
> --- a/drivers/staging/gdm724x/gdm_usb.c
> +++ b/drivers/staging/gdm724x/gdm_usb.c
> @@ -56,7 +56,7 @@ static int gdm_usb_recv(void *priv_dev,
>
> static int request_mac_address(struct lte_udev *udev)
> {
> - u8 buf[16] = {0,};
> + u8 *buf;
> struct hci_packet *hci = (struct hci_packet *)buf;
> struct usb_device *usbdev = udev->usbdev;
> int actual;
> @@ -66,6 +66,10 @@ static int request_mac_address(struct lte_udev *udev)
> hci->len = gdm_cpu_to_dev16(udev->gdm_ed, 1);
> hci->data[0] = MAC_ADDRESS;
>
> + buf = kmalloc(16, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
> ret = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 2), buf, 5,
> &actual, 1000);
You need to add a kfree() as well.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: gdm724x: Fix DMA from stack
2021-02-09 17:40 ` Greg KH
@ 2021-02-09 19:35 ` Amey Narkhede
0 siblings, 0 replies; 5+ messages in thread
From: Amey Narkhede @ 2021-02-09 19:35 UTC (permalink / raw)
To: Greg KH; +Cc: devel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1454 bytes --]
On 21/02/09 06:40PM, Greg KH wrote:
> On Tue, Feb 09, 2021 at 08:24:15PM +0530, ameynarkhede03@gmail.com wrote:
> > From: Amey Narkhede <ameynarkhede03@gmail.com>
> >
> > Stack allocated buffers cannot be used for DMA
> > on all architectures so allocate usbdev buffer
> > using kmalloc().
> >
> > Signed-off-by: Amey Narkhede <ameynarkhede03@gmail.com>
> > ---
> > drivers/staging/gdm724x/gdm_usb.c | 6 +++++-
> > 1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/gdm724x/gdm_usb.c b/drivers/staging/gdm724x/gdm_usb.c
> > index dc4da66c3..50dc463d4 100644
> > --- a/drivers/staging/gdm724x/gdm_usb.c
> > +++ b/drivers/staging/gdm724x/gdm_usb.c
> > @@ -56,7 +56,7 @@ static int gdm_usb_recv(void *priv_dev,
> >
> > static int request_mac_address(struct lte_udev *udev)
> > {
> > - u8 buf[16] = {0,};
> > + u8 *buf;
> > struct hci_packet *hci = (struct hci_packet *)buf;
> > struct usb_device *usbdev = udev->usbdev;
> > int actual;
> > @@ -66,6 +66,10 @@ static int request_mac_address(struct lte_udev *udev)
> > hci->len = gdm_cpu_to_dev16(udev->gdm_ed, 1);
> > hci->data[0] = MAC_ADDRESS;
> >
> > + buf = kmalloc(16, GFP_KERNEL);
> > + if (!buf)
> > + return -ENOMEM;
> > +
>
> This is great, but you just added a build warning, which implies that
> the patch is incorrect.
>
> You also have a memory leak here, which is not acceptable :(
>
> thanks,
>
> greg k-h
Apologoes. I'll send v2.
Thanks,
Amey
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-02-09 23:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 14:54 [PATCH] staging: gdm724x: Fix DMA from stack ameynarkhede03
2021-02-09 17:22 ` kernel test robot
2021-02-09 17:40 ` Greg KH
2021-02-09 19:35 ` Amey Narkhede
2021-02-09 18:19 ` Dan Carpenter
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).