summaryrefslogtreecommitdiffstats
path: root/drivers/rapidio/devices
diff options
context:
space:
mode:
authorIoan Nicu <ioan.nicu.ext@nokia.com>2018-04-20 17:55:49 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-04-20 20:18:35 -0400
commitc5157b76869ba98c3a99a1982396437464e131a6 (patch)
treece99b92a5e52ca9a13f865899ae5646719351eaa /drivers/rapidio/devices
parente71769ae52609ea0044a9901709042e5634c2306 (diff)
rapidio: fix rio_dma_transfer error handling
Some of the mport_dma_req structure members were initialized late inside the do_dma_request() function, just before submitting the request to the dma engine. But we have some error branches before that. In case of such an error, the code would return on the error path and trigger the calling of dma_req_free() with a req structure which is not completely initialized. This causes a NULL pointer dereference in dma_req_free(). This patch fixes these error branches by making sure that all necessary mport_dma_req structure members are initialized in rio_dma_transfer() immediately after the request structure gets allocated. Link: http://lkml.kernel.org/r/20180412150605.GA31409@nokia.com Fixes: bbd876adb8c72 ("rapidio: use a reference count for struct mport_dma_req") Signed-off-by: Ioan Nicu <ioan.nicu.ext@nokia.com> Tested-by: Alexander Sverdlin <alexander.sverdlin@nokia.com> Acked-by: Alexandre Bounine <alex.bou9@gmail.com> Cc: Barry Wood <barry.wood@idt.com> Cc: Matt Porter <mporter@kernel.crashing.org> Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Cc: Logan Gunthorpe <logang@deltatee.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Frank Kunz <frank.kunz@nokia.com> Cc: <stable@vger.kernel.org> [4.6+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rapidio/devices')
-rw-r--r--drivers/rapidio/devices/rio_mport_cdev.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
index 9d27016c899e..0434ab7b6497 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -740,10 +740,7 @@ static int do_dma_request(struct mport_dma_req *req,
740 tx->callback = dma_xfer_callback; 740 tx->callback = dma_xfer_callback;
741 tx->callback_param = req; 741 tx->callback_param = req;
742 742
743 req->dmach = chan;
744 req->sync = sync;
745 req->status = DMA_IN_PROGRESS; 743 req->status = DMA_IN_PROGRESS;
746 init_completion(&req->req_comp);
747 kref_get(&req->refcount); 744 kref_get(&req->refcount);
748 745
749 cookie = dmaengine_submit(tx); 746 cookie = dmaengine_submit(tx);
@@ -831,13 +828,20 @@ rio_dma_transfer(struct file *filp, u32 transfer_mode,
831 if (!req) 828 if (!req)
832 return -ENOMEM; 829 return -ENOMEM;
833 830
834 kref_init(&req->refcount);
835
836 ret = get_dma_channel(priv); 831 ret = get_dma_channel(priv);
837 if (ret) { 832 if (ret) {
838 kfree(req); 833 kfree(req);
839 return ret; 834 return ret;
840 } 835 }
836 chan = priv->dmach;
837
838 kref_init(&req->refcount);
839 init_completion(&req->req_comp);
840 req->dir = dir;
841 req->filp = filp;
842 req->priv = priv;
843 req->dmach = chan;
844 req->sync = sync;
841 845
842 /* 846 /*
843 * If parameter loc_addr != NULL, we are transferring data from/to 847 * If parameter loc_addr != NULL, we are transferring data from/to
@@ -925,11 +929,6 @@ rio_dma_transfer(struct file *filp, u32 transfer_mode,
925 xfer->offset, xfer->length); 929 xfer->offset, xfer->length);
926 } 930 }
927 931
928 req->dir = dir;
929 req->filp = filp;
930 req->priv = priv;
931 chan = priv->dmach;
932
933 nents = dma_map_sg(chan->device->dev, 932 nents = dma_map_sg(chan->device->dev,
934 req->sgt.sgl, req->sgt.nents, dir); 933 req->sgt.sgl, req->sgt.nents, dir);
935 if (nents == 0) { 934 if (nents == 0) {