linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yicong Yang <yangyicong@hisilicon.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Alexandru Ardelean <ardeleanalex@gmail.com>,
	Jonathan Cameron <jic23@kernel.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	"Hennerich, Michael" <Michael.Hennerich@analog.com>,
	"Peter Meerwald-Stadler" <pmeerw@pmeerw.net>,
	<prime.zeng@huawei.com>, Tian Tao <tiantao6@hisilicon.com>
Subject: Re: [PATCH 5/7] iio: core: simplify some devm functions
Date: Fri, 9 Apr 2021 17:41:38 +0800	[thread overview]
Message-ID: <94bbe851-1f09-7099-38ac-2b6fcb056349@hisilicon.com> (raw)
In-Reply-To: <CAHp75Ve_JwGeruZeZnVk3pXXmETVERQTdR2+MSPX=Y75+nQLcw@mail.gmail.com>

On 2021/4/9 17:19, Andy Shevchenko wrote:
> On Fri, Apr 9, 2021 at 10:22 AM Yicong Yang <yangyicong@hisilicon.com> wrote:
>> On 2021/4/8 21:09, Alexandru Ardelean wrote:
>>> On Thu, Apr 8, 2021 at 2:41 PM Yicong Yang <yangyicong@hisilicon.com> wrote:
> 
> ...
> 
>>>> -       if (!ptr)
>>>> -               return NULL;
> 
>>>> +       if (!iio_dev)
>>>> +               return iio_dev;
>>>
>>> This is correct.
>>> But the preference is usually:
>>>         if (!iio_dev)
>>>             return NULL;
>>>
>>
>> since it returned iio_dev when failure before, so i just keep as is
> 
> Actually Alexandru has a good point. Compare the pieces I left above.
> 

a little different from my perspective when I did this.

previously:

-       ptr = devres_alloc(devm_iio_device_release, sizeof(*ptr),
-                          GFP_KERNEL);
-       if (!ptr)
-               return NULL;

if devres_alloc() failure we return NULL.


        iio_dev = iio_device_alloc(parent, sizeof_priv);
-       if (iio_dev) {
-               *ptr = iio_dev;
-               devres_add(parent, ptr);
-       } else {
-               devres_free(ptr);
-       }

        return iio_dev;

if iio_device_alloc() failed, we return what it returns.

now we remove devres_alloc() and stay iio_device_alloc(), so I just
keep to return iio_dev.

but actually iio_device_alloc() will return NULL at failure. :)
so return NULL here is definitely correct. i'll change to that if
it's recommended.

thanks,
Yicong




  reply	other threads:[~2021-04-09  9:42 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-08 11:38 [PATCH 0/7] Simplify codes with devm_add_action_or_reset Yicong Yang
2021-04-08 11:38 ` [PATCH 1/7] iio: adc: adi-axi-adc: simplify devm_adi_axi_adc_conv_register Yicong Yang
2021-04-08 13:00   ` Alexandru Ardelean
2021-04-08 13:04   ` Alexandru Ardelean
2021-04-09  7:39     ` Yicong Yang
2021-04-11 14:12   ` Jonathan Cameron
2021-04-12  9:10     ` Yicong Yang
2021-04-24 12:31       ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 2/7] iio: buffer-dmaengine: simplify __devm_iio_dmaengine_buffer_free Yicong Yang
2021-04-24 12:33   ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 3/7] iio: hw_consumer: simplify devm_iio_hw_consumer_alloc Yicong Yang
2021-04-24 13:56   ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 4/7] iio: triggered-buffer: simplify devm_iio_triggered_buffer_setup_ext Yicong Yang
2021-04-11 14:16   ` Jonathan Cameron
2021-04-12  9:05     ` Yicong Yang
2021-04-24 13:59       ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 5/7] iio: core: simplify some devm functions Yicong Yang
2021-04-08 13:09   ` Alexandru Ardelean
2021-04-09  7:21     ` Yicong Yang
2021-04-09  9:19       ` Andy Shevchenko
2021-04-09  9:41         ` Yicong Yang [this message]
2021-04-09  9:55           ` Andy Shevchenko
2021-04-09 13:05             ` Yicong Yang
2021-04-24 14:04               ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 6/7] iio: trigger: simplify __devm_iio_trigger_register Yicong Yang
2021-04-24 14:05   ` Jonathan Cameron
2021-04-08 11:38 ` [PATCH 7/7] iio: inkern: simplify some devm functions Yicong Yang
2021-04-24 14:12   ` Jonathan Cameron
2021-04-08 13:14 ` [PATCH 0/7] Simplify codes with devm_add_action_or_reset Alexandru Ardelean
2021-04-09  6:58 ` Lars-Peter Clausen
2021-04-09  7:27 ` Sa, Nuno
2021-04-09  9:17 ` Andy Shevchenko
2021-04-11 14:21 ` Jonathan Cameron
2021-04-24 14:15   ` Jonathan Cameron
2021-04-25  9:13     ` Yicong Yang

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=94bbe851-1f09-7099-38ac-2b6fcb056349@hisilicon.com \
    --to=yangyicong@hisilicon.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=ardeleanalex@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=prime.zeng@huawei.com \
    --cc=tiantao6@hisilicon.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 NNTP newsgroup(s).