2021-09-20 23:39:01

by Russell King (Oracle)

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

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!