miiphyutil: Fix inconsistent miiphy_write() error return value
Subsystems (2)
PATCH 1/2 miiphyutil: Fix inconsistent miiphy_write() error return value
miiphy_write() should not directly return the error return value from bus->write(), because that is typically a -errno value, while generally miiphy_write() and other miiphy_*() functions return 1 on error. Some miiphy_write() callers only check for > 0 to detect errors.
Fix it to match miiphy_read(), which also converts bus->read() failure to "return 1".
--- common/miiphyutil.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
common/miiphyutil.c +10 -5
@@ -236,7 +236,7 @@ static struct mii_dev *miiphy_get_active_dev(const char *devname)* This API is deprecated. Use phy_read on a phy_device found via phy_connect * * Returns: -* 0 on success +* 0 on success, 1 on error */ int miiphy_read (const char *devname,unsigned char addr,unsigned char reg,unsigned short *value)
@@ -264,18 +264,23 @@ int miiphy_read(const char *devname, unsigned char addr, unsigned char reg,* This API is deprecated. Use phy_write on a phy_device found by phy_connect * * Returns: -* 0 on success +* 0 on success, 1 on error */ int miiphy_write (const char *devname,unsigned char addr,unsigned char reg,unsigned short value) {struct mii_dev *bus; +int ret; bus =miiphy_get_active_dev (devname); -if (bus) -return bus->write (bus, addr,MDIO_DEVAD_NONE , reg, value); +if (!bus) +return 1 ; -return 1 ; + ret = bus->write (bus, addr,MDIO_DEVAD_NONE , reg, value); +if (ret <0 ) +return 1 ; + +return 0 ; }/*****************************************************************************
Signature · 1 line
2.32.0
PATCH 2/2 net: phy: mv88e6352: Fix miiphy_read/miiphy_write return value checks
The miiphy_read/miiphy_write functions return 1 on error, not -errno. Fix up the checks accordingly and insert -EIO as fallback error code.
--- drivers/net/phy/mv88e6352.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
drivers/net/phy/mv88e6352.c +11 -15
@@ -36,16 +36,14 @@ static int sw_wait_rdy(const char *devname, u8 phy_addr) {u16 command;u32 timeout =100 ; -int ret;/* wait till the SMI is not busy */ do { /* read command register */ - ret = miiphy_read(devname, phy_addr, COMMAND_REG, &command); - if (ret < 0) { + if (miiphy_read(devname, phy_addr, COMMAND_REG, &command)) { printf("%s: Error reading command register\n", __func__); - return ret; + return -EIO; } if (timeout-- == 0) { printf("Err..(%s) SMI busy timeout\n", __func__);
@@ -69,17 +67,17 @@ static int sw_reg_read(const char *devname, u8 phy_addr, u8 port, command =SMI_HDR |SMIRD_OP | ((port&SMI_MASK ) <<PORT_SHIFT ) | (reg &SMI_MASK );debug ("%s: write to command: %#x\n" , __func__, command); - ret =miiphy_write (devname, phy_addr,COMMAND_REG , command); -if (ret) -return ret; +if (miiphy_write (devname, phy_addr,COMMAND_REG , command)) +return -EIO ; ret =sw_wait_rdy (devname, phy_addr);if (ret)return ret; - ret =miiphy_read (devname, phy_addr,DATA_REG , data); +if (miiphy_read (devname, phy_addr,DATA_REG , data)) +return -EIO ; -return ret; +return 0 ; } static int sw_reg_write(const char *devname, u8 phy_addr, u8 port,
@@ -93,16 +91,14 @@ static int sw_reg_write(const char *devname, u8 phy_addr, u8 port,return ret;debug ("%s: write to data: %#x\n" , __func__, data); - ret =miiphy_write (devname, phy_addr,DATA_REG , data); -if (ret) -return ret; +if (miiphy_write (devname, phy_addr,DATA_REG , data)) +return -EIO ; value =SMI_HDR |SMIWR_OP | ((port &SMI_MASK ) <<PORT_SHIFT ) | (reg &SMI_MASK );debug ("%s: write to command: %#x\n" , __func__, value); - ret =miiphy_write (devname, phy_addr,COMMAND_REG , value); -if (ret) -return ret; +if (miiphy_write (devname, phy_addr,COMMAND_REG , value)) +return -EIO ; ret =sw_wait_rdy (devname, phy_addr);if (ret)
Signature · 1 line
2.32.0
Re: [PATCH 2/2] net: phy: mv88e6352: Fix miiphy_read/miiphy_write return value checks
Quoted 2 lines · Daniel Klauer
The miiphy_read/miiphy_write functions return 1 on error, not -errno.
Why don't you just fix the miiphy_read/miiphy_write functions ?
Re: [PATCH 2/2] net: phy: mv88e6352: Fix miiphy_read/miiphy_write return value checks
Quoted 4 lines · Ramon Fried
Quoted 2 lines · Daniel Klauer
The miiphy_read/miiphy_write functions return 1 on error, not -errno.
Why don't you just fix the miiphy_read/miiphy_write functions ?
Other functions from that module do the same, so I assumed it's intentional. It could be fixed too though, with a corresponding fix up of the few callers that expect the positive return value on error.
Re: [PATCH 2/2] net: phy: mv88e6352: Fix miiphy_read/miiphy_write return value checks
Quoted 10 lines · Daniel Klauer
Quoted 4 lines · Ramon Fried
Quoted 2 lines · Daniel Klauer
The miiphy_read/miiphy_write functions return 1 on error, not -errno.
Why don't you just fix the miiphy_read/miiphy_write functions ?
Other functions from that module do the same, so I assumed it's intentional. It could be fixed too though, with a corresponding fix up of the few callers that expect the positive return value on error.
Sometimes a real fix needs more work.
What caused you to change it on your side to -EIO, is there someone checking for EIO in the framework code ?
Re: [PATCH 2/2] net: phy: mv88e6352: Fix miiphy_read/miiphy_write return value checks
Quoted 6 lines · Ramon Fried
Quoted 5 lines · Daniel Klauer
Quoted 3 lines · Ramon Fried
Quoted 2 lines · Daniel Klauer
The miiphy_read/miiphy_write functions return 1 on error, not -errno.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Why don't you just fix the miiphy_read/miiphy_write functions ?
Other functions from that module do the same, so I assumed it's intentional. It could be fixed too though, with a corresponding fix up of the few callers that expect the positive return value on error.
Sometimes a real fix needs more work.
What caused you to change it on your side to-EIO, is there someone checking for EIO in the framework code ?
It's not that anything specifically expects -EIO, I just picked it because I had to pick something and it seemed like a good solution. Of course that only makes sense with the current miiphy_read/write functions which don't propagate the real errno. If that were to be changed, this patch for mv88e6352.c would not be useful anymore.