From: Khalid Masum <khalid.masum.92@gmail.com>
To: Pavel Skripkin <paskripkin@gmail.com>
Cc: Johan Hedberg <johan.hedberg@gmail.com>,
netdev@vger.kernel.org, Marcel Holtmann <marcel@holtmann.org>,
linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org,
Eric Dumazet <edumazet@google.com>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
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 00:34:19 +0600 [thread overview]
Message-ID: <CAABMjtHiet1_SRvLBhoNxeEh865rwtZCkb510JmFPkHFMd5chQ@mail.gmail.com> (raw)
In-Reply-To: <3ea0ea90-48bf-ce19-e014-9443d732e831@gmail.com>
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
>
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
>
> Thanks,
> --Pavel Skripkin
Thanks,
-- Khalid Masum
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
next prev parent reply other threads:[~2022-07-17 18:34 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 [this message]
2022-07-18 23:03 ` Luiz Augusto von Dentz
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=CAABMjtHiet1_SRvLBhoNxeEh865rwtZCkb510JmFPkHFMd5chQ@mail.gmail.com \
--to=khalid.masum.92@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=johan.hedberg@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=luiz.dentz@gmail.com \
--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).