Re: [PATCH net] device property: change device_get_phy_mode() to prevent signedess bugs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx> 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




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux