From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8798BC2BA19 for ; Mon, 6 Apr 2020 10:32:26 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2E5D5206F5 for ; Mon, 6 Apr 2020 10:32:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ellerman.id.au header.i=@ellerman.id.au header.b="QicFLfQG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E5D5206F5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48wn0l1XgWzDqHr for ; Mon, 6 Apr 2020 20:32:23 +1000 (AEST) Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 48wmyn01MwzDqHr for ; Mon, 6 Apr 2020 20:30:41 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ellerman.id.au header.i=@ellerman.id.au header.a=rsa-sha256 header.s=201909 header.b=QicFLfQG; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 48wmyl5g9kz9sQx; Mon, 6 Apr 2020 20:30:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1586169040; bh=J5Gd4sFnjMTia0MKfTM4yZ4mKW3Qdp/00DZrLvgYTxk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=QicFLfQGVKf+EPEYIGe18QEpu6hKyZuXjgrAYbCk3RLWX+UCTouDgg0ACEP7WNh/i JN0vleiGiYFEd1IG3RnQvRKXfRpKxdj3zoSPrkKjCFS3XMLgSb5JOnKTeH2bqP1tBd V4js1Frnhko4PiK8YJDeArFluBvP5+dbOSY0gBnEuFan4ukV2njhtMQBJrV7DtgNK1 ycXOhJkA/CtlcvBZ7KAl3MoLXsTCrbZN+DObrxKXLlFrut73b6IeFXl1cHc1c/95+t t3hovoPqlZ51a8/zHHklmJeljzX+xRG03RdBfKovtGInBjDLNDuEy/NQFtzIKqo0Ha PSMBJnn05ciVQ== From: Michael Ellerman To: Qiujun Huang , benh@kernel.crashing.org, paulus@samba.org, oohall@gmail.com Subject: Re: [PATCH v4] powerpc/powernv: add NULL check after kzalloc in opal_add_one_export In-Reply-To: <20200406093944.4174-1-hqjagain@gmail.com> References: <20200406093944.4174-1-hqjagain@gmail.com> Date: Mon, 06 Apr 2020 20:30:50 +1000 Message-ID: <87eet0sy79.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, Markus.Elfring@web.de, tglx@linutronix.de, linuxppc-dev@lists.ozlabs.org, Qiujun Huang Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Qiujun Huang writes: > Here needs a NULL check as kzalloc may fail returning NULL. > > Issue was found by coccinelle. > Generated by: scripts/coccinelle/null/kmerr.cocci > > Signed-off-by: Qiujun Huang > Reviewed-by: Oliver O'Halloran > > --- Thanks for putting up with all the review comments :) But I think this should actually be two patches now. The first patch should change the goto after of_property_read_u64_array() into a return and drop the redundant assignments. Then the second patch can add the NULL check for attr. cheers > v3->v4: > Added the information about coccinelle script. > Added change log. > Added Oliver's Reviewed-by. > v2->v3: > Removed redundant assignment to 'attr' and 'name'. > v1->v2: > Just return -ENOMEM if attr is NULL. > --- > arch/powerpc/platforms/powernv/opal.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c > index 2b3dfd0b6cdd..908d749bcef5 100644 > --- a/arch/powerpc/platforms/powernv/opal.c > +++ b/arch/powerpc/platforms/powernv/opal.c > @@ -801,16 +801,19 @@ static ssize_t export_attr_read(struct file *fp, struct kobject *kobj, > static int opal_add_one_export(struct kobject *parent, const char *export_name, > struct device_node *np, const char *prop_name) > { > - struct bin_attribute *attr = NULL; > - const char *name = NULL; > + struct bin_attribute *attr; > + const char *name; > u64 vals[2]; > int rc; > > rc = of_property_read_u64_array(np, prop_name, &vals[0], 2); > if (rc) > - goto out; > + return rc; > > attr = kzalloc(sizeof(*attr), GFP_KERNEL); > + if (!attr) > + return -ENOMEM; > + > name = kstrdup(export_name, GFP_KERNEL); > if (!name) { > rc = -ENOMEM; > -- > 2.17.1