lkml.org 
[lkml]   [2022]   [Jul]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] Bluetooth: hci_core: Use ERR_PTR instead of NULL
From
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

\
 
 \ /
  Last update: 2022-07-17 18:18    [W:0.101 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site