[PATCH] net: Fix static checker warnings

Michal Simek michal.simek at amd.com
Tue Oct 4 14:35:46 CEST 2022



On 9/29/22 06:56, Venkatesh Yadav Abbarapu wrote:
> Here are the smatch warning messages:
> 
> drivers/net/xilinx_axi_emac.c:324 axiemac_phy_init()
> error: 'phydev' dereferencing possible ERR_PTR()
> 
> drivers/net/zynq_gem.c:340 zynq_phy_init()
> error: 'priv->phydev' dereferencing possible ERR_PTR()
> 
> Fix by adding error checking before dereferencing the pointer.
> 
> Signed-off-by: Venkatesh Yadav Abbarapu <venkatesh.abbarapu at amd.com>
> ---
> 
>   drivers/net/xilinx_axi_emac.c | 5 +++++
>   drivers/net/zynq_gem.c        | 2 +-
>   2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/xilinx_axi_emac.c b/drivers/net/xilinx_axi_emac.c
> index d48e342ea0..5f5bc650be 100644
> --- a/drivers/net/xilinx_axi_emac.c
> +++ b/drivers/net/xilinx_axi_emac.c
> @@ -11,6 +11,7 @@
>   #include <cpu_func.h>
>   #include <display_options.h>
>   #include <dm.h>
> +#include <dm/device_compat.h>
>   #include <log.h>
>   #include <net.h>
>   #include <malloc.h>
> @@ -317,6 +318,10 @@ static int axiemac_phy_init(struct udevice *dev)
>   
>   	/* Interface - look at tsec */
>   	phydev = phy_connect(priv->bus, priv->phyaddr, dev, priv->interface);
> +	if (IS_ERR_OR_NULL(phydev)) {
> +		dev_err(dev, "phy_connect() failed\n");
> +		return -ENODEV;
> +	}
>   
>   	phydev->supported &= supported;
>   	phydev->advertising = phydev->supported;
> diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c
> index 4e8dd4badd..c23602f573 100644
> --- a/drivers/net/zynq_gem.c
> +++ b/drivers/net/zynq_gem.c
> @@ -328,7 +328,7 @@ static int zynq_phy_init(struct udevice *dev)
>   
>   	priv->phydev = phy_connect(priv->bus, priv->phyaddr, dev,
>   				   priv->interface);
> -	if (!priv->phydev)
> +	if (IS_ERR_OR_NULL(priv->phydev))
>   		return -ENODEV;
>   
>   	if (priv->max_speed) {


Applied.
M


More information about the U-Boot mailing list