Parcourir la source

Merge "msm: camera: icp: Avoid resource leak during comp bind failure" into camera-kernel.lnx.7.0

Camera Software Integration il y a 1 an
Parent
commit
352ce6b61d
1 fichiers modifiés avec 15 ajouts et 13 suppressions
  1. 15 13
      drivers/cam_icp/cam_icp_subdev.c

+ 15 - 13
drivers/cam_icp/cam_icp_subdev.c

@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022,2024 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/delay.h>
@@ -251,11 +251,8 @@ const struct v4l2_subdev_internal_ops cam_icp_subdev_internal_ops = {
 
 static inline int cam_icp_subdev_clean_up(uint32_t device_idx)
 {
-	struct cam_icp_subdev *icp_subdev;
-
-	icp_subdev = g_icp_dev[device_idx];
-	icp_subdev->node = NULL;
-	icp_subdev->open_cnt = 0;
+	kfree(g_icp_dev[device_idx]);
+	g_icp_dev[device_idx] = NULL;
 
 	return 0;
 }
@@ -297,13 +294,6 @@ static int cam_icp_component_bind(struct device *dev,
 	else
 		subdev_name = cam_icp_subdev_name_arr[device_idx];
 
-	icp_dev = kzalloc(sizeof(struct cam_icp_subdev), GFP_KERNEL);
-	if (!icp_dev) {
-		CAM_ERR(CAM_ICP,
-			"Unable to allocate memory for icp device:%s size:%llu",
-			pdev->name, sizeof(struct cam_icp_subdev));
-		return -ENOMEM;
-	}
 
 	mutex_lock(&g_dev_lock);
 	if (g_icp_dev[device_idx]) {
@@ -314,6 +304,17 @@ static int cam_icp_component_bind(struct device *dev,
 		mutex_unlock(&g_dev_lock);
 		goto probe_fail;
 	}
+	mutex_unlock(&g_dev_lock);
+
+	icp_dev = kzalloc(sizeof(struct cam_icp_subdev), GFP_KERNEL);
+	if (!icp_dev) {
+		CAM_ERR(CAM_ICP,
+			"Unable to allocate memory for icp device:%s size:%llu",
+			pdev->name, sizeof(struct cam_icp_subdev));
+		return -ENOMEM;
+	}
+
+	mutex_lock(&g_dev_lock);
 	g_icp_dev[device_idx] = icp_dev;
 	mutex_unlock(&g_dev_lock);
 
@@ -373,6 +374,7 @@ ctx_fail:
 		cam_icp_context_deinit(&icp_dev->ctx_icp[i]);
 	cam_icp_hw_mgr_deinit(device_idx);
 hw_init_fail:
+	cam_node_deinit(icp_dev->node);
 	cam_subdev_remove(&icp_dev->sd);
 probe_fail:
 	cam_icp_subdev_clean_up(device_idx);