staging: emxx_udc: Fix passing of NULL to dma_alloc_coherent()
A message that is not in the archive (sent off-list or not yet received): 20200824142118.GA223827@mwanda
PATCH 1/1 staging: emxx_udc: Fix passing of NULL to dma_alloc_coherent()
In nbu2ss_eq_queue() memory is allocated with dma_alloc_coherent(), though, strangely, NULL is passed as the struct device* argument. Pass the UDC's device instead.
Build-tested on x86 only.
---
So I *think* this is the right fix, but I don't have the hardware so I've only been able to build-test it. My worry is that I could be passing in the wrong struct device* here, which would squelch the warning without fixing the breakage.
Can someone cleverer than me tell me if this makes sense?
- Alex
--- drivers/staging/emxx_udc/emxx_udc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/emxx_udc/emxx_udc.c +1 -1
@@ -2593,7 +2593,7 @@ static int nbu2ss_ep_queue(struct usb_ep *_ep,if (req->unaligned) {if (!ep->virt_buf) - ep->virt_buf =dma_alloc_coherent (NULL ,PAGE_SIZE , + ep->virt_buf =dma_alloc_coherent (udc->dev,PAGE_SIZE , &ep->phys_buf,GFP_ATOMIC |GFP_DMA );if (ep->epnum >0 ) {
Signature · 1 line
2.28.0
Quoted 10 lines · Alex Dewar
In
nbu2ss_eq_queue()memory is allocated withdma_alloc_coherent(), though, strangely, NULL is passed as the struct device* argument. Pass the UDC's device instead.Build-tested on x86 only.
Fixes 33aa8d45a4fe ("staging: emxx_udc: Add Emma Mobile USB Gadget driver")Signed-off-by Alex Dewar <[email protected]>---
Quoted 8 lines
So I *think* this is the right fix, but I don't have the hardware so I've only been able to build-test it. My worry is that I could be passing in the wrong struct device* here, which would squelch the warning without fixing the breakage.
Can someone cleverer than me tell me if this makes sense?
- Alex
PS -- I meant to put an RFC in the subject line and an extra tag:
Quoted 20 lines
--- drivers/staging/emxx_udc/emxx_udc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/emxx_udc/emxx_udc.c +1
-1@@ -2593,7 +2593,7 @@ static int nbu2ss_ep_queue(struct usb_ep *_ep,if (req->unaligned) {if (!ep->virt_buf) - ep->virt_buf =dma_alloc_coherent (NULL ,PAGE_SIZE , + ep->virt_buf =dma_alloc_coherent (udc->dev,PAGE_SIZE , &ep->phys_buf,GFP_ATOMIC |GFP_DMA );if (ep->epnum >0 ) {Signature · 1 line
2.28.0
Quoted 4 lines · Alex Dewar
Quoted 3 lines · Alex Dewar
In
nbu2ss_eq_queue()memory is allocated withdma_alloc_coherent(), though, strangely, NULL is passed as the struct device* argument. Pass the UDC's device instead.
I think passing NULL was always wrong, but it used to not cause an Oops. This was changed a year or two ago.
Quoted 12 lines
Quoted 12 lines
Build-tested on x86 only.
Fixes 33aa8d45a4fe ("staging: emxx_udc: Add Emma Mobile USB Gadget driver")Signed-off-by Alex Dewar <[email protected]>---
So I *think* this is the right fix, but I don't have the hardware so I've only been able to build-test it. My worry is that I could be passing in the wrong struct device* here, which would squelch the warning without fixing the breakage.
Quoted 7 lines
Quoted 3 lines
Can someone cleverer than me tell me if this makes sense?
- Alex
PS -- I meant to put an RFC in the subject line and an extra tag:
Reported-by Dan Carpenter <[email protected]>
I don't know which dev pointer we're supposed to pass... It would be good to find someone to test the patch but if not then applying your patch is reasonable.
But could you search through the file and update the rest as well. The dma_free_coherent() needs to be updated and there was a second dma_alloc_coherent() in the bug report.
regards,
dan carpenter
Quoted 33 lines · Dan Carpenter
Quoted 4 lines · Alex Dewar
Quoted 3 lines · Alex Dewar
In
nbu2ss_eq_queue()memory is allocated withdma_alloc_coherent(), though, strangely, NULL is passed as the struct device* argument. Pass the UDC's device instead.I think passing NULL was always wrong, but it used to not cause an Oops. This was changed a year or two ago.
Quoted 12 lines
Quoted 12 lines
Build-tested on x86 only.
Fixes 33aa8d45a4fe ("staging: emxx_udc: Add Emma Mobile USB Gadget driver")Signed-off-by Alex Dewar <[email protected]>---
So I *think* this is the right fix, but I don't have the hardware so I've only been able to build-test it. My worry is that I could be passing in the wrong struct device* here, which would squelch the warning without fixing the breakage.
Quoted 7 lines
Quoted 3 lines
Can someone cleverer than me tell me if this makes sense?
- Alex
PS -- I meant to put an RFC in the subject line and an extra tag:
Reported-by Dan Carpenter <[email protected]>I don't know which dev pointer we're supposed to pass... It would be good to find someone to test the patch but if not then applying your patch is reasonable.
Quoted 7 lines
But could you search through the file and update the rest as well. The
dma_free_coherent()needs to be updated and there was a seconddma_alloc_coherent()in the bug report.regards,
dan carpenter
I can only find the one instance of dma_alloc_coherent(). Was it by any chance a different warning about the same call....?
Quoted 38 lines · Alex Dewar
Quoted 37 lines · Dan Carpenter
Quoted 4 lines · Alex Dewar
Quoted 3 lines · Alex Dewar
In
nbu2ss_eq_queue()memory is allocated withdma_alloc_coherent(), though, strangely, NULL is passed as the struct device* argument. Pass the UDC's device instead.I think passing NULL was always wrong, but it used to not cause an Oops. This was changed a year or two ago.
Quoted 12 lines
Quoted 12 lines
Build-tested on x86 only.
Fixes 33aa8d45a4fe ("staging: emxx_udc: Add Emma Mobile USB Gadget driver")Signed-off-by Alex Dewar <[email protected]>---
So I *think* this is the right fix, but I don't have the hardware so I've only been able to build-test it. My worry is that I could be passing in the wrong struct device* here, which would squelch the warning without fixing the breakage.
Quoted 7 lines
Quoted 3 lines
Can someone cleverer than me tell me if this makes sense?
- Alex
PS -- I meant to put an RFC in the subject line and an extra tag:
Reported-by Dan Carpenter <[email protected]>I don't know which dev pointer we're supposed to pass... It would be good to find someone to test the patch but if not then applying your patch is reasonable.
But could you search through the file and update the rest as well. The
dma_free_coherent()needs to be updated and there was a seconddma_alloc_coherent()in the bug report.
Quoted 6 lines
Quoted 3 lines
regards,
dan carpenterI can only find the one instance of
dma_alloc_coherent(). Was it by any chance a different warning about the same call....?
Ah.... It was warning about the dma_free_coherent().
regards,
dan carpenter
PATCH v2 1/1 staging: emxx_udc: Fix passing of NULL to dma_alloc_coherent()
In nbu2ss_eq_queue() memory is allocated with dma_alloc_coherent(), though, strangely, NULL is passed as the struct device* argument. Pass the UDC's device instead. Fix up the corresponding call to dma_free_coherent() in the same way.
Build-tested on x86 only.
---
v2: also fix call to dma_free_coherent() (Dan)
@Magnus: I noticed you contributed this code back in 2014... I don't suppose you happen to have the hardware lying around to test this so we can get a Tested-by....? :)
--- drivers/staging/emxx_udc/emxx_udc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/emxx_udc/emxx_udc.c +2 -2
@@ -2593,7 +2593,7 @@ static int nbu2ss_ep_queue(struct usb_ep *_ep,if (req->unaligned) {if (!ep->virt_buf) - ep->virt_buf =dma_alloc_coherent (NULL ,PAGE_SIZE , + ep->virt_buf =dma_alloc_coherent (udc->dev,PAGE_SIZE , &ep->phys_buf,GFP_ATOMIC |GFP_DMA );if (ep->epnum >0 ) {
@@ -3148,7 +3148,7 @@ static int nbu2ss_drv_remove(struct platform_device *pdev)for (i =0 ; i <NUM_ENDPOINTS ; i++) { ep = &udc->ep[i];if (ep->virt_buf) -dma_free_coherent (NULL ,PAGE_SIZE , (void *)ep->virt_buf, +dma_free_coherent (udc->dev,PAGE_SIZE , (void *)ep->virt_buf, ep->phys_buf); }
Signature · 1 line
2.28.0