lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20160913191241.GD62872@google.com>
Date:   Tue, 13 Sep 2016 12:12:41 -0700
From:   Matthias Kaehlcke <mka@...omium.org>
To:     Mark Brown <broonie@...nel.org>
Cc:     lgirdwood@...il.com, Douglas Anderson <dianders@...omium.org>,
        briannorris@...omium.org, javier@...hile0.org, robh+dt@...nel.org,
        mark.rutland@....com, linux-kernel@...r.kernel.org,
        devicetree@...r.kernel.org
Subject: Re: [PATCH v4 1/4] regulator: Add set_voltage_time op

El Mon, Sep 12, 2016 at 06:18:31PM -0700 Matthias Kaehlcke ha dit:

> El Tue, Sep 13, 2016 at 12:57:58AM +0100 Mark Brown ha dit:
> 
> > On Mon, Sep 12, 2016 at 04:18:51PM -0700, Matthias Kaehlcke wrote:
> > > El Mon, Sep 12, 2016 at 07:32:30PM +0100 Mark Brown ha dit:
> > > > On Tue, Sep 06, 2016 at 12:03:15PM -0700, Matthias Kaehlcke wrote:
...
> > > > Why were the gotos there?
> > 
> > > Not sure how to interpret your question. Would you prefer no to use
> > > gotos, should the notification be skipped in case the voltage is not
> > > changed, do you expect a comment, ...?
> > 
> > I mean I couldn't tell why a goto was a good idea for what seemed like
> > perfectly normal conditional logic.  Either I couldn't tell because it's
> > not a good idea or it is a good idea but should be clearer in some way
> > but since I didn't really understand what the purpose of doing the gotos
> > was I can't say for sure either way.
> 
> The main purpose is to avoid deeply nested code branches.
> 
> Without gotos I think we'd end up with something like this:
> 
> static int _regulator_do_set_voltage(struct regulator_dev *rdev,
>                                      int min_uV, int max_uV)
> {
> 	...
> 	if (ret == 0 && !rdev->constraints->ramp_disable) {
> 		if (rdev->desc->ops->set_voltage_time_sel) {
> 			if (old_selector >= 0 && old_selector != selector)
> 				  rdev->desc->ops->set_voltage_time_sel(rdev, old_selector, selector);
> 		} else {
> 		       if (old_uV != new_uV) {
> 				if (rdev->desc->ops->set_voltage_time)
> 					delay = rdev->desc->ops->set_voltage_time(rdev, old_uV, new_uV);
> 				else
> 					delay = _regulator_set_voltage_time(rdev, old_uV, new_uV);
> 		       }
> 		}
> 
> 		// delay
> 	}
> }
> 
> I can change the patch accordingly if this is preferred.

The above improves a bit when a local ops variable is used instead of
rdev->desc->ops. With that it looks bearable and probably better than
the goto version.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ