Subject: Re: [RFC PATCH net-next 03/12] phy: Add lan966x ethernet serdes PHY driver

From: "Russell King (Oracle)" <[email-masked]>
Date: Mon, 20 Sep 2021 14:42:00 +0100

On Mon, Sep 20, 2021 at 11:52:09AM +0200, Horatiu Vultur wrote:
> +static int lan966x_calc_sd6g40_setup_lane(struct lan966x_sd6g40_setup_args config,
> +					  struct lan966x_sd6g40_setup *ret_val)
> +{
> +	struct lan966x_sd6g40_mode_args sd6g40_mode;
> +	struct lan966x_sd6g40_mode_args *mode_args = &sd6g40_mode;
> +
> +	if (lan966x_sd6g40_get_conf_from_mode(config.mode, config.refclk125M,
> +					      mode_args))
> +		return -1;

This needs fixing to be a real negative error number.
lan966x_sd6g40_setup_lane() propagates this functions non-zero
return value, which is then propagated through lan966x_sd6g40_setup(),
and then through serdes_set_mode() to the PHY layer.

In general, I would suggest that _all_ int-returning functions in the
kernel that return a negative failure value _should_ _always_ return a
negative error code, so that your reviewers don't have to chase code
paths to work out whether a mistake such as the above exists.

To put it another way: never use "return -1" in the kernel.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!