int altek6045_exec_cmd(const hwextisp_intf_t* i, hwcam_config_data_t *data) { int rc = 0; u8 *in_buf = NULL, *out_buf = NULL; u32 opcode, dir_type, block_response, out_len, in_len; bool out_to_block; cam_notice("enter %s cmd=0x%x.", __func__, data->cmd); dir_type = data->cmd & EXTISP_CMD_DIR_FLAG_MASK; block_response = data->cmd & EXTISP_CMD_RESP_FLAG_MASK; out_len = in_len = (data->cmd & EXTISP_CMD_LEN_MASK)>>EXTISP_CMD_LEN_SHIT; opcode = (data->cmd & EXTISP_CMD_OPCODE_MASK)>>EXTISP_CMD_OPCODE_SHIT; out_buf = in_buf = data->u.buf; out_to_block = (EXTISP_BLOCK_RESPONSE_CMD == block_response)? true: false; /* allocate kernel buf: override out_buf out_len*/ if (out_to_block) { out_len = data->ext_buf.user_buf_len; if (out_len > 4096) { cam_err("%s invalid ext_buf_len=%d", __func__, out_len); return -EINVAL; } out_buf = kmalloc(out_len, GFP_KERNEL); if (NULL == out_buf) { cam_err("%s kmalloc failed", __func__); return -ENOMEM;; } } if (EXTISP_INOUT_CMD == dir_type) { rc = misp_exec_bidir_cmd((u16)opcode, data->u.buf, in_len, out_to_block, out_buf, out_len); } else if (EXTISP_SET_CMD == dir_type) { rc = misp_exec_unidir_cmd((u16)opcode, true, out_to_block, in_buf, in_len); } else if (EXTISP_GET_CMD == dir_type) { rc = misp_exec_unidir_cmd((u16)opcode, false, out_to_block, out_buf, out_len); } else { cam_err("%s unkown cmd direction", __func__); rc = -EINVAL; } /* reclaimed kernel buf*/ if (out_to_block) { if (copy_to_user(data->ext_buf.user_buf_ptr, out_buf, out_len)) { cam_err("%s copy to user failed", __func__); rc = -EFAULT; } kfree(out_buf); } return rc; }
int altek6045_exec_cmd(const hwextisp_intf_t* i, hwextisp_config_data_t *data) { int rc = 0; u8 *in_buf = NULL, *out_buf = NULL; u32 opcode, dir_type, block_response, out_len, in_len, bulk_len; bool out_to_block, out_from_block; if (get_boot_into_recovery_flag()||(misp_cmd_filter==1)) { cam_info("%s cmd=0x%x is blocked", __func__, data->cmd); return 0; } if(((data->cmd & 0x0000FFFF )!= 0x2106)&&((data->cmd & 0x0000FFFF )!= 0x2105)) cam_info("%s cmd=0x%x", __func__, data->cmd); dir_type = (data->cmd & EXTISP_CMD_DIR_FLAG_MASK)>>EXTISP_CMD_DIR_FLAG_SHIT; block_response = (data->cmd & EXTISP_CMD_RESP_FLAG_MASK)>>EXTISP_CMD_RESP_FLAG_SHIT; out_len = (data->cmd & EXTISP_CMD_OUT_LEN_MASK)>>EXTISP_CMD_OUT_LEN_SHIT; in_len = (data->cmd & EXTISP_CMD_IN_LEN_MASK)>>EXTISP_CMD_IN_LEN_SHIT; opcode = (data->cmd & EXTISP_CMD_OPCODE_MASK)>>EXTISP_CMD_OPCODE_SHIT; out_buf = in_buf = data->u.buf; out_to_block = (EXTISP_BLOCK_RESPONSE_CMD == block_response)? true: false; out_from_block = (EXTISP_BLOCK_WRITE_CMD == block_response) ? true : false; /* allocate kernel buf: override out_buf out_len*/ if (out_to_block) { out_len = data->ext_buf.user_buf_len; if (out_len > 4096) { cam_err("%s invalid ext_buf_len=%d", __func__, out_len); return -EINVAL; } out_buf = kmalloc(out_len, GFP_KERNEL); if (NULL == out_buf) { cam_err("%s kmalloc failed", __func__); return -ENOMEM;; } memset(out_buf,0,out_len); } if(out_from_block) { bulk_len = data->ext_buf.user_buf_len; out_buf = kmalloc(bulk_len, GFP_KERNEL); if(copy_from_user(out_buf, data->ext_buf.user_buf_ptr, bulk_len)) { cam_err("%s copy from user failed", __func__); rc = -EFAULT; } } if (EXTISP_INOUT_CMD == dir_type) { if(out_from_block) { rc = misp_exec_write_block_res((u16)opcode, in_buf, in_len, out_to_block, out_buf,bulk_len, out_len); } else { rc = misp_exec_bidir_cmd((u16)opcode, data->u.buf, in_len, out_to_block, out_buf, out_len); } } else if (EXTISP_SET_CMD == dir_type) { if(out_from_block) { rc = misp_exec_write_block((u16)opcode, in_buf, in_len, out_buf, bulk_len); } else { rc = misp_exec_unidir_cmd((u16)opcode, true, out_to_block, in_buf, in_len); } } else if (EXTISP_GET_CMD == dir_type) { rc = misp_exec_unidir_cmd((u16)opcode, false, out_to_block, out_buf, out_len); } else { cam_err("%s unkown cmd direction", __func__); rc = -EINVAL; } /* reclaimed kernel buf*/ if (out_to_block) { if (copy_to_user(data->ext_buf.user_buf_ptr, out_buf, out_len)) { cam_err("%s copy to user failed", __func__); rc = -EFAULT; } kfree(out_buf); out_buf = NULL; } if(out_from_block) { if(out_buf) { kfree(out_buf); } } out_buf = NULL; return rc; }