From 21fea5466493e99cd4cd9e7a72479a042dac678e Mon Sep 17 00:00:00 2001 From: shiwgupt Date: Thu, 25 Feb 2021 16:32:33 +0530 Subject: [PATCH] msm: camera: sensor: Change regulator get,put to devres entry This change modifies regulator_get, regulator_put to devres entry. Devres is linked list of arbitrarily sized memory areas associated with a struct device. Each devres entry is associated with a release function. All devres entries are released on driver detach. This avoids potential leaking of resources on driver detach or having half broken failure path implementation in probe call which would leak resources when failure occurs. CRs-Fixed: 2890861 Change-Id: Ibd46bc37bd6e31aeb2a5ea90ed75a1f596b57bf9 Signed-off-by: shiwgupt --- .../cam_actuator/cam_actuator_soc.c | 6 ++- .../cam_eeprom/cam_eeprom_soc.c | 4 +- .../cam_sensor_module/cam_ois/cam_ois_soc.c | 6 ++- .../cam_sensor/cam_sensor_soc.c | 7 +++- .../cam_sensor_utils/cam_sensor_util.c | 38 ++++++++++--------- .../cam_sensor_utils/cam_sensor_util.h | 5 ++- 6 files changed, 44 insertions(+), 22 deletions(-) diff --git a/drivers/cam_sensor_module/cam_actuator/cam_actuator_soc.c b/drivers/cam_sensor_module/cam_actuator/cam_actuator_soc.c index 0248effdfbe4..cb852423a228 100644 --- a/drivers/cam_sensor_module/cam_actuator/cam_actuator_soc.c +++ b/drivers/cam_sensor_module/cam_actuator/cam_actuator_soc.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. */ #include @@ -56,6 +56,10 @@ int32_t cam_actuator_parse_dt(struct cam_actuator_ctrl_t *a_ctrl, CAM_DBG(CAM_ACTUATOR, "cci-device %d", a_ctrl->cci_num); } + rc = cam_sensor_util_regulator_powerup(soc_info); + if (rc < 0) + return rc; + if (!soc_info->gpio_data) { CAM_DBG(CAM_ACTUATOR, "No GPIO found"); rc = 0; diff --git a/drivers/cam_sensor_module/cam_eeprom/cam_eeprom_soc.c b/drivers/cam_sensor_module/cam_eeprom/cam_eeprom_soc.c index 33f80b0c9716..c725beb0af3f 100644 --- a/drivers/cam_sensor_module/cam_eeprom/cam_eeprom_soc.c +++ b/drivers/cam_sensor_module/cam_eeprom/cam_eeprom_soc.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. */ #include @@ -380,5 +380,7 @@ int cam_eeprom_parse_dt(struct cam_eeprom_ctrl_t *e_ctrl) } } + rc = cam_sensor_util_regulator_powerup(soc_info); + return rc; } diff --git a/drivers/cam_sensor_module/cam_ois/cam_ois_soc.c b/drivers/cam_sensor_module/cam_ois/cam_ois_soc.c index 9c14d87e233d..510c81d9e9f3 100644 --- a/drivers/cam_sensor_module/cam_ois/cam_ois_soc.c +++ b/drivers/cam_sensor_module/cam_ois/cam_ois_soc.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. */ #include @@ -41,6 +41,10 @@ static int cam_ois_get_dt_data(struct cam_ois_ctrl_t *o_ctrl) return rc; } + rc = cam_sensor_util_regulator_powerup(soc_info); + if (rc < 0) + return rc; + if (!soc_info->gpio_data) { CAM_INFO(CAM_OIS, "No GPIO found"); return 0; diff --git a/drivers/cam_sensor_module/cam_sensor/cam_sensor_soc.c b/drivers/cam_sensor_module/cam_sensor/cam_sensor_soc.c index 2c25ee0aa6f0..d5cfe48223a5 100644 --- a/drivers/cam_sensor_module/cam_sensor/cam_sensor_soc.c +++ b/drivers/cam_sensor_module/cam_sensor/cam_sensor_soc.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. */ #include @@ -268,6 +268,11 @@ int32_t cam_sensor_parse_dt(struct cam_sensor_ctrl_t *s_ctrl) return rc; } } + + rc = cam_sensor_util_regulator_powerup(soc_info); + if (rc < 0) + return rc; + rc = msm_sensor_init_default_params(s_ctrl); if (rc < 0) { CAM_ERR(CAM_SENSOR, diff --git a/drivers/cam_sensor_module/cam_sensor_utils/cam_sensor_util.c b/drivers/cam_sensor_module/cam_sensor_utils/cam_sensor_util.c index 4dde033a2fbd..4147c1dc7409 100644 --- a/drivers/cam_sensor_module/cam_sensor_utils/cam_sensor_util.c +++ b/drivers/cam_sensor_module/cam_sensor_utils/cam_sensor_util.c @@ -64,6 +64,27 @@ int32_t cam_sensor_util_get_current_qtimer_ns(uint64_t *qtime_ns) return rc; } +int32_t cam_sensor_util_regulator_powerup(struct cam_hw_soc_info *soc_info) +{ + int32_t i, rc = 0; + /* Initialize regulators to default parameters */ + for (i = 0; i < soc_info->num_rgltr; i++) { + soc_info->rgltr[i] = devm_regulator_get(soc_info->dev, + soc_info->rgltr_name[i]); + if (IS_ERR_OR_NULL(soc_info->rgltr[i])) { + rc = PTR_ERR(soc_info->rgltr[i]); + rc = rc ? rc : -EINVAL; + CAM_ERR(CAM_ACTUATOR, "get failed for regulator %s %d", + soc_info->rgltr_name[i], rc); + return rc; + } + CAM_DBG(CAM_ACTUATOR, "get for regulator %s", + soc_info->rgltr_name[i]); + } + + return rc; +} + int32_t delete_request(struct i2c_settings_array *i2c_array) { struct i2c_settings_list *i2c_list = NULL, *i2c_next = NULL; @@ -1974,10 +1995,6 @@ static int cam_config_mclk_reg(struct cam_sensor_power_ctrl_t *ctrl, ps->data[0] = soc_info->rgltr[j]; - - regulator_put( - soc_info->rgltr[j]); - soc_info->rgltr[j] = NULL; } } } @@ -2057,11 +2074,6 @@ int cam_sensor_core_power_up(struct cam_sensor_power_ctrl_t *ctrl, CAM_DBG(CAM_SENSOR, "Enable cam_clk: %d", j); - soc_info->rgltr[j] = - regulator_get( - soc_info->dev, - soc_info->rgltr_name[j]); - if (IS_ERR_OR_NULL( soc_info->rgltr[j])) { rc = PTR_ERR( @@ -2156,9 +2168,6 @@ int cam_sensor_core_power_up(struct cam_sensor_power_ctrl_t *ctrl, CAM_DBG(CAM_SENSOR, "Enable Regulator"); vreg_idx = power_setting->seq_val; - soc_info->rgltr[vreg_idx] = - regulator_get(soc_info->dev, - soc_info->rgltr_name[vreg_idx]); if (IS_ERR_OR_NULL( soc_info->rgltr[vreg_idx])) { rc = PTR_ERR(soc_info->rgltr[vreg_idx]); @@ -2281,8 +2290,6 @@ power_up_failed: power_setting->data[0] = soc_info->rgltr[vreg_idx]; - regulator_put(soc_info->rgltr[vreg_idx]); - soc_info->rgltr[vreg_idx] = NULL; } else { CAM_ERR(CAM_SENSOR, "seq_val:%d > num_vreg: %d", power_setting->seq_val, num_vreg); @@ -2449,9 +2456,6 @@ int cam_sensor_util_power_down(struct cam_sensor_power_ctrl_t *ctrl, } ps->data[0] = soc_info->rgltr[ps->seq_val]; - regulator_put( - soc_info->rgltr[ps->seq_val]); - soc_info->rgltr[ps->seq_val] = NULL; } else { CAM_ERR(CAM_SENSOR, "seq_val:%d > num_vreg: %d", diff --git a/drivers/cam_sensor_module/cam_sensor_utils/cam_sensor_util.h b/drivers/cam_sensor_module/cam_sensor_utils/cam_sensor_util.h index 66731008826b..4fc0ee857ae9 100644 --- a/drivers/cam_sensor_module/cam_sensor_utils/cam_sensor_util.h +++ b/drivers/cam_sensor_module/cam_sensor_utils/cam_sensor_util.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. */ #ifndef _CAM_SENSOR_UTIL_H_ @@ -41,6 +41,9 @@ int msm_camera_pinctrl_init int32_t cam_sensor_util_get_current_qtimer_ns(uint64_t *qtime_ns); +int32_t cam_sensor_util_regulator_powerup( + struct cam_hw_soc_info *soc_info); + int32_t cam_sensor_util_write_qtimer_to_io_buffer( struct cam_buf_io_cfg *io_cfg);