linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: Khalid Masum <khalid.masum.92@gmail.com>
Cc: Johan Hedberg <johan.hedberg@gmail.com>,
	Pavel Skripkin <paskripkin@gmail.com>,
	Marcel Holtmann <marcel@holtmann.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"linux-bluetooth@vger.kernel.org"
	<linux-bluetooth@vger.kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	"open list:NETWORKING \[GENERAL\]" <netdev@vger.kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	linux-kernel-mentees@lists.linuxfoundation.org,
	"David S . Miller" <davem@davemloft.net>
Subject: Re: [PATCH] Bluetooth: hci_core: Use ERR_PTR instead of NULL
Date: Mon, 18 Jul 2022 16:03:52 -0700	[thread overview]
Message-ID: <CABBYNZJVv=pJv60P6fYZh65JU+BV5agGfXEh4VenxELEXqtDsA@mail.gmail.com> (raw)
In-Reply-To: <CAABMjtHiet1_SRvLBhoNxeEh865rwtZCkb510JmFPkHFMd5chQ@mail.gmail.com>

Hi Khalid,

On Sun, Jul 17, 2022 at 11:34 AM Khalid Masum <khalid.masum.92@gmail.com> wrote:
>
> On Sun, Jul 17, 2022 at 10:17 PM Pavel Skripkin <paskripkin@gmail.com> wrote:
> >
> > Hi Khalid,
> >
> > Khalid Masum <khalid.masum.92@gmail.com> says:
> > > Failure of kzalloc to allocate memory is not reported. Return Error
> > > pointer to ENOMEM if memory allocation fails. This will increase
> > > readability and will make the function easier to use in future.
> > >
> > > Signed-off-by: Khalid Masum <khalid.masum.92@gmail.com>
> > > ---
> >
> > [snip]
> >
> > > index a0f99baafd35..ea50767e02bf 100644
> > > --- a/net/bluetooth/hci_core.c
> > > +++ b/net/bluetooth/hci_core.c
> > > @@ -2419,7 +2419,7 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv)
> > >
> > >       hdev = kzalloc(alloc_size, GFP_KERNEL);
> > >       if (!hdev)
> > > -             return NULL;
> > > +             return ERR_PTR(-ENOMEM);
> > >
> >
> > This will break all callers of hci_alloc_dev(). All callers expect NULL
> > in case of an error, so you will leave them with wrong pointer.
>
> You are right. All callers of hci_alloc_dev() need to be able to handle
> the error pointer. I shall send a V2 with all the callers of hci_alloc_dev
> handling the ERR_PTR.
>
> > Also, allocation functionS return an error only in case of ENOMEM, so
> > initial code is fine, IMO
> >

If there just a single error like ENOMEM then Id say this is fine,
just as it is fine for kzalloc.

> I think it makes the memory allocation error handling look to be a bit
> different from what we usually do while allocating memory which is,
> returning an error or an error pointer. Here we are returning a NULL
> without any context, making it a bit unreadable. So I think returning
> an error pointer is better. If I am not mistaken, this also complies with
> the return convention:
> https://www.kernel.org/doc/htmldocs/kernel-hacking/convention-returns.html

Not sure if that would apply to code that is basically a wrapper of kzalloc.

> >
> > Thanks,
> > --Pavel Skripkin
>
>
> Thanks,
>   -- Khalid Masum



-- 
Luiz Augusto von Dentz
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  reply	other threads:[~2022-07-18 23:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-17 13:37 [PATCH] Bluetooth: hci_core: Use ERR_PTR instead of NULL Khalid Masum
2022-07-17 16:17 ` Pavel Skripkin
2022-07-17 18:34   ` Khalid Masum
2022-07-18 23:03     ` Luiz Augusto von Dentz [this message]
2022-07-23 10:54       ` Khalid Masum

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='CABBYNZJVv=pJv60P6fYZh65JU+BV5agGfXEh4VenxELEXqtDsA@mail.gmail.com' \
    --to=luiz.dentz@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=johan.hedberg@gmail.com \
    --cc=khalid.masum.92@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=paskripkin@gmail.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).