Re: [PATCH net] device property: change device_get_phy_mode() to prevent signedess bugs
From: Andy Shevchenko <hidden>
Date: 2020-01-31 08:15:28
Also in:
kernel-janitors, lkml
From: Andy Shevchenko <hidden>
Date: 2020-01-31 08:15:28
Also in:
kernel-janitors, lkml
On Fri, Jan 31, 2020 at 7:03 AM Dan Carpenter [off-list ref] wrote:
The device_get_phy_mode() was returning negative error codes on
failure and positive phy_interface_t values on success. The problem is
that the phy_interface_t type is an enum which GCC treats as unsigned.
This lead to recurring signedness bugs where we check "if (phy_mode < 0)"
and "phy_mode" is unsigned.
In the commit 0c65b2b90d13 ("net: of_get_phy_mode: Change API to solve
int/unit warnings") we updated of_get_phy_mode() take a pointer to
phy_mode and only return zero on success and negatives on failure. This
patch does the same thing for device_get_phy_mode(). Plus it's just
nice for the API to be the same in both places.+ err = device_get_phy_mode(dev, &config->phy_interface);
+ if (err) + config->phy_interface = PHY_INTERFACE_MODE_NA;
Do you need these? It seems the default settings when error appears. -- With Best Regards, Andy Shevchenko