Skip to contentSkip to conversation

dmatest: Fix NULL pointer dereference on ioat

PATCH Applied Jon Mason 3 participants 4 messages Nov 11, 2012 – Dec 3, 2012 dmaengine

lore
Share & tools
lore

Jon Mason

author
#0 lore raw

PATCH v2 1/1 dmatest: Fix NULL pointer dereference on ioat

device_control is an optional and not implemented in all DMA drivers. Any calls to these will result in a NULL pointer dereference. dmatest makes two of these calls when completing the kernel thread and removing the module. These are corrected by calling the dmaengine_device_control wrapper and checking for a non-existant device_control function pointer there.

CC Vinod Koul <[email protected]>
CC Dan Williams <[email protected]>
---
 drivers/dma/dmatest.c     |    4 ++--
 include/linux/dmaengine.h |    5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/dma/dmatest.c +2 -2
index 24225f0..6ef9465 100644
@@ -499,7 +499,7 @@ err_srcs:
 			thread_name, total_tests, failed_tests, ret);
 
 	/* terminate all transfers on specified channels */
-	chan->device->device_control(chan, DMA_TERMINATE_ALL, 0);
+	dmaengine_terminate_all(chan);
 	if (iterations > 0)
 		while (!kthread_should_stop()) {
 			DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit);
@@ -524,7 +524,7 @@ static void dmatest_cleanup_channel(struct dmatest_chan *dtc)
 	}
 
 	/* terminate all transfers on specified channels */
-	dtc->chan->device->device_control(dtc->chan, DMA_TERMINATE_ALL, 0);
+	dmaengine_terminate_all(dtc->chan);
 
 	kfree(dtc);
 }
include/linux/dmaengine.h +4 -1
index d3201e4..cf94e5f 100644
@@ -608,7 +608,10 @@ static inline int dmaengine_device_control(struct dma_chan *chan,
 					   enum dma_ctrl_cmd cmd,
 					   unsigned long arg)
 {
-	return chan->device->device_control(chan, cmd, arg);
+	if (chan->device->device_control)
+		return chan->device->device_control(chan, cmd, arg);
+	else
+		return -ENOSYS;
 }
 
 static inline int dmaengine_slave_config(struct dma_chan *chan,
Signature · 1 line
1.7.9.5
Reviewed-by on v2 1/1
#1 lore raw
Quoted 42 lines · Jon Mason

device_control is an optional and not implemented in all DMA drivers. Any calls to these will result in a NULL pointer dereference. dmatest makes two of these calls when completing the kernel thread and removing the module. These are corrected by calling the dmaengine_device_control wrapper and checking for a non-existant device_control function pointer there.

CC Vinod Koul <[email protected]>
CC Dan Williams <[email protected]>
---
 drivers/dma/dmatest.c     |    4 ++--
 include/linux/dmaengine.h |    5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/dma/dmatest.c +2 -2
index 24225f0..6ef9465 100644
@@ -499,7 +499,7 @@ err_srcs:
                        thread_name, total_tests, failed_tests, ret);
 
        /* terminate all transfers on specified channels */
-       chan->device->device_control(chan, DMA_TERMINATE_ALL, 0);
+       dmaengine_terminate_all(chan);
        if (iterations > 0)
                while (!kthread_should_stop()) {
                        DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit);
@@ -524,7 +524,7 @@ static void dmatest_cleanup_channel(struct dmatest_chan *dtc)
        }
 
        /* terminate all transfers on specified channels */
-       dtc->chan->device->device_control(dtc->chan, DMA_TERMINATE_ALL, 0);
+       dmaengine_terminate_all(dtc->chan);
 
        kfree(dtc);
 }
include/linux/dmaengine.h +0 -0
index d3201e4..cf94e5f 100644

include/linux/dmaengine.h static inline int dmaengine_device_control(struct dma_chan *chan, · line 615

Quoted 9 lines
include/linux/dmaengine.h +4 -1
@@ -608,7 +608,10 @@ static inline int dmaengine_device_control(struct dma_chan *chan,
                                           enum dma_ctrl_cmd cmd,
                                           unsigned long arg)
 {
-       return chan->device->device_control(chan, cmd, arg);
+       if (chan->device->device_control)
+               return chan->device->device_control(chan, cmd, arg);
+       else
+               return -ENOSYS;
 }
#2 lore raw
Quoted 8 lines · viresh kumar
Quoted 7 lines · Jon Mason

device_control is an optional and not implemented in all DMA drivers. Any calls to these will result in a NULL pointer dereference. dmatest makes two of these calls when completing the kernel thread and removing the module. These are corrected by calling the dmaengine_device_control wrapper and checking for a non-existant device_control function pointer there.

Quoted 5 lines
Quoted 3 lines
CC Vinod Koul <[email protected]>
CC Dan Williams <[email protected]>

Vinod/Dan: I couldn't find this patch and
https://patchwork.kernel.org/patch/1720971/
in you trees. Are you pushing them for 3.8?

--
viresh

Applied
#3 lore raw
Quoted 9 lines · viresh kumar
Quoted 8 lines · Jon Mason
Quoted 7 lines

device_control is an optional and not implemented in all DMA drivers. Any calls to these will result in a NULL pointer dereference. dmatest makes two of these calls when completing the kernel thread and removing the module. These are corrected by calling the dmaengine_device_control wrapper and checking for a non-existant device_control function pointer there.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
CC Vinod Koul <[email protected]>
CC Dan Williams <[email protected]>

Applied, Thanks

--
~Vinod