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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20181012155459.GG31561@ulmo>
Date:   Fri, 12 Oct 2018 17:54:59 +0200
From:   Thierry Reding <thierry.reding@...il.com>
To:     Vokáč Michal <Michal.Vokac@...ft.com>
Cc:     Uwe Kleine-König 
        <u.kleine-koenig@...gutronix.de>, Rob Herring <robh+dt@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        "devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
        "linux-pwm@...r.kernel.org" <linux-pwm@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        Lukasz Majewski <l.majewski@...ess.pl>,
        Fabio Estevam <fabio.estevam@....com>,
        Lothar Waßmann <LW@...o-electronics.de>,
        "kernel@...gutronix.de" <kernel@...gutronix.de>
Subject: Re: [RCF PATCH,v2,2/2] pwm: imx:
 Configure output to GPIO in disabled state

On Fri, Oct 12, 2018 at 03:04:48PM +0000, Vokáč Michal wrote:
> On 12.10.2018 10:57, Uwe Kleine-König wrote:
> > On Wed, Oct 10, 2018 at 09:33:26AM +0000, Vokáč Michal wrote:
[...]
> >> +static int imx_pwm_init_pinctrl_info(struct imx_chip *imx_chip,
> >> +		struct platform_device *pdev)
> >> +{
> >> +	imx_chip->pinctrl = devm_pinctrl_get(&pdev->dev);
> >> +	if (!imx_chip->pinctrl || IS_ERR(imx_chip->pinctrl)) {
> >> +		dev_info(&pdev->dev, "can not get pinctrl\n");
> >> +		return PTR_ERR(imx_chip->pinctrl);
> >> +	}
> >> +
> >> +	imx_chip->pinctrl_pins_pwm = pinctrl_lookup_state(imx_chip->pinctrl,
> >> +			"pwm");
> >> +	imx_chip->pinctrl_pins_gpio = pinctrl_lookup_state(imx_chip->pinctrl,
> >> +			"gpio");
> >> +	imx_chip->pwm_gpiod = devm_gpiod_get_optional(&pdev->dev, "pwm",
> >> +			GPIOD_IN);
> >> +
> >> +	if (PTR_ERR(imx_chip->pwm_gpiod) == -EPROBE_DEFER) {
> > 
> > You must not use PTR_ERR on a value that might not contain an error
> > pointer.
> 
> OK, thank you for valuable info.
> So it seems like the I2C folks are in troubles as well:
> 
> 	https://elixir.bootlin.com/linux/latest/source/drivers/i2c/busses/i2c-imx.c#L996

There's nothing inherently wrong with doing it like the above, just
maybe slightly unusual. PTR_ERR() is really just casting from a pointer
to an integer, so if the pointer happens to contain the value
-EPROBE_DEFER, then the above will be true. If it contains a valid
pointer, the above will be false, so it does exactly what you want.

Perhaps a more idiomatic way to write this would be:

	if (IS_ERR(imx_chip->pwm_gpiod)) {
		if (PTR_ERR(imx_chip->pwm_gpiod) == -EPROBE_DEFER)
			return -EPROBE_DEFER;
	}

But that's not much clearer than what you have, so feel free to keep it
that way.

Thierry

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ