lcd: add protection for tcon memory size [1/1]
authorshaochan.liu <shaochan.liu@amlogic.com>
Tue, 11 Jun 2019 06:36:20 +0000 (14:36 +0800)
committerTao Zeng <tao.zeng@amlogic.com>
Tue, 11 Jun 2019 09:04:41 +0000 (02:04 -0700)
PD#SWPL-9502

Problem:
need avoid when set error tcon memory size

Solution:
add protection for tcon memory size

Verify:
t962_x301

Change-Id: I40c295c9ebcb26a991dc66b4fb2a7f0d006d4359
Signed-off-by: shaochan.liu <shaochan.liu@amlogic.com>
arch/arm/boot/dts/amlogic/tl1_t962x2_x301_1g.dts
arch/arm64/boot/dts/amlogic/tl1_t962x2_x301_1g.dts
drivers/amlogic/media/vout/lcd/lcd_tcon.c

index 335d45f..b07108b 100644 (file)
@@ -81,7 +81,7 @@
                lcd_tcon_reserved:linux,lcd_tcon {
                        compatible = "shared-dma-pool";
                        reusable;
-                       size = <0xc00000>;
+                       size = <0x0>;
                        alignment = <0x400000>;
                        alloc-ranges = <0x3ec00000 0xc00000>;
                };
index e8bc174..ec9f977 100644 (file)
@@ -79,7 +79,7 @@
                lcd_tcon_reserved:linux,lcd_tcon {
                        compatible = "shared-dma-pool";
                        reusable;
-                       size = <0x0 0xc00000>;
+                       size = <0x0 0x0>;
                        alignment = <0x0 0x400000>;
                        alloc-ranges = <0x0 0x3ec00000 0x0 0xc00000>;
                };
index b260a37..fb77059 100644 (file)
@@ -736,19 +736,22 @@ int lcd_tcon_probe(struct aml_lcd_drv_s *lcd_drv)
                                LCDPR("tcon axi_mem base:0x%lx, size:0x%lx\n",
                                        (unsigned long)tcon_rmem.mem_paddr,
                                        cma_get_size(cma));
-
                                mem_size = lcd_tcon_data->axi_mem_size;
+                               if (cma_get_size(cma) < mem_size)
+                                       tcon_rmem.flag = 0;
+                               else {
                                tcon_rmem.mem_vaddr = dma_alloc_from_contiguous(
                                        lcd_drv->dev,
                                        (mem_size >> PAGE_SHIFT),
                                        0);
-                               if (tcon_rmem.mem_vaddr == NULL) {
+                                       if (tcon_rmem.mem_vaddr == NULL) {
                                        LCDERR("tcon axi_mem alloc failed\n");
-                               } else {
+                                       } else {
                                        LCDPR("tcon axi_mem dma_alloc=0x%x\n",
                                                mem_size);
-                                       tcon_rmem.mem_size = mem_size;
+                                               tcon_rmem.mem_size = mem_size;
                                        tcon_rmem.flag = 2; /* cma memory */
+                                       }
                                }
                        } else {
                                LCDERR("tcon: NO CMA\n");
@@ -757,10 +760,14 @@ int lcd_tcon_probe(struct aml_lcd_drv_s *lcd_drv)
                        LCDERR("tcon axi_mem alloc failed\n");
 #endif
                } else {
-                       tcon_rmem.flag = 1; /* reserved memory */
                        mem_size = tcon_rmem.mem_size;
-                       LCDPR("tcon axi_mem base:0x%lx, size:0x%x\n",
+                       if (mem_size < lcd_tcon_data->axi_mem_size)
+                               tcon_rmem.flag = 0;
+                       else {
+                               tcon_rmem.flag = 1; /* reserved memory */
+                               LCDPR("tcon axi_mem base:0x%lx, size:0x%x\n",
                                (unsigned long)tcon_rmem.mem_paddr, mem_size);
+                       }
                }
        }