decoder: Alloc memory optimization [1/1]
authormiaohong chen <miaohong.chen@amlogic.com>
Mon, 14 Dec 2020 05:24:09 +0000 (13:24 +0800)
committerHui Zhang <hui.zhang@amlogic.com>
Fri, 18 Dec 2020 02:01:30 +0000 (18:01 -0800)
PD#SWPL-39007

Problem:
It is not neccessary to using kmalloc.

Solution:
Replace kmalloc with vzalloc.

Verify:
u212

Change-Id: I6e9dc6497f2827feb00af25ef7bd0d4bd23590a1
Signed-off-by: miaohong chen <miaohong.chen@amlogic.com>
drivers/common/media_clock/clk/clk.c
drivers/frame_provider/decoder/h264_multi/vmh264.c
drivers/frame_provider/decoder/utils/vdec.c

index 144006c158194a952bfe321d1b1e2d2f09dbe3da..972bcc131b8f7f5f338a492d41084e5290c9f226 100644 (file)
@@ -372,7 +372,7 @@ static int register_vdec_clk_mgr_per_cpu(int cputype,
                 */
                return 0;       /* ignore don't needed firmare. */
        }
-       mgr = kmalloc(sizeof(struct chip_vdec_clk_s), GFP_KERNEL);
+       mgr = vzalloc(sizeof(struct chip_vdec_clk_s));
        if (!mgr)
                return -ENOMEM;
        *mgr = *t_mgr;
@@ -381,7 +381,7 @@ static int register_vdec_clk_mgr_per_cpu(int cputype,
         */
        if (mgr->clock_init) {
                if (mgr->clock_init()) {
-                       kfree(mgr);
+                       vfree(mgr);
                        return -ENOMEM;
                }
        }
@@ -404,7 +404,7 @@ EXPORT_SYMBOL(register_vdec_clk_mgr);
 
 int unregister_vdec_clk_mgr(enum vdec_type_e vdec_type)
 {
-       kfree(get_current_vdec_chip()->clk_mgr[vdec_type]);
+       vfree(get_current_vdec_chip()->clk_mgr[vdec_type]);
 
        return 0;
 }
@@ -423,7 +423,7 @@ static int register_vdec_clk_setting_per_cpu(int cputype,
                 */
                return 0;       /* ignore don't needed this setting . */
        }
-       p_setting = kmalloc(size, GFP_KERNEL);
+       p_setting = vzalloc(size);
        if (!p_setting)
                return -ENOMEM;
        memcpy(p_setting, setting, size);
@@ -449,7 +449,7 @@ EXPORT_SYMBOL(register_vdec_clk_setting);
 
 int unregister_vdec_clk_setting(void)
 {
-       kfree(get_current_vdec_chip()->clk_setting_array);
+       vfree(get_current_vdec_chip()->clk_setting_array);
 
        return 0;
 }
index 85ef3cc71f150019e44abcc7154b63a4fdca9ee7..ffa17eff5eb61c1e46ba99ad243d17ad5ed15288 100644 (file)
@@ -7818,13 +7818,13 @@ static s32 vh264_init(struct vdec_h264_hw_s *hw)
                        return -1;
                }
 
-               hw->sei_data_buf = kmalloc(SEI_DATA_SIZE, GFP_KERNEL);
+               hw->sei_data_buf = vzalloc(SEI_DATA_SIZE);
                if (hw->sei_data_buf == NULL) {
                        pr_err("%s: failed to alloc sei itu data buffer\n",
                                __func__);
                        return -1;
                }
-               hw->sei_itu_data_buf = kmalloc(SEI_ITU_DATA_SIZE, GFP_KERNEL);
+               hw->sei_itu_data_buf = vzalloc(SEI_ITU_DATA_SIZE);
                if (hw->sei_itu_data_buf == NULL) {
                        pr_err("%s: failed to alloc sei itu data buffer\n",
                                __func__);
@@ -7832,15 +7832,14 @@ static s32 vh264_init(struct vdec_h264_hw_s *hw)
                                hw->prefix_aux_size + hw->suffix_aux_size, hw->aux_addr,
                                hw->aux_phy_addr);
                        hw->aux_addr = NULL;
-                       kfree(hw->sei_data_buf);
+                       vfree(hw->sei_data_buf);
                        hw->sei_data_buf = NULL;
 
                        return -1;
                }
 
                if (NULL == hw->sei_user_data_buffer) {
-                       hw->sei_user_data_buffer = kmalloc(USER_DATA_SIZE,
-                                                               GFP_KERNEL);
+                       hw->sei_user_data_buffer = vzalloc(USER_DATA_SIZE);
                        if (!hw->sei_user_data_buffer) {
                                pr_info("%s: Can not allocate sei_data_buffer\n",
                                           __func__);
@@ -7848,9 +7847,9 @@ static s32 vh264_init(struct vdec_h264_hw_s *hw)
                                        hw->prefix_aux_size + hw->suffix_aux_size, hw->aux_addr,
                                        hw->aux_phy_addr);
                                hw->aux_addr = NULL;
-                               kfree(hw->sei_data_buf);
+                               vfree(hw->sei_data_buf);
                                hw->sei_data_buf = NULL;
-                               kfree(hw->sei_itu_data_buf);
+                               vfree(hw->sei_itu_data_buf);
                                hw->sei_itu_data_buf = NULL;
 
                                return -1;
@@ -7918,15 +7917,15 @@ static int vh264_stop(struct vdec_h264_hw_s *hw)
                hw->aux_addr = NULL;
        }
        if (hw->sei_data_buf != NULL) {
-               kfree(hw->sei_data_buf);
+               vfree(hw->sei_data_buf);
                hw->sei_data_buf = NULL;
        }
        if (hw->sei_itu_data_buf != NULL) {
-               kfree(hw->sei_itu_data_buf);
+               vfree(hw->sei_itu_data_buf);
                hw->sei_itu_data_buf = NULL;
        }
        if (hw->sei_user_data_buffer != NULL) {
-               kfree(hw->sei_user_data_buffer);
+               vfree(hw->sei_user_data_buffer);
                hw->sei_user_data_buffer = NULL;
        }
        /* amvdec_disable(); */
@@ -8263,7 +8262,7 @@ static void show_user_data_buf(void)
 
 static int vmh264_init_userdata_dump(void)
 {
-       user_data_buf = kmalloc(MAX_USER_DATA_SIZE, GFP_KERNEL);
+       user_data_buf = vzalloc(MAX_USER_DATA_SIZE);
        if (user_data_buf)
                return 1;
        else
@@ -8274,7 +8273,7 @@ static void vmh264_dump_userdata(void)
 {
        if (user_data_buf) {
                show_user_data_buf();
-               kfree(user_data_buf);
+               vfree(user_data_buf);
                user_data_buf = NULL;
        }
 }
index 9646f7da4baf7b00b5221a19d01922892127311a..f0193b895c6ff660dc8beb15b85d3a987ea29d67 100644 (file)
@@ -4058,7 +4058,7 @@ static ssize_t dump_trace_show(struct class *class,
        int i;
        char *pbuf = buf;
        ssize_t ret;
-       u16 *trace_buf = kmalloc(debug_trace_num * 2, GFP_KERNEL);
+       u16 *trace_buf = vzalloc(debug_trace_num * 2);
 
        if (!trace_buf) {
                pbuf += sprintf(pbuf, "No Memory bug\n");
@@ -4069,7 +4069,7 @@ static ssize_t dump_trace_show(struct class *class,
                mutex_lock(&vdec_mutex);
                if (!vdec_on(VDEC_1)) {
                        mutex_unlock(&vdec_mutex);
-                       kfree(trace_buf);
+                       vfree(trace_buf);
                        pbuf += sprintf(pbuf, "amrisc is power off\n");
                        ret = pbuf - buf;
                        return ret;
@@ -4125,7 +4125,7 @@ static ssize_t dump_trace_show(struct class *class,
        }
        while (i < debug_trace_num)
                ;
-       kfree(trace_buf);
+       vfree(trace_buf);
        pbuf += sprintf(pbuf, "\n");
        ret = pbuf - buf;
        return ret;