Просмотр исходного кода

msm: camera: common: Add cam_free_clear to cam_compat

Kernel 5.10 and up have renamed kzfree to kfree_secure. As such,
we have added a cam_free_clear function to redirect all uses of kzfree
uses to the appropriate function depending on the kernel version the
driver is built against.

CRs-Fixed: 2835738
Change-Id: I72d191c9fb0454a4dbb1392894a909e81fe07caa
Signed-off-by: Karthik Jayakumar <[email protected]>
Karthik Jayakumar 4 лет назад
Родитель
Сommit
2c67e897da

+ 2 - 1
drivers/cam_cpas/cam_cpas_hw.c

@@ -15,6 +15,7 @@
 #include "cam_cpas_soc.h"
 #include "cam_req_mgr_dev.h"
 #include "cam_smmu_api.h"
+#include "cam_compat.h"
 
 static uint cam_min_camnoc_ib_bw;
 module_param(cam_min_camnoc_ib_bw, uint, 0644);
@@ -1120,7 +1121,7 @@ static int cam_cpas_hw_update_axi_vote(struct cam_hw_info *cpas_hw,
 	cam_cpas_update_monitor_array(cpas_hw, "CPAS AXI post-update",
 		client_indx);
 unlock_client:
-	kzfree(axi_vote);
+	cam_free_clear((void *)axi_vote);
 	axi_vote = NULL;
 	mutex_unlock(&cpas_core->client_mutex[client_indx]);
 	mutex_unlock(&cpas_hw->hw_mutex);

+ 2 - 1
drivers/cam_icp/hfi.c

@@ -19,6 +19,7 @@
 #include "hfi_intf.h"
 #include "cam_icp_hw_mgr_intf.h"
 #include "cam_debug_util.h"
+#include "cam_compat.h"
 
 #define HFI_VERSION_INFO_MAJOR_VAL  1
 #define HFI_VERSION_INFO_MINOR_VAL  1
@@ -882,7 +883,7 @@ void cam_hfi_deinit(void)
 	g_hfi->cmd_q_state = false;
 	g_hfi->msg_q_state = false;
 
-	kzfree(g_hfi);
+	cam_free_clear((void *)g_hfi);
 	g_hfi = NULL;
 
 err:

+ 3 - 1
drivers/cam_isp/isp_hw_mgr/cam_tfe_hw_mgr.c

@@ -8,6 +8,7 @@
 #include <linux/uaccess.h>
 #include <linux/debugfs.h>
 #include <media/cam_tfe.h>
+
 #include "cam_smmu_api.h"
 #include "cam_req_mgr_workq.h"
 #include "cam_isp_hw_mgr_intf.h"
@@ -25,6 +26,7 @@
 #include "cam_compat.h"
 #include "cam_req_mgr_debug.h"
 #include "cam_trace.h"
+#include "cam_compat.h"
 
 #define CAM_TFE_HW_ENTRIES_MAX  20
 #define CAM_TFE_HW_CONFIG_TIMEOUT 60
@@ -2428,7 +2430,7 @@ static int cam_isp_tfe_blob_bw_update(
 	}
 
 end:
-	kzfree(bw_upd_args);
+	cam_free_clear((void *)bw_upd_args);
 	bw_upd_args = NULL;
 	return rc;
 }

+ 3 - 1
drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_core.c

@@ -9,6 +9,7 @@
 #include <linux/timer.h>
 #include <linux/ratelimit.h>
 #include <media/cam_tfe.h>
+
 #include "cam_cdm_util.h"
 #include "cam_tasklet_util.h"
 #include "cam_isp_hw_mgr_intf.h"
@@ -17,6 +18,7 @@
 #include "cam_tfe_bus.h"
 #include "cam_debug_util.h"
 #include "cam_cpas_api.h"
+#include "cam_compat.h"
 
 static const char drv_name[] = "tfe";
 
@@ -1163,7 +1165,7 @@ static int cam_tfe_top_set_axi_bw_vote(
 	}
 
 free_mem:
-	kzfree(agg_vote);
+	cam_free_clear((void *)agg_vote);
 	agg_vote = NULL;
 	return rc;
 }

+ 20 - 19
drivers/cam_ope/ope_hw_mgr/cam_ope_hw_mgr.c

@@ -40,6 +40,7 @@
 #include "cam_cdm_util.h"
 #include "cam_cdm.h"
 #include "ope_dev_intf.h"
+#include "cam_compat.h"
 
 static struct cam_ope_hw_mgr *ope_hw_mgr;
 
@@ -180,7 +181,7 @@ static void cam_ope_free_io_config(struct cam_ope_request *req)
 	for (i = 0; i < OPE_MAX_BATCH_SIZE; i++) {
 		for (j = 0; j < OPE_MAX_IO_BUFS; j++) {
 			if (req->io_buf[i][j]) {
-				kzfree(req->io_buf[i][j]);
+				cam_free_clear((void *)req->io_buf[i][j]);
 				req->io_buf[i][j] = NULL;
 			}
 		}
@@ -1686,10 +1687,10 @@ static void cam_ope_ctx_cdm_callback(uint32_t handle, void *userdata,
 
 	buf_data.request_id = ope_req->request_id;
 	ope_req->request_id = 0;
-	kzfree(ctx->req_list[cookie]->cdm_cmd);
+	cam_free_clear((void *)ctx->req_list[cookie]->cdm_cmd);
 	ctx->req_list[cookie]->cdm_cmd = NULL;
 	cam_ope_free_io_config(ctx->req_list[cookie]);
-	kzfree(ctx->req_list[cookie]);
+	cam_free_clear((void *)ctx->req_list[cookie]);
 	ctx->req_list[cookie] = NULL;
 	clear_bit(cookie, ctx->bitmap);
 	ctx->ctxt_event_cb(ctx->context_priv, evt_id, &buf_data);
@@ -2761,7 +2762,7 @@ static int cam_ope_mgr_acquire_hw(void *hw_priv, void *hw_acquire_args)
 	return rc;
 
 free_bw_update:
-	kzfree(bw_update);
+	cam_free_clear((void *)bw_update);
 	bw_update = NULL;
 ope_clk_update_failed:
 	ope_dev_release.ctx_id = ctx_id;
@@ -2805,7 +2806,7 @@ cdm_stream_on_failure:
 
 cdm_acquire_failed:
 free_cdm_acquire:
-	kzfree(cdm_acquire);
+	cam_free_clear((void *)cdm_acquire);
 	cdm_acquire = NULL;
 end:
 	args->ctxt_to_hw_map = NULL;
@@ -2917,11 +2918,11 @@ static int cam_ope_mgr_release_ctx(struct cam_ope_hw_mgr *hw_mgr, int ctx_id)
 			continue;
 
 		if (hw_mgr->ctx[ctx_id].req_list[i]->cdm_cmd) {
-			kzfree(hw_mgr->ctx[ctx_id].req_list[i]->cdm_cmd);
+			cam_free_clear((void *)hw_mgr->ctx[ctx_id].req_list[i]->cdm_cmd);
 			hw_mgr->ctx[ctx_id].req_list[i]->cdm_cmd = NULL;
 		}
 		cam_ope_free_io_config(hw_mgr->ctx[ctx_id].req_list[i]);
-		kzfree(hw_mgr->ctx[ctx_id].req_list[i]);
+		cam_free_clear((void *)hw_mgr->ctx[ctx_id].req_list[i]);
 		hw_mgr->ctx[ctx_id].req_list[i] = NULL;
 		clear_bit(i, hw_mgr->ctx[ctx_id].bitmap);
 	}
@@ -3289,10 +3290,10 @@ static int cam_ope_mgr_prepare_hw_update(void *hw_priv,
 	return rc;
 
 end:
-	kzfree(ctx_data->req_list[request_idx]->cdm_cmd);
+	cam_free_clear((void *)ctx_data->req_list[request_idx]->cdm_cmd);
 	ctx_data->req_list[request_idx]->cdm_cmd = NULL;
 req_cdm_mem_alloc_failed:
-	kzfree(ctx_data->req_list[request_idx]);
+	cam_free_clear((void *)ctx_data->req_list[request_idx]);
 	ctx_data->req_list[request_idx] = NULL;
 req_mem_alloc_failed:
 	clear_bit(request_idx, ctx_data->bitmap);
@@ -3317,10 +3318,10 @@ static int cam_ope_mgr_handle_config_err(
 
 	req_idx = ope_req->req_idx;
 	ope_req->request_id = 0;
-	kzfree(ctx_data->req_list[req_idx]->cdm_cmd);
+	cam_free_clear((void *)ctx_data->req_list[req_idx]->cdm_cmd);
 	ctx_data->req_list[req_idx]->cdm_cmd = NULL;
 	cam_ope_free_io_config(ctx_data->req_list[req_idx]);
-	kzfree(ctx_data->req_list[req_idx]);
+	cam_free_clear((void *)ctx_data->req_list[req_idx]);
 	ctx_data->req_list[req_idx] = NULL;
 	clear_bit(req_idx, ctx_data->bitmap);
 
@@ -3588,10 +3589,10 @@ static int cam_ope_mgr_flush_req(struct cam_ope_ctx *ctx_data,
 			continue;
 
 		ctx_data->req_list[idx]->request_id = 0;
-		kzfree(ctx_data->req_list[idx]->cdm_cmd);
+		cam_free_clear((void *)ctx_data->req_list[idx]->cdm_cmd);
 		ctx_data->req_list[idx]->cdm_cmd = NULL;
 		cam_ope_free_io_config(ctx_data->req_list[idx]);
-		kzfree(ctx_data->req_list[idx]);
+		cam_free_clear((void *)ctx_data->req_list[idx]);
 		ctx_data->req_list[idx] = NULL;
 		clear_bit(idx, ctx_data->bitmap);
 	}
@@ -3621,10 +3622,10 @@ static int cam_ope_mgr_flush_all(struct cam_ope_ctx *ctx_data,
 			continue;
 
 		ctx_data->req_list[i]->request_id = 0;
-		kzfree(ctx_data->req_list[i]->cdm_cmd);
+		cam_free_clear((void *)ctx_data->req_list[i]->cdm_cmd);
 		ctx_data->req_list[i]->cdm_cmd = NULL;
 		cam_ope_free_io_config(ctx_data->req_list[i]);
-		kzfree(ctx_data->req_list[i]);
+		cam_free_clear((void *)ctx_data->req_list[i]);
 		ctx_data->req_list[i] = NULL;
 		clear_bit(i, ctx_data->bitmap);
 	}
@@ -4117,24 +4118,24 @@ secure_hdl_failed:
 	cam_smmu_destroy_handle(ope_hw_mgr->iommu_hdl);
 	ope_hw_mgr->iommu_hdl = -1;
 ope_get_hdl_failed:
-	kzfree(ope_hw_mgr->ctx_bitmap);
+	cam_free_clear((void *)ope_hw_mgr->ctx_bitmap);
 	ope_hw_mgr->ctx_bitmap = NULL;
 	ope_hw_mgr->ctx_bitmap_size = 0;
 	ope_hw_mgr->ctx_bits = 0;
 ctx_bitmap_alloc_failed:
-	kzfree(ope_hw_mgr->devices[OPE_DEV_OPE]);
+	cam_free_clear((void *)ope_hw_mgr->devices[OPE_DEV_OPE]);
 	ope_hw_mgr->devices[OPE_DEV_OPE] = NULL;
 dev_init_failed:
 ope_ctx_bitmap_failed:
 	mutex_destroy(&ope_hw_mgr->hw_mgr_mutex);
 	for (j = i - 1; j >= 0; j--) {
 		mutex_destroy(&ope_hw_mgr->ctx[j].ctx_mutex);
-		kzfree(ope_hw_mgr->ctx[j].bitmap);
+		cam_free_clear((void *)ope_hw_mgr->ctx[j].bitmap);
 		ope_hw_mgr->ctx[j].bitmap = NULL;
 		ope_hw_mgr->ctx[j].bitmap_size = 0;
 		ope_hw_mgr->ctx[j].bits = 0;
 	}
-	kzfree(ope_hw_mgr);
+	cam_free_clear((void *)ope_hw_mgr);
 	ope_hw_mgr = NULL;
 
 	return rc;

+ 3 - 1
drivers/cam_ope/ope_hw_mgr/ope_hw/ope_core.c

@@ -13,6 +13,7 @@
 #include <linux/timer.h>
 #include <linux/iopoll.h>
 #include <media/cam_ope.h>
+
 #include "cam_io_util.h"
 #include "cam_hw.h"
 #include "cam_hw_intf.h"
@@ -27,6 +28,7 @@
 #include "cam_cdm_util.h"
 #include "ope_bus_rd.h"
 #include "ope_bus_wr.h"
+#include "cam_compat.h"
 
 static int cam_ope_caps_vote(struct cam_ope_device_core_info *core_info,
 	struct cam_ope_dev_bw_update *cpas_vote)
@@ -250,7 +252,7 @@ enable_soc_resource_failed:
 	else
 		core_info->cpas_start = false;
 free_cpas_vote:
-	kzfree(cpas_vote);
+	cam_free_clear((void *)cpas_vote);
 	cpas_vote = NULL;
 end:
 	return rc;

+ 1 - 1
drivers/cam_sensor_module/cam_ois/cam_ois_core.c

@@ -5,7 +5,7 @@
 
 #include <linux/module.h>
 #include <linux/firmware.h>
-#include <linux/dma-contiguous.h>
+
 #include <cam_sensor_cmn_header.h>
 #include "cam_ois_core.h"
 #include "cam_ois_soc.h"

+ 0 - 1
drivers/cam_sensor_module/cam_sensor_io/cam_sensor_spi.c

@@ -3,7 +3,6 @@
  * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  */
 
-#include <linux/dma-contiguous.h>
 #include "cam_sensor_spi.h"
 #include "cam_debug_util.h"
 

+ 15 - 2
drivers/cam_utils/cam_compat.c

@@ -5,13 +5,14 @@
 
 #include <linux/dma-mapping.h>
 #include <linux/of_address.h>
+#include <linux/slab.h>
 
 #include "cam_compat.h"
 #include "cam_debug_util.h"
 #include "cam_cpas_api.h"
 #include "camera_main.h"
 
-#if KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
 int cam_reserve_icp_fw(struct cam_fw_alloc_info *icp_fw, size_t fw_length)
 {
 	int rc = 0;
@@ -189,6 +190,18 @@ static int camera_platform_compare_dev(struct device *dev, void *data)
 }
 #endif
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)
+void cam_free_clear(const void * ptr)
+{
+	kfree_sensitive(ptr);
+}
+#else
+void cam_free_clear(const void * ptr)
+{
+	kzfree(ptr);
+}
+#endif
+
 /* Callback to compare device from match list before adding as component */
 static inline int camera_component_compare_dev(struct device *dev, void *data)
 {
@@ -209,7 +222,7 @@ int camera_component_match_add_drivers(struct device *master_dev,
 	}
 
 	for (i = 0; i < ARRAY_SIZE(cam_component_drivers); i++) {
-#if KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
 		struct device_driver const *drv =
 			&cam_component_drivers[i]->driver;
 		const void *drv_ptr = (const void *)drv;

+ 8 - 1
drivers/cam_utils/cam_compat.h

@@ -13,7 +13,13 @@
 #include "cam_csiphy_dev.h"
 #include "cam_cpastop_hw.h"
 
-#if KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 7, 0)
+
+#define VFL_TYPE_VIDEO VFL_TYPE_GRABBER
+
+#endif
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
 
 #include <linux/msm_ion.h>
 #include <linux/ion.h>
@@ -41,5 +47,6 @@ int camera_component_match_add_drivers(struct device *master_dev,
 	struct component_match **match_list);
 int cam_csiphy_notify_secure_mode(struct csiphy_device *csiphy_dev,
 	bool protect, int32_t offset);
+void cam_free_clear(const void *);
 
 #endif /* _CAM_COMPAT_H_ */