[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAABMjtEDHLRGVHrjPaCyuTX0SBODVcS+U+G+xS+YQH=23zk=hg@mail.gmail.com>
Date: Sat, 23 Jul 2022 16:54:03 +0600
From: Khalid Masum <khalid.masum.92@...il.com>
To: Luiz Augusto von Dentz <luiz.dentz@...il.com>
Cc: Pavel Skripkin <paskripkin@...il.com>,
linux-kernel-mentees@...ts.linuxfoundation.org,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Shuah Khan <skhan@...uxfoundation.org>,
Marcel Holtmann <marcel@...tmann.org>,
Johan Hedberg <johan.hedberg@...il.com>,
"David S . Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
"linux-bluetooth@...r.kernel.org" <linux-bluetooth@...r.kernel.org>,
"open list:NETWORKING [GENERAL]" <netdev@...r.kernel.org>
Subject: Re: [PATCH] Bluetooth: hci_core: Use ERR_PTR instead of NULL
On Tue, Jul 19, 2022 at 5:04 AM Luiz Augusto von Dentz
<luiz.dentz@...il.com> wrote:
>
> Hi Khalid,
>
> On Sun, Jul 17, 2022 at 11:34 AM Khalid Masum <khalid.masum.92@...il.com> wrote:
> >
> > On Sun, Jul 17, 2022 at 10:17 PM Pavel Skripkin <paskripkin@...il.com> wrote:
> > >
> > > Hi Khalid,
> > >
> > > Khalid Masum <khalid.masum.92@...il.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@...il.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.
I got you.
> > > Thanks,
> > > --Pavel Skripkin
> >
> >
> > Thanks,
> > -- Khalid Masum
>
>
>
> --
> Luiz Augusto von Dentz
Thanks,
-- Khalid Masum
Powered by blists - more mailing lists