From beec8b33a15e85a9a9431176c4527b508a824530 Mon Sep 17 00:00:00 2001 From: miaohong chen Date: Mon, 14 Dec 2020 13:24:09 +0800 Subject: [PATCH] decoder: Alloc memory optimization [1/1] 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 --- drivers/common/media_clock/clk/clk.c | 10 ++++---- .../decoder/h264_multi/vmh264.c | 23 +++++++++---------- drivers/frame_provider/decoder/utils/vdec.c | 6 ++--- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/drivers/common/media_clock/clk/clk.c b/drivers/common/media_clock/clk/clk.c index 144006c..972bcc1 100644 --- a/drivers/common/media_clock/clk/clk.c +++ b/drivers/common/media_clock/clk/clk.c @@ -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; } diff --git a/drivers/frame_provider/decoder/h264_multi/vmh264.c b/drivers/frame_provider/decoder/h264_multi/vmh264.c index 85ef3cc..ffa17ef 100644 --- a/drivers/frame_provider/decoder/h264_multi/vmh264.c +++ b/drivers/frame_provider/decoder/h264_multi/vmh264.c @@ -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; } } diff --git a/drivers/frame_provider/decoder/utils/vdec.c b/drivers/frame_provider/decoder/utils/vdec.c index 9646f7d..f0193b8 100644 --- a/drivers/frame_provider/decoder/utils/vdec.c +++ b/drivers/frame_provider/decoder/utils/vdec.c @@ -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; -- 2.20.1