linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: hci_core: Use ERR_PTR instead of NULL
@ 2022-07-17 13:37 Khalid Masum
  2022-07-17 14:04 ` bluez.test.bot
  2022-07-17 16:17 ` [PATCH] " Pavel Skripkin
  0 siblings, 2 replies; 6+ messages in thread
From: Khalid Masum @ 2022-07-17 13:37 UTC (permalink / raw)
  To: linux-kernel-mentees, linux-kernel
  Cc: Shuah Khan, Pavel Skripkin, Marcel Holtmann, Johan Hedberg,
	Luiz Augusto von Dentz, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-bluetooth, netdev,
	Khalid Masum

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>
---
 drivers/bluetooth/btusb.c | 4 ++--
 net/bluetooth/hci_core.c  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index e25fcd49db70..3407762b3b15 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -3692,8 +3692,8 @@ static int btusb_probe(struct usb_interface *intf,
 	data->recv_acl = hci_recv_frame;
 
 	hdev = hci_alloc_dev_priv(priv_size);
-	if (!hdev)
-		return -ENOMEM;
+	if (IS_ERR(hdev))
+		return PTR_ERR(hdev);
 
 	hdev->bus = HCI_USB;
 	hci_set_drvdata(hdev, data);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
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);
 
 	hdev->pkt_type  = (HCI_DM1 | HCI_DH1 | HCI_HV1);
 	hdev->esco_type = (ESCO_HV1);
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-23 10:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-17 13:37 [PATCH] Bluetooth: hci_core: Use ERR_PTR instead of NULL Khalid Masum
2022-07-17 14:04 ` bluez.test.bot
2022-07-17 16:17 ` [PATCH] " Pavel Skripkin
2022-07-17 18:34   ` Khalid Masum
2022-07-18 23:03     ` Luiz Augusto von Dentz
2022-07-23 10:54       ` Khalid Masum

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).