Linux-IIO Archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Michael Hennerich" <michael.hennerich@analog.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: adc: ad7944: simplify adi,spi-mode property parsing
Date: Sun, 24 Mar 2024 12:18:53 +0000	[thread overview]
Message-ID: <20240324121853.460ba5f8@jic23-huawei> (raw)
In-Reply-To: <Zf8_NZ5cNb9TVThx@surfacebook.localdomain>

On Sat, 23 Mar 2024 22:44:37 +0200
Andy Shevchenko <andy.shevchenko@gmail.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@baylibre.com> wrote:  
> > > On Tue, Mar 19, 2024 at 10:01 AM Andy Shevchenko
> > > <andy.shevchenko@gmail.com> wrote:  
> > > > On Tue, Mar 19, 2024 at 4:28 PM David Lechner <dlechner@baylibre.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


  reply	other threads:[~2024-03-24 12:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19 14:27 [PATCH v2] iio: adc: ad7944: simplify adi,spi-mode property parsing David Lechner
2024-03-19 15:01 ` Andy Shevchenko
2024-03-19 15:28   ` David Lechner
2024-03-23 18:29     ` Jonathan Cameron
2024-03-23 20:44       ` Andy Shevchenko
2024-03-24 12:18         ` Jonathan Cameron [this message]
2024-03-23 18:31 ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240324121853.460ba5f8@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).