drm/tilcdc: Allocate register storage based on the actual number registers
authorJyri Sarha <jsarha@ti.com>
Thu, 2 Jul 2015 13:26:12 +0000 (16:26 +0300)
committerJyri Sarha <jsarha@ti.com>
Thu, 25 Feb 2016 14:39:35 +0000 (16:39 +0200)
Allocate suspend/resume register storage based on the actual number
registers the driver is aware of. The static allocation for register
storage had fallen behind badly.

Reported-by: Michael Bode <michael@bumbleB.de>
Signed-off-by: Jyri Sarha <jsarha@ti.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
drivers/gpu/drm/tilcdc/tilcdc_drv.c
drivers/gpu/drm/tilcdc/tilcdc_drv.h

index 977c843f663a25aea2c94821da9e1dc05b9689ea..47096b1b8b2ab1e235e58c30039ae4fd637381e2 100644 (file)
@@ -141,11 +141,14 @@ static int tilcdc_unload(struct drm_device *dev)
 
        pm_runtime_disable(dev->dev);
 
+       kfree(priv->saved_register);
        kfree(priv);
 
        return 0;
 }
 
+static size_t tilcdc_num_regs(void);
+
 static int tilcdc_load(struct drm_device *dev, unsigned long flags)
 {
        struct platform_device *pdev = dev->platformdev;
@@ -157,7 +160,12 @@ static int tilcdc_load(struct drm_device *dev, unsigned long flags)
        int ret;
 
        priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-       if (!priv) {
+       if (priv)
+               priv->saved_register = kcalloc(tilcdc_num_regs(),
+                                              sizeof(*priv->saved_register),
+                                              GFP_KERNEL);
+       if (!priv || !priv->saved_register) {
+               kfree(priv);
                dev_err(dev->dev, "failed to allocate private data\n");
                return -ENOMEM;
        }
@@ -339,6 +347,7 @@ fail_free_wq:
 
 fail_free_priv:
        dev->dev_private = NULL;
+       kfree(priv->saved_register);
        kfree(priv);
        return ret;
 }
@@ -456,6 +465,16 @@ static const struct {
                REG(2, true,  LCDC_INT_ENABLE_SET_REG),
 #undef REG
 };
+
+static size_t tilcdc_num_regs(void)
+{
+       return ARRAY_SIZE(registers);
+}
+#else
+static size_t tilcdc_num_regs(void)
+{
+       return 0;
+}
 #endif
 
 #ifdef CONFIG_DEBUG_FS
index 95324f19d891905611873bfd2006c07a0928e0fb..c1de18bae41530df2eb1d8390b4876d60f29007a 100644 (file)
@@ -66,7 +66,7 @@ struct tilcdc_drm_private {
        uint32_t max_width;
 
        /* register contents saved across suspend/resume: */
-       u32 saved_register[12];
+       u32 *saved_register;
        bool ctx_valid;
 
 #ifdef CONFIG_CPU_FREQ