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