RE: [PATCH v5 4/5] typec: tcpm: Represent source supply through power_supply
From: Adam Thomson
Date: Thu Mar 22 2018 - 06:40:16 EST
On 22 March 2018 04:09, Guenter Roeck wrote:
> > +static int tcpm_psy_set_prop(struct power_supply *psy,
> > + enum power_supply_property psp,
> > + const union power_supply_propval *val)
> > +{
> > + struct tcpm_port *port = power_supply_get_drvdata(psy);
> > + int ret = 0;
> > +
> > + switch (psp) {
> > + case POWER_SUPPLY_PROP_ONLINE:
> > + ret = tcpm_psy_set_online(port, val);
> > + break;
> > + case POWER_SUPPLY_PROP_VOLTAGE_NOW:
> > + if ((val->intval < (port->pps_data.min_volt * 1000)) ||
> > + (val->intval > (port->pps_data.max_volt * 1000)))
> > + ret = -EINVAL;
> > + else
> > + ret = tcpm_pps_set_out_volt(port, (val->intval / 1000));
> > + break;
> > + case POWER_SUPPLY_PROP_CURRENT_NOW:
> > + if (val->intval > (port->pps_data.max_curr * 1000))
> > + ret = -EINVAL;
> > + else
> > + ret = tcpm_pps_set_op_curr(port, (val->intval / 1000));
>
> I am really not a friend of excessive ( ).
Yes, I got that. :) I am of the opinion that they should be used to enforce
precedence. This to me is good coding practice and makes it unambiguous for the
reader. That's why I use them as above. Do you think the above uses make it
harder to understand or more difficult to maintain?