# Re: \[PATCH net-next\] mdio\_bus: Fix PTR\_ERR() usage after initialization to constant

- From: Al Viro \<viro@zeniv.linux.org.uk\>
- Date: 2019-02-01 04:24:25 
- List: netdev
- Page: https://ratatoskr.run/netdev/2019/02/5500895
- Thread: https://ratatoskr.run/netdev/2019/01/5495372/t.md

```text
On Tue, Jan 29, 2019 at 11:30:27AM +0800, YueHaibing wrote:
> >>  		gpiod = fwnode_get_named_gpiod(&mdiodev->dev.of_node->fwnode,
> >>  					       "reset-gpios", 0, GPIOD_OUT_LOW,
> >>  					       "PHY reset");
> >> -	if (PTR_ERR(gpiod) == -ENOENT ||
> >> -	    PTR_ERR(gpiod) == -ENOSYS)
> >> -		gpiod = NULL;
> >> -	else if (IS_ERR(gpiod))
> >> -		return PTR_ERR(gpiod);
> >> +	if (IS_ERR(gpiod)) {
> >> +		ret = PTR_ERR(gpiod);
> >> +		if (ret == -ENOENT || ret == -ENOSYS)
> >> +			gpiod = NULL;
> >> +		else
> >> +			return ret;
> >> +	}

Rule of the thumb: PTR_ERR(p) == -E... is almost always better off
as p == ERR_PTR(-E...)
```
