[COMMON] media: mfc: check low memory device
authorJeonghee Kim <jhhhh.kim@samsung.com>
Tue, 26 Jun 2018 02:23:31 +0000 (11:23 +0900)
committerSunyoung Kang <sy0816.kang@samsung.com>
Mon, 23 Jul 2018 06:18:48 +0000 (15:18 +0900)
Returns error if the total memory is less than 1.5GB and DPB size is too big
to pass android.security.cts.StagefrightTest#testBug_37930177

Change-Id: I62f82f73ea49a490317e54faf80adf467474be70
Signed-off-by: Jeonghee Kim <jhhhh.kim@samsung.com>
drivers/media/platform/exynos/mfc/s5p_mfc_common.h
drivers/media/platform/exynos/mfc/s5p_mfc_debugfs.c
drivers/media/platform/exynos/mfc/s5p_mfc_dec.c

index ef3d98d7909d57b6a25404dcc6f3d5d31713148f..0a919066cb1876363d63eaca368eb493053ddcd0 100644 (file)
 
 #define MFC_FEATURE_SUPPORT(dev, f)    ((f).support && ((dev)->fw.date >= (f).version))
 
+/* Low memory check */
+#define IS_LOW_MEM                     (totalram_pages <= ((SZ_1G + SZ_512M) >> PAGE_SHIFT))
+#define SZ_600M                                (6 * 1024 * 1024)
+
 #endif /* __S5P_MFC_COMMON_H */
index 55e17ff0710dbd395ec3d82884bceefd48f919fe..61f80a6bd5c84aafded7d5c814da92fef478215d 100644 (file)
@@ -70,6 +70,7 @@ static int mfc_info_show(struct seq_file *s, void *unused)
                        dev->pdata->support_10bit ? "supported" : "not supported",
                        dev->pdata->support_422 ? "supported" : "not supported",
                        dev->pdata->support_rgb ? "supported" : "not supported");
+       seq_printf(s, "[LOWMEM] is_low_mem: %d\n", IS_LOW_MEM);
        if (dev->nal_q_handle)
                seq_printf(s, "[NAL-Q] state: %d\n", dev->nal_q_handle->nal_q_state);
 
index 8ea96d3dc6669587a88157d3cc56afdbc3b3f740..a28c70faff011e8bd7f56c371960166c330c0ca1 100644 (file)
@@ -314,6 +314,25 @@ static int vidioc_g_fmt_vid_cap_mplane(struct file *file, void *priv,
                   rectangle. */
                s5p_mfc_dec_calc_dpb_size(ctx);
 
+               if (IS_LOW_MEM) {
+                       unsigned int dpb_size;
+                       /*
+                        * If total memory requirement is too big for this device,
+                        * then it returns error.
+                        * DPB size : Total plane size * the number of DPBs
+                        * 5: the number of extra DPBs
+                        * 3: the number of DPBs for Android framework
+                        * 600MB: being used to return an error,
+                        * when 8K resolution video clip is being tried to be decoded
+                        */
+                       dpb_size = (ctx->raw_buf.total_plane_size * (ctx->dpb_count + 5 + 3));
+                       if (dpb_size > SZ_600M) {
+                               mfc_info_ctx("required memory size is too big (%dx%d, dpb: %d)\n",
+                                               ctx->img_width, ctx->img_height, ctx->dpb_count);
+                               return -EINVAL;
+                       }
+               }
+
                pix_fmt_mp->width = ctx->img_width;
                pix_fmt_mp->height = ctx->img_height;
                pix_fmt_mp->num_planes = ctx->dst_fmt->mem_planes;