@@ -193,6 +193,26 @@ static void cam_ope_free_io_config(struct cam_ope_request *req)
193193 }
194194}
195195
196+ static void cam_ope_free_cpu_buf (struct cam_ope_request * req )
197+ {
198+ if (!req )
199+ return ;
200+
201+ // Only release KMD buffer if it was acquired and not already released
202+ if (req -> ope_kmd_buf .cpu_addr && req -> ope_kmd_buf .mem_handle ) {
203+ cam_mem_put_cpu_buf (req -> ope_kmd_buf .mem_handle );
204+ req -> ope_kmd_buf .cpu_addr = 0 ;
205+ req -> ope_kmd_buf .mem_handle = 0 ;
206+ }
207+
208+ // Only release debug buffer if it was acquired and not already released
209+ if (req -> ope_debug_buf .cpu_addr && req -> ope_debug_buf .mem_handle ) {
210+ cam_mem_put_cpu_buf (req -> ope_debug_buf .mem_handle );
211+ req -> ope_debug_buf .cpu_addr = 0 ;
212+ req -> ope_debug_buf .mem_handle = 0 ;
213+ }
214+ }
215+
196216static void cam_ope_device_timer_stop (struct cam_ope_hw_mgr * hw_mgr )
197217{
198218 if (hw_mgr -> clk_info .watch_dog ) {
@@ -1740,6 +1760,8 @@ static void cam_ope_ctx_cdm_callback(uint32_t handle, void *userdata,
17401760 if (ctx -> ctx_state != OPE_CTX_STATE_ACQUIRED ) {
17411761 CAM_ERR (CAM_OPE , "ctx %u is in %d state" ,
17421762 ctx -> ctx_id , ctx -> ctx_state );
1763+ if (ope_req )
1764+ cam_ope_free_cpu_buf (ope_req );
17431765 mutex_unlock (& ctx -> ctx_mutex );
17441766 return ;
17451767 }
@@ -1796,6 +1818,7 @@ static void cam_ope_ctx_cdm_callback(uint32_t handle, void *userdata,
17961818 ctx -> req_cnt -- ;
17971819
17981820 buf_data .request_id = ope_req -> request_id ;
1821+ cam_ope_free_cpu_buf (ope_req );
17991822 ope_req -> request_id = 0 ;
18001823 cam_free_clear ((void * )ctx -> req_list [req_id ]-> cdm_cmd );
18011824 ctx -> req_list [req_id ]-> cdm_cmd = NULL ;
@@ -2319,6 +2342,8 @@ static int cam_ope_mgr_process_cmd_buf_req(struct cam_ope_hw_mgr *hw_mgr,
23192342 ope_request -> ope_kmd_buf .iova_cdm_addr );
23202343 } else if (cmd_buf -> cmd_buf_usage ==
23212344 OPE_CMD_BUF_DEBUG ) {
2345+ ope_request -> ope_debug_buf .mem_handle =
2346+ cmd_buf -> mem_handle ;
23222347 ope_request -> ope_debug_buf .cpu_addr =
23232348 cpu_addr ;
23242349 ope_request -> ope_debug_buf .iova_addr =
@@ -2332,7 +2357,9 @@ static int cam_ope_mgr_process_cmd_buf_req(struct cam_ope_hw_mgr *hw_mgr,
23322357 CAM_DBG (CAM_OPE , "dbg buf = %x" ,
23332358 ope_request -> ope_debug_buf .cpu_addr );
23342359 }
2335- cam_mem_put_cpu_buf (cmd_buf -> mem_handle );
2360+ if ((cmd_buf -> cmd_buf_usage != OPE_CMD_BUF_KMD ) &&
2361+ (cmd_buf -> cmd_buf_usage != OPE_CMD_BUF_DEBUG ))
2362+ cam_mem_put_cpu_buf (cmd_buf -> mem_handle );
23362363 break ;
23372364 }
23382365 case OPE_CMD_BUF_SCOPE_STRIPE : {
@@ -2443,6 +2470,7 @@ static int cam_ope_mgr_process_cmd_desc(struct cam_ope_hw_mgr *hw_mgr,
24432470 if (rc ) {
24442471 CAM_ERR (CAM_OPE , "Process OPE cmd io request is failed: %d" ,
24452472 rc );
2473+ cam_ope_free_cpu_buf (ope_request );
24462474 goto free_buf ;
24472475 }
24482476
@@ -3485,6 +3513,7 @@ static int cam_ope_mgr_prepare_hw_update(void *hw_priv,
34853513 return rc ;
34863514
34873515free_buf :
3516+ cam_ope_free_cpu_buf (ope_req );
34883517 cam_common_mem_free (ope_cmd_buf_addr );
34893518end :
34903519 cam_ope_mgr_put_cmd_buf (packet );
@@ -3514,6 +3543,7 @@ static int cam_ope_mgr_handle_config_err(
35143543 ctx_data -> ctxt_event_cb (ctx_data -> context_priv , CAM_CTX_EVT_ID_ERROR ,
35153544 & buf_data );
35163545
3546+ cam_ope_free_cpu_buf (ope_req );
35173547 req_idx = ope_req -> req_idx ;
35183548 ope_req -> request_id = 0 ;
35193549 cam_free_clear ((void * )ctx_data -> req_list [req_idx ]-> cdm_cmd );
@@ -3693,6 +3723,7 @@ static int cam_ope_mgr_flush_req(struct cam_ope_ctx *ctx_data,
36933723{
36943724 int idx ;
36953725 int64_t request_id ;
3726+ struct cam_ope_request * ope_req ;
36963727
36973728 request_id = * (int64_t * )flush_args -> flush_req_pending [0 ];
36983729 for (idx = 0 ; idx < CAM_CTX_REQ_MAX ; idx ++ ) {
@@ -3701,7 +3732,8 @@ static int cam_ope_mgr_flush_req(struct cam_ope_ctx *ctx_data,
37013732
37023733 if (ctx_data -> req_list [idx ]-> request_id != request_id )
37033734 continue ;
3704-
3735+ ope_req = ctx_data -> req_list [idx ];
3736+ cam_ope_free_cpu_buf (ope_req );
37053737 ctx_data -> req_list [idx ]-> request_id = 0 ;
37063738 cam_free_clear ((void * )ctx_data -> req_list [idx ]-> cdm_cmd );
37073739 ctx_data -> req_list [idx ]-> cdm_cmd = NULL ;
@@ -3719,6 +3751,7 @@ static int cam_ope_mgr_flush_all(struct cam_ope_ctx *ctx_data,
37193751{
37203752 int i , rc ;
37213753 struct cam_ope_hw_mgr * hw_mgr = ope_hw_mgr ;
3754+ struct cam_ope_request * ope_req ;
37223755
37233756 rc = cam_cdm_flush_hw (ctx_data -> ope_cdm .cdm_handle );
37243757
@@ -3734,7 +3767,8 @@ static int cam_ope_mgr_flush_all(struct cam_ope_ctx *ctx_data,
37343767 for (i = 0 ; i < CAM_CTX_REQ_MAX ; i ++ ) {
37353768 if (!ctx_data -> req_list [i ])
37363769 continue ;
3737-
3770+ ope_req = ctx_data -> req_list [i ];
3771+ cam_ope_free_cpu_buf (ope_req );
37383772 ctx_data -> req_list [i ]-> request_id = 0 ;
37393773 cam_free_clear ((void * )ctx_data -> req_list [i ]-> cdm_cmd );
37403774 ctx_data -> req_list [i ]-> cdm_cmd = NULL ;
0 commit comments