lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20240324121853.460ba5f8@jic23-huawei>
Date: Sun, 24 Mar 2024 12:18:53 +0000
From: Jonathan Cameron <jic23@...nel.org>
To: Andy Shevchenko <andy.shevchenko@...il.com>
Cc: David Lechner <dlechner@...libre.com>, Michael Hennerich
 <michael.hennerich@...log.com>, Nuno Sá <nuno.sa@...log.com>,
 linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] iio: adc: ad7944: simplify adi,spi-mode property
 parsing

On Sat, 23 Mar 2024 22:44:37 +0200
Andy Shevchenko <andy.shevchenko@...il.com> wrote:

> Sat, Mar 23, 2024 at 06:29:18PM +0000, Jonathan Cameron kirjoitti:
> > On Tue, 19 Mar 2024 10:28:31 -0500
> > David Lechner <dlechner@...libre.com> wrote:  
> > > On Tue, Mar 19, 2024 at 10:01 AM Andy Shevchenko
> > > <andy.shevchenko@...il.com> wrote:  
> > > > On Tue, Mar 19, 2024 at 4:28 PM David Lechner <dlechner@...libre.com> wrote:    
> 
> ...
> 
> > > > > +       ret = device_property_match_property_string(dev, "adi,spi-mode",
> > > > > +                                                   ad7944_spi_modes,
> > > > > +                                                   ARRAY_SIZE(ad7944_spi_modes));
> > > > > +       if (ret < 0) {
> > > > > +               if (ret != -EINVAL)
> > > > > +                       return dev_err_probe(dev, ret,
> > > > > +                                            "getting adi,spi-mode property failed\n");    
> > > >    
> > > > > -               adc->spi_mode = ret;
> > > > > -       } else {    
> > > >
> > > > Actually we may even leave these unchanged
> > > >    
> > > > >                 /* absence of adi,spi-mode property means default mode */
> > > > >                 adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
> > > > > +       } else {
> > > > > +               adc->spi_mode = ret;
> > > > >         }    
> > > >
> > > >        ret = device_property_match_property_string(dev, "adi,spi-mode",
> > > >                                                    ad7944_spi_modes,
> > > >
> > > > ARRAY_SIZE(ad7944_spi_modes));
> > > >        if (ret >= 0) {
> > > >                adc->spi_mode = ret;
> > > >        } else if (ret != -EINVAL) {
> > > >                        return dev_err_probe(dev, ret,
> > > >                                             "getting adi,spi-mode
> > > > property failed\n");
> > > >        } else {
> > > >                /* absence of adi,spi-mode property means default mode */
> > > >                adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
> > > >        }
> > > >
> > > > But I can admit this is not an often used approach.
> > > >    
> > > 
> > > I think Jonathan prefers to have the error path first, so I would like
> > > to wait and see if he has an opinion here.  
> > I do prefer error paths first.  Thanks.  
> 
> Still the above can be refactored to have one line less
> 
> 	ret = device_property_match_property_string(dev, "adi,spi-mode",
>                                                     ad7944_spi_modes,
> 						    ARRAY_SIZE(ad7944_spi_modes));
> 	if (ret == -EINVAL) {
> 		/* absence of adi,spi-mode property means default mode */
> 		adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
> 	} else if (ret < 0) {
> 		return dev_err_probe(dev, ret, "getting adi,spi-mode property failed\n");
> 	} else {
> 		adc->spi_mode = ret;
>         }
> 
True.  I'll take a patch doing that, but I'm not going to tweak
it again directly.

Thanks,

Jonathan


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ