[PATCH v3 02/11] power: charger-manager: don't write through desc->properties

From: MichaÅ MirosÅaw
Date: Fri Apr 03 2020 - 16:20:44 EST


psy_desc->properties will become pointer to const. Avoid writing
through the pointer to enable constification of the tables elsewhere.

Signed-off-by: MichaÅ MirosÅaw <mirq-linux@xxxxxxxxxxxx>
---
v3: initial version
---
drivers/power/supply/charger-manager.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c
index 887f5bb879e5..7ecb82107efb 100644
--- a/drivers/power/supply/charger-manager.c
+++ b/drivers/power/supply/charger-manager.c
@@ -1425,15 +1425,18 @@ static int cm_init_thermal_data(struct charger_manager *cm,
struct power_supply *fuel_gauge)
{
struct charger_desc *desc = cm->desc;
+ enum power_supply_property *props;
union power_supply_propval val;
int ret;

+ props = (void *)cm->charger_psy_desc.properties;
+
/* Verify whether fuel gauge provides battery temperature */
ret = power_supply_get_property(fuel_gauge,
POWER_SUPPLY_PROP_TEMP, &val);

if (!ret) {
- cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
+ props[cm->charger_psy_desc.num_properties] =
POWER_SUPPLY_PROP_TEMP;
cm->charger_psy_desc.num_properties++;
cm->desc->measure_battery_temp = true;
@@ -1446,7 +1449,7 @@ static int cm_init_thermal_data(struct charger_manager *cm,
return PTR_ERR(cm->tzd_batt);

/* Use external thermometer */
- cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
+ props[cm->charger_psy_desc.num_properties] =
POWER_SUPPLY_PROP_TEMP_AMBIENT;
cm->charger_psy_desc.num_properties++;
cm->desc->measure_battery_temp = true;
@@ -1622,6 +1625,7 @@ static int charger_manager_probe(struct platform_device *pdev)
union power_supply_propval val;
struct power_supply *fuel_gauge;
struct power_supply_config psy_cfg = {};
+ enum power_supply_property *props;

if (IS_ERR(desc)) {
dev_err(&pdev->dev, "No platform data (desc) found\n");
@@ -1717,7 +1721,7 @@ static int charger_manager_probe(struct platform_device *pdev)
cm->charger_psy_desc.name = cm->psy_name_buf;

/* Allocate for psy properties because they may vary */
- cm->charger_psy_desc.properties =
+ cm->charger_psy_desc.properties = props =
devm_kcalloc(&pdev->dev,
ARRAY_SIZE(default_charger_props) +
NUM_CHARGER_PSY_OPTIONAL,
@@ -1725,7 +1729,7 @@ static int charger_manager_probe(struct platform_device *pdev)
if (!cm->charger_psy_desc.properties)
return -ENOMEM;

- memcpy(cm->charger_psy_desc.properties, default_charger_props,
+ memcpy(props, default_charger_props,
sizeof(enum power_supply_property) *
ARRAY_SIZE(default_charger_props));

@@ -1738,14 +1742,14 @@ static int charger_manager_probe(struct platform_device *pdev)
}
if (!power_supply_get_property(fuel_gauge,
POWER_SUPPLY_PROP_CHARGE_NOW, &val)) {
- cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
+ props[cm->charger_psy_desc.num_properties] =
POWER_SUPPLY_PROP_CHARGE_NOW;
cm->charger_psy_desc.num_properties++;
}
if (!power_supply_get_property(fuel_gauge,
POWER_SUPPLY_PROP_CURRENT_NOW,
&val)) {
- cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] =
+ props[cm->charger_psy_desc.num_properties] =
POWER_SUPPLY_PROP_CURRENT_NOW;
cm->charger_psy_desc.num_properties++;
}
--
2.20.1