lkml.org 
[lkml]   [2020]   [Jan]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH net] device property: change device_get_phy_mode() to prevent signedess bugs
On Fri, Jan 31, 2020 at 10:15:14AM +0200, Andy Shevchenko wrote:
> On Fri, Jan 31, 2020 at 7:03 AM Dan Carpenter <dan.carpenter@oracle.com> 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.
>

We don't need it, but I thought it made things more readable.

regards,
dan carpenter

\
 
 \ /
  Last update: 2020-01-31 09:26    [W:0.544 / U:0.324 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site