Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f11d5280 authored by Swinder Pal Singh Juneja's avatar Swinder Pal Singh Juneja Committed by hecaiqiang
Browse files

Optimize the camera memory allocation

Change-Id: I26c7fa4190174c7812644d2e1a528f18e0b1bd4d
(cherry picked from commit 58310e8b077ca3dd6eaf3b48e819d110da50bef2)
parent 11b42f53
Loading
Loading
Loading
Loading
+28 −18
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
 */

#include <linux/kernel.h>
#include <linux/vmalloc.h>
#include "cam_sensor_util.h"
#include <cam_mem_mgr.h>
#include "cam_res_mgr_api.h"
@@ -26,7 +27,6 @@ static struct i2c_settings_list*
		uint32_t size)
{
	struct i2c_settings_list *tmp;
	int  retry_time = 3;
	tmp = (struct i2c_settings_list *)
		kzalloc(sizeof(struct i2c_settings_list), GFP_KERNEL);

@@ -36,24 +36,27 @@ static struct i2c_settings_list*
	else
		return NULL;

	tmp->i2c_settings.reg_setting = (struct cam_sensor_i2c_reg_array *)
	if ((sizeof(struct cam_sensor_i2c_reg_array) * size) < PAGE_SIZE) {
		tmp->i2c_settings.reg_setting =
			(struct cam_sensor_i2c_reg_array *)
			kcalloc(size, sizeof(struct cam_sensor_i2c_reg_array),
			GFP_KERNEL);

	while (tmp->i2c_settings.reg_setting == NULL && retry_time > 0) {
		msleep(5);
		tmp->i2c_settings.reg_setting = (struct cam_sensor_i2c_reg_array *)
			kcalloc(size, sizeof(struct cam_sensor_i2c_reg_array),
				GFP_KERNEL);
		retry_time--;
		CAM_ERR(CAM_SENSOR, "fail to alloc memory, retry = %d", retry_time);
		if (tmp->i2c_settings.reg_setting == NULL) {
			list_del(&(tmp->list));
			kfree(tmp);
			return NULL;
		}

	} else {
		tmp->i2c_settings.reg_setting =
			(struct cam_sensor_i2c_reg_array *)
			vzalloc(sizeof(struct cam_sensor_i2c_reg_array) *
				size);
		if (tmp->i2c_settings.reg_setting == NULL) {
			list_del(&(tmp->list));
			kfree(tmp);
			return NULL;
		}
	}
	tmp->i2c_settings.size = size;

	return tmp;
@@ -71,7 +74,14 @@ int32_t delete_request(struct i2c_settings_array *i2c_array)

	list_for_each_entry_safe(i2c_list, i2c_next,
		&(i2c_array->list_head), list) {

		if ((sizeof(struct cam_sensor_i2c_reg_array) *
			i2c_list->i2c_settings.size) < PAGE_SIZE) {
			kfree(i2c_list->i2c_settings.reg_setting);
		} else {
			vfree(i2c_list->i2c_settings.reg_setting);
		}

		list_del(&(i2c_list->list));
		kfree(i2c_list);
	}