Re: [PATCH net] device property: change device_get_phy_mode() to prevent signedess bugs
From: Dan Carpenter <hidden>
Date: 2020-01-31 08:25:57
Also in:
kernel-janitors, lkml
From: Dan Carpenter <hidden>
Date: 2020-01-31 08:25:57
Also in:
kernel-janitors, lkml
On Fri, Jan 31, 2020 at 10:15:14AM +0200, Andy Shevchenko wrote:
On Fri, Jan 31, 2020 at 7:03 AM Dan Carpenter [off-list ref] wrote:quoted
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.quoted
+ err = device_get_phy_mode(dev, &config->phy_interface);quoted
+ if (err) + config->phy_interface = PHY_INTERFACE_MODE_NA;Do you need these? It seems the default settings when error appears.
We don't need it, but I thought it made things more readable. regards, dan carpenter