staging: gdm724x: Fix DMA from stack
PATCH v2 1/1 staging: gdm724x: Fix DMA from stack
Stack allocated buffers cannot be used for DMA on all architectures so allocate hci_packet buffer using kzalloc().
---
Changes in v2:
- Fixed build warning
- Fixed memory leak using kfree
drivers/staging/gdm724x/gdm_usb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/staging/gdm724x/gdm_usb.c +7 -2
@@ -56,11 +56,15 @@ static int gdm_usb_recv(void *priv_dev,static int request_mac_address (struct lte_udev *udev) { -u8 buf[16 ] = {0 ,}; -struct hci_packet *hci = (struct hci_packet *)buf; +u8 *buf; +struct hci_packet *hci;struct usb_device *usbdev = udev->usbdev;int actual;int ret =-1 ; + buf =kzalloc (16 ,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + hci = (struct hci_packet *)buf; hci->cmd_evt =gdm_cpu_to_dev16 (udev->gdm_ed,LTE_GET_INFORMATION ); hci->len =gdm_cpu_to_dev16 (udev->gdm_ed,1 );
@@ -70,6 +74,7 @@ static int request_mac_address(struct lte_udev *udev) &actual, 1000); udev->request_mac_addr =1 ; +kfree (buf);return ret; }
--
2.30.0
Greg KH
maintainerQuoted 19 lines · Amey Narkhede
Stack allocated buffers cannot be used for DMA on all architectures so allocate
hci_packetbuffer usingkzalloc().Signed-off-by Amey Narkhede <[email protected]>---
Changes in v2:
- Fixed build warning
- Fixed memory leak using kfreedrivers/staging/gdm724x/gdm_usb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/staging/gdm724x/gdm_usb.c +0
-0@@ -56,11 +56,15 @@ static int gdm_usb_recv(void *priv_dev,
drivers/staging/gdm724x/gdm_usb.c static int gdm_usb_recv(void *priv_dev, · line 64
Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c +3
-2static int request_mac_address (struct lte_udev *udev) { -u8 buf[16 ] = {0 ,}; -struct hci_packet *hci = (struct hci_packet *)buf; +u8 *buf; +struct hci_packet *hci;struct usb_device *usbdev = udev->usbdev;int actual;int ret =-1 ; + buf =kzalloc (16 ,GFP_KERNEL );
checkpatch did not complain about this?
And why do you need 'buf' anymore now? Why not just allocate hci and pass that to the request instead? Saves you an extra cast and an extra pointer.
thanks,
greg k-h
Quoted 20 lines · Greg KH
Quoted 19 lines · Amey Narkhede
Stack allocated buffers cannot be used for DMA on all architectures so allocate
hci_packetbuffer usingkzalloc().Signed-off-by Amey Narkhede <[email protected]>---
Changes in v2:
- Fixed build warning
- Fixed memory leak using kfreedrivers/staging/gdm724x/gdm_usb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/staging/gdm724x/gdm_usb.c +0
-0@@ -56,11 +56,15 @@ static int gdm_usb_recv(void *priv_dev,
Quoted 12 lines
drivers/staging/gdm724x/gdm_usb.c static int gdm_usb_recv(void *priv_dev, · line 64
Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c +3
-2static int request_mac_address (struct lte_udev *udev) { -u8 buf[16 ] = {0 ,}; -struct hci_packet *hci = (struct hci_packet *)buf; +u8 *buf; +struct hci_packet *hci;struct usb_device *usbdev = udev->usbdev;int actual;int ret =-1 ; + buf =kzalloc (16 ,GFP_KERNEL );checkpatch did not complain about this?
No. checkpatch shows no errors and warnings.
Quoted 8 lines
And why do you need 'buf' anymore now? Why not just allocate hci and pass that to the request instead? Saves you an extra cast and an extra pointer.
thanks,
greg k-h
Thanks. I'll send v3. I assume now we don't need kzalloc anymore as we initialize the hci_packet so kmalloc(sizeof(struct hci_packet),..) will do.
Amey
Quoted 39 lines · Amey Narkhede
Quoted 20 lines · Greg KH
Quoted 19 lines · Amey Narkhede
Stack allocated buffers cannot be used for DMA on all architectures so allocate
hci_packetbuffer usingkzalloc().Signed-off-by Amey Narkhede <[email protected]>---
Changes in v2:
- Fixed build warning
- Fixed memory leak using kfreedrivers/staging/gdm724x/gdm_usb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/staging/gdm724x/gdm_usb.c +0
-0@@ -56,11 +56,15 @@ static int gdm_usb_recv(void *priv_dev,Quoted 12 lines
drivers/staging/gdm724x/gdm_usb.c static int gdm_usb_recv(void *priv_dev, · line 64
Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c +3
-2static int request_mac_address (struct lte_udev *udev) { -u8 buf[16 ] = {0 ,}; -struct hci_packet *hci = (struct hci_packet *)buf; +u8 *buf; +struct hci_packet *hci;struct usb_device *usbdev = udev->usbdev;int actual;int ret =-1 ; + buf =kzalloc (16 ,GFP_KERNEL );checkpatch did not complain about this?
No. checkpatch shows no errors and warnings.
Quoted 5 lines
And why do you need 'buf' anymore now? Why not just allocate hci and pass that to the request instead? Saves you an extra cast and an extra pointer.
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
Thanks. I'll send v3. I assume now we don't need kzalloc anymore as we initialize the
hci_packetsokmalloc(sizeof(struct hci_packet),..)will do.
We only initialize the first five bytes, but it also seems as if we only use the first five bytes which raises the question of why we are allocating 16 bytes.
regards,
dan carpenter
Greg KH
maintainerQuoted 33 lines · Amey Narkhede
Quoted 20 lines · Greg KH
Quoted 19 lines · Amey Narkhede
Stack allocated buffers cannot be used for DMA on all architectures so allocate
hci_packetbuffer usingkzalloc().Signed-off-by Amey Narkhede <[email protected]>---
Changes in v2:
- Fixed build warning
- Fixed memory leak using kfreedrivers/staging/gdm724x/gdm_usb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/staging/gdm724x/gdm_usb.c +0
-0@@ -56,11 +56,15 @@ static int gdm_usb_recv(void *priv_dev,Quoted 12 lines
drivers/staging/gdm724x/gdm_usb.c static int gdm_usb_recv(void *priv_dev, · line 64
Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c +3
-2static int request_mac_address (struct lte_udev *udev) { -u8 buf[16 ] = {0 ,}; -struct hci_packet *hci = (struct hci_packet *)buf; +u8 *buf; +struct hci_packet *hci;struct usb_device *usbdev = udev->usbdev;int actual;int ret =-1 ; + buf =kzalloc (16 ,GFP_KERNEL );checkpatch did not complain about this?
Quoted 1 line
No. checkpatch shows no errors and warnings.
Please add a blank line after variables and before logic.
Quoted 9 lines
Quoted 7 lines
And why do you need 'buf' anymore now? Why not just allocate hci and pass that to the request instead? Saves you an extra cast and an extra pointer.
thanks,
greg k-h
Thanks. I'll send v3. I assume now we don't need kzalloc anymore as we initialize the
hci_packetsokmalloc(sizeof(struct hci_packet),..)will do.
Why is it needed now? And why would that change?
thanks,
greg k-h
Quoted 46 lines · Dan Carpenter
Quoted 39 lines · Amey Narkhede
Quoted 20 lines · Greg KH
Quoted 19 lines · Amey Narkhede
Stack allocated buffers cannot be used for DMA on all architectures so allocate
hci_packetbuffer usingkzalloc().Signed-off-by Amey Narkhede <[email protected]>---
Changes in v2:
- Fixed build warning
- Fixed memory leak using kfreedrivers/staging/gdm724x/gdm_usb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/staging/gdm724x/gdm_usb.c +0
-0@@ -56,11 +56,15 @@ static int gdm_usb_recv(void *priv_dev,Quoted 12 lines
drivers/staging/gdm724x/gdm_usb.c static int gdm_usb_recv(void *priv_dev, · line 64
Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c +3
-2static int request_mac_address (struct lte_udev *udev) { -u8 buf[16 ] = {0 ,}; -struct hci_packet *hci = (struct hci_packet *)buf; +u8 *buf; +struct hci_packet *hci;struct usb_device *usbdev = udev->usbdev;int actual;int ret =-1 ; + buf =kzalloc (16 ,GFP_KERNEL );checkpatch did not complain about this?
No. checkpatch shows no errors and warnings.
Quoted 5 lines
And why do you need 'buf' anymore now? Why not just allocate hci and pass that to the request instead? Saves you an extra cast and an extra pointer.
Quoted 5 lines
Quoted 3 lines
thanks,
greg k-h
Thanks. I'll send v3. I assume now we don't need kzalloc anymore as we initialize the
hci_packetsokmalloc(sizeof(struct hci_packet),..)will do.
Quoted 7 lines
We only initialize the first five bytes, but it also seems as if we only use the first five bytes which raises the question of why we are allocating 16 bytes.
regards,
dan carpenter
That makes sense. I kept 16 bytes as original implementation allocated 16 bytes on stack.
Thanks,
Amey
Quoted 34 lines · Greg KH
Quoted 33 lines · Amey Narkhede
Quoted 32 lines · Greg KH
Quoted 19 lines · Amey Narkhede
Stack allocated buffers cannot be used for DMA on all architectures so allocate
hci_packetbuffer usingkzalloc().Signed-off-by Amey Narkhede <[email protected]>---
Changes in v2:
- Fixed build warning
- Fixed memory leak using kfreedrivers/staging/gdm724x/gdm_usb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/staging/gdm724x/gdm_usb.c +0
-0@@ -56,11 +56,15 @@ static int gdm_usb_recv(void *priv_dev,drivers/staging/gdm724x/gdm_usb.c static int gdm_usb_recv(void *priv_dev, · line 64
Quoted 10 lines
drivers/staging/gdm724x/gdm_usb.c +3
-2static int request_mac_address (struct lte_udev *udev) { -u8 buf[16 ] = {0 ,}; -struct hci_packet *hci = (struct hci_packet *)buf; +u8 *buf; +struct hci_packet *hci;struct usb_device *usbdev = udev->usbdev;int actual;int ret =-1 ; + buf =kzalloc (16 ,GFP_KERNEL );checkpatch did not complain about this?
Quoted 4 lines
Quoted 1 line
No. checkpatch shows no errors and warnings.
Please add a blank line after variables and before logic.
Will do thanks.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
And why do you need 'buf' anymore now? Why not just allocate hci and pass that to the request instead? Saves you an extra cast and an extra pointer.
thanks,
greg k-h
Quoted 8 lines
Quoted 2 lines
Thanks. I'll send v3. I assume now we don't need kzalloc anymore as we initialize the
hci_packetsokmalloc(sizeof(struct hci_packet),..)will do.Why is it needed now? And why would that change?
thanks,
greg k-h
I was thinking about allcoating hci_packet(hci) but as Dan said we only use first five bytes so kmalloc(5, ...) should work.
Thanks,
Amey