linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Skripkin <paskripkin@gmail.com>
To: Khalid Masum <khalid.masum.92@gmail.com>,
	linux-kernel-mentees@lists.linuxfoundation.org,
	linux-kernel@vger.kernel.org
Cc: Johan Hedberg <johan.hedberg@gmail.com>,
	netdev@vger.kernel.org, Marcel Holtmann <marcel@holtmann.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>,
	"David S . Miller" <davem@davemloft.net>
Subject: Re: [PATCH] Bluetooth: hci_core: Use ERR_PTR instead of NULL
Date: Sun, 17 Jul 2022 19:17:33 +0300	[thread overview]
Message-ID: <3ea0ea90-48bf-ce19-e014-9443d732e831@gmail.com> (raw)
In-Reply-To: <20220717133759.8479-1-khalid.masum.92@gmail.com>

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.

Also, allocation functionS return an error only in case of ENOMEM, so 
initial code is fine, IMO




Thanks,
--Pavel Skripkin
_______________________________________________
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-17 16:17 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 [this message]
2022-07-17 18:34   ` Khalid Masum
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=3ea0ea90-48bf-ce19-e014-9443d732e831@gmail.com \
    --to=paskripkin@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=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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).