Subject: Re: [PATCH net-next v8 4/4] net: dsa: add basic initial driver for MxL862xx switches

From: Daniel Golle <[email-masked]>
Date: Tue, 27 Jan 2026 14:48:10 +0000

On Tue, Jan 27, 2026 at 02:50:14PM +0100, Andrew Lunn wrote:
> > > > +	/* handle errors returned by the firmware as -EIO
> > > > +	 * The firmware is based on Zephyr OS and uses the errors as
> > > > +	 * defined in errno.h of Zephyr OS. See
> > > > +	 * https://github.com/zephyrproject-rtos/zephyr/blob/v3.7.0/lib/libc/minimal/include/errno.h
> > > > +	 */
> > > > +	if ((s16)ret < 0) {
> > > 
> > > The cast is likely not needed above? if `ret` values < S16_MIN are
> > > possible this will return such values to the caller without the IO err
> > > printk.
> > 
> > Right, it should rather be
> > 
> > if (ret > S16_MAX && ret <= U16_MAX)
> > 
> > to really only catch the range of numbers which are negative 16-bit
> > signed values represented as positive 32-bit signed values.
> > 
> > mxl862xx_reg_read() primarily returns a signed 32-bit integer, as it is
> > basically just a wrapper around __mdiodev_c45_read(). Negative values of
> > that 32-bit integer mean that the MDIO Clause-45 read has somehow
> > failed, ie. it's the error the MDIO bus .read_c45() operation has
> > returned.
> > 
> > In case __mdiodev_c45_read() succeeds it returns the 16-bit value of the
> > register read. In this case, those 16-bit should be interpreted as a
> > 16-bit signed integer here. A negative value denotes an error returned
> > from the firmware running on the switch (see comment above the code).
> 
> Rather than these casts, maybe add a helper which takes the unsigned
> u16 from the register and returns a signed Zepher error code?
> 
> int mxl862xx_to_zephyr_errno(u16 reg)
so that would then just be
	return (s16)reg;
right?

Or did you think to include the handling of the error __mdiodev_c45_read()
would return, ie.
int mxl862xx_to_zephyr_errno(int reg)
{
	if (reg < 0)
		return reg;

	/* handle errors returned by the firmware as -EIO
	 * The firmware is based on Zephyr OS and uses the errors as
	 * defined in errno.h of Zephyr OS. See
	 * https://github.com/zephyrproject-rtos/zephyr/blob/v3.7.0/lib/libc/minimal/include/errno.h
	 */
	if (reg > S16_MAX && reg <= U16_MAX)
		return -EIO;
}

Or actually translating the actual errno to a Linux error code?