MLK-11907 dma: pxp-dev: allocate the 'sg' buffer dynamically.
authorFancy Fang <chen.fang@freescale.com>
Thu, 26 Nov 2015 08:47:07 +0000 (16:47 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 19:49:15 +0000 (14:49 -0500)
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 <chen.fang@freescale.com>
(cherry picked from commit 57f08c108fc4f4721449b4b94be9820c7443978a)

drivers/dma/pxp/pxp_device.c

index b2716a0..a4a65a4 100644 (file)
@@ -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;
 }