Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3855638imw; Mon, 18 Jul 2022 16:05:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uo3md0Y6yvOUJniOZlEgLz4PyGuPXvghQYyB/MWq4/DfrmXg3fFbrn/fuNCsd68XFlas1u X-Received: by 2002:a63:484d:0:b0:419:cde7:a912 with SMTP id x13-20020a63484d000000b00419cde7a912mr19481761pgk.621.1658185515570; Mon, 18 Jul 2022 16:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658185515; cv=none; d=google.com; s=arc-20160816; b=g9XBy0OJFj4d/Uv6bvwUWsSs/givs14UxPf7KjJARhiavbSG5ZDwlgjz3DELIYb+8Q bXoLVr5j8R/SBAWl/g4QeWth2U90keFztI5MM3s8HqCHbs4o/HaEvZpCR+iXTN9toROK oZDiU3duEQGKClQMeotpnaFVEklZkd/7wSuqbE5milFdUsaBfFBIIT8MUsCrquQCRvXX hBd4ND6MVWkAl1GqtTDqgjvViWz3XD4OEs4EfsZ7bj8xcXskPl+68cEoMItqZKk4Rk24 BCqnwxo/synU1SrIBv6+nMflSU4zV7gr7ZtsWLJG/n5XdWcBSMl75glt3Bvd68B1XQAL LLtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TZUTBE8JOO+dBwswBQU/UW48YDxWzcOqBKIIatUeRxg=; b=uAUeAmz2I92MJKuPyzv2ExL88+cDsMMb+e/kbkhHzGuJ5iWhmNSrT+O61fkc5yGR6s gjzLzag8K2JEKQTdofpFiaQnsQ3yqyIAB9n/jGcbjeAZg2ycTuF513pQVVDCHT63xWQo 1X+hte56Lqu5klyCHwI23NkkVJbwYrBTFmnKh6P4+/JuU3dkdgpRLfs1UCHIglghmh+f DzRrMFA3Lm+pSkFwXwGDjVM6nRrh+EzQCwW0AukDTz6WQDZ6Qijcv6FijosxPpv3SyDz sEvhF2O7/bxffQj+N4ikRzEANRmV2/eA/K25Bw7hLD1XeQgPTV4SrTFZKhERyFUWafPR MWrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=eu+8mAms; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 137-20020a63048f000000b003fc5a89b010si21625505pge.103.2022.07.18.16.04.19; Mon, 18 Jul 2022 16:05:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=eu+8mAms; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234766AbiGRXEM (ORCPT + 99 others); Mon, 18 Jul 2022 19:04:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236414AbiGRXEG (ORCPT ); Mon, 18 Jul 2022 19:04:06 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56442EE2F; Mon, 18 Jul 2022 16:04:05 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id z22so8283613lfu.7; Mon, 18 Jul 2022 16:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TZUTBE8JOO+dBwswBQU/UW48YDxWzcOqBKIIatUeRxg=; b=eu+8mAmsNBdDm3xB9tJ7qWbNXhdC6joRhpKHQAJ4NU3Mky13rD9L25sbhWt9DuIotI gUojvdBW5A0Yn/MC4O+GhB63tm4n97gegK8HpEZRkzwH2RBhJ3qbgnumGnjVrlCvsJR7 2tNXRis6jsm9duhk3z7u+9TVJuxAzDeFkQhctki+wu7c0eWrDms/Ckpf9yes50sGz5ZS iqzCE8Mh9LilppMXKYD8OidSUpoV8K4oY90b0RKIZ/yMBMgmavyjBG0D5sM+o8aKrngS gmmNcREgRh2MPSjA60ICVGr0N2G66g230+VXfqZ4m8y7QeVjVf+NB5gcvz50Ti9awr+y lg8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TZUTBE8JOO+dBwswBQU/UW48YDxWzcOqBKIIatUeRxg=; b=rtpI9Unm45IrX6GHJ32A73KgZUTHBXuByJTKBO3+A2GvT6xLpx/vDxNkkHn2VZ+RSo T6009zsOqom79UFdfVY9lC/9GSyFCCEB7Jvc7/9QQf/aLKf8iEekOjI+2cn/w3Md6MwV L2FyNHJAd/OUu8sQkG6rUM4RafOFbH/prvOHFVdWFAV+TZYO2qNQFAfj9GSacUub35Jm kR+CK+76LsW0BMcQ++Mf2VyktVpkMTrT4zE2z79zrQGSnVwD/0XAdOqoeUY+MNKOpiql lc+Riy8yc1sTQ0hQamw/yDviN+8E1qH6Ho5jYY+hyzWKPgzHhrAyRQqiinVkJI9ymV6U duNA== X-Gm-Message-State: AJIora95pibKA1l3Z+2MrEWIAlDa3oCFEekfIoOFQO6PDUHxf8DnjbLF 1yBkN4cEfKDJTrRS97aVR5uxmcrtPWapTgb8fLAeYpS81FPgjg== X-Received: by 2002:a05:6512:3409:b0:489:c549:4693 with SMTP id i9-20020a056512340900b00489c5494693mr15228484lfr.26.1658185443502; Mon, 18 Jul 2022 16:04:03 -0700 (PDT) MIME-Version: 1.0 References: <20220717133759.8479-1-khalid.masum.92@gmail.com> <3ea0ea90-48bf-ce19-e014-9443d732e831@gmail.com> In-Reply-To: From: Luiz Augusto von Dentz Date: Mon, 18 Jul 2022 16:03:52 -0700 Message-ID: Subject: Re: [PATCH] Bluetooth: hci_core: Use ERR_PTR instead of NULL To: Khalid Masum Cc: Pavel Skripkin , linux-kernel-mentees@lists.linuxfoundation.org, Linux Kernel Mailing List , Shuah Khan , Marcel Holtmann , Johan Hedberg , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "linux-bluetooth@vger.kernel.org" , "open list:NETWORKING [GENERAL]" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Khalid, On Sun, Jul 17, 2022 at 11:34 AM Khalid Masum wrote: > > On Sun, Jul 17, 2022 at 10:17 PM Pavel Skripkin wrote: > > > > Hi Khalid, > > > > Khalid Masum 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 > > > --- > > > > [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. > > > > Thanks, > > --Pavel Skripkin > > > Thanks, > -- Khalid Masum -- Luiz Augusto von Dentz