Message ID | a529e64edb81a4795fe0b6480f1e4051bed1b099.1585944770.git.mirq-linux@rere.qmqm.pl (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
Series | extensions and fixes | expand |
Hi, On Fri, Apr 03, 2020 at 10:20:31PM +0200, Michał Mirosław wrote: > 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@rere.qmqm.pl> > --- For patches 1-3 I used my version, that I wrote in parallel while reviewing a different patch series. It is slightly different, but achieves the same goal. -- Sebastian
On Fri, May 01, 2020 at 02:38:49PM +0200, Sebastian Reichel wrote: > Hi, > > On Fri, Apr 03, 2020 at 10:20:31PM +0200, Michał Mirosław wrote: > > 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@rere.qmqm.pl> > For patches 1-3 I used my version, that I wrote in parallel while > reviewing a different patch series. It is slightly different, but > achieves the same goal. There is a bug in the tree now regarding use of num_properties in charger-manager. Following patch should fix it. Best Regards, Michał Mirosław diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index a71e2ee81423..2ef53dc1f2fb 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -1740,14 +1740,14 @@ static int charger_manager_probe(struct platform_device *pdev) } if (!power_supply_get_property(fuel_gauge, POWER_SUPPLY_PROP_CHARGE_NOW, &val)) { - properties[cm->charger_psy_desc.num_properties] = + properties[num_properties] = POWER_SUPPLY_PROP_CHARGE_NOW; num_properties++; } if (!power_supply_get_property(fuel_gauge, POWER_SUPPLY_PROP_CURRENT_NOW, &val)) { - properties[cm->charger_psy_desc.num_properties] = + properties[num_properties] = POWER_SUPPLY_PROP_CURRENT_NOW; num_properties++; }
Hi, On Fri, May 01, 2020 at 03:30:08PM +0200, Michał Mirosław wrote: > On Fri, May 01, 2020 at 02:38:49PM +0200, Sebastian Reichel wrote: > > Hi, > > > > On Fri, Apr 03, 2020 at 10:20:31PM +0200, Michał Mirosław wrote: > > > 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@rere.qmqm.pl> > > For patches 1-3 I used my version, that I wrote in parallel while > > reviewing a different patch series. It is slightly different, but > > achieves the same goal. > > There is a bug in the tree now regarding use of num_properties > in charger-manager. Following patch should fix it. Thanks, I folded this into the charger-manager patch. -- Sebastian > Best Regards, > Michał Mirosław > > diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c > index a71e2ee81423..2ef53dc1f2fb 100644 > --- a/drivers/power/supply/charger-manager.c > +++ b/drivers/power/supply/charger-manager.c > @@ -1740,14 +1740,14 @@ static int charger_manager_probe(struct platform_device *pdev) > } > if (!power_supply_get_property(fuel_gauge, > POWER_SUPPLY_PROP_CHARGE_NOW, &val)) { > - properties[cm->charger_psy_desc.num_properties] = > + properties[num_properties] = > POWER_SUPPLY_PROP_CHARGE_NOW; > num_properties++; > } > if (!power_supply_get_property(fuel_gauge, > POWER_SUPPLY_PROP_CURRENT_NOW, > &val)) { > - properties[cm->charger_psy_desc.num_properties] = > + properties[num_properties] = > POWER_SUPPLY_PROP_CURRENT_NOW; > num_properties++; > }
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++; }
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@rere.qmqm.pl> --- v3: initial version --- drivers/power/supply/charger-manager.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)