From c6b6b161bfd72bb18f9b3210cde5f822077097a5 Mon Sep 17 00:00:00 2001 From: Fancy Fang Date: Thu, 26 Nov 2015 16:47:07 +0800 Subject: [PATCH] MLK-11907 dma: pxp-dev: allocate the 'sg' buffer dynamically. The 'sg' buffer should be allocated dynamically, since its size is dependent on the 'sg_len' which is calculated according to the functions required. Signed-off-by: Fancy Fang (cherry picked from commit 57f08c108fc4f4721449b4b94be9820c7443978a) --- drivers/dma/pxp/pxp_device.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/dma/pxp/pxp_device.c b/drivers/dma/pxp/pxp_device.c index b2716a07d4ec..a4a65a45d30c 100644 --- a/drivers/dma/pxp/pxp_device.c +++ b/drivers/dma/pxp/pxp_device.c @@ -317,7 +317,7 @@ static void pxp_dma_done(void *arg) static int pxp_ioc_config_chan(struct pxp_file *priv, unsigned long arg) { - struct scatterlist sg[3]; + struct scatterlist *sg; struct pxp_tx_desc *desc; struct dma_async_tx_descriptor *txd; struct pxp_config_data *pxp_conf; @@ -356,6 +356,12 @@ static int pxp_ioc_config_chan(struct pxp_file *priv, unsigned long arg) if (pxp_conf->proc_data.engine_enable & PXP_ENABLE_DITHER) sg_len += 4; + sg = kmalloc(sizeof(*sg) * sg_len, GFP_KERNEL); + if (!sg) { + kfree(pxp_conf); + return -ENOMEM; + } + sg_init_table(sg, sg_len); txd = chan->device->device_prep_slave_sg(chan, @@ -366,6 +372,7 @@ static int pxp_ioc_config_chan(struct pxp_file *priv, unsigned long arg) if (!txd) { pr_err("Error preparing a DMA transaction descriptor.\n"); kfree(pxp_conf); + kfree(sg); return -EIO; } @@ -488,12 +495,14 @@ static int pxp_ioc_config_chan(struct pxp_file *priv, unsigned long arg) if (cookie < 0) { pr_err("Error tx_submit\n"); kfree(pxp_conf); + kfree(sg); return -EIO; } atomic_inc(&irq_info[chan_id].irq_pending); kfree(pxp_conf); + kfree(sg); return 0; } -- 2.17.1