Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2204279rdb; Fri, 8 Dec 2023 01:00:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+82ELhr0NjXNe0tCKk8oUwW62Z44aSjEknbH4GegcWYkAerCEDDZ1wYIusw7vmo7E26SF X-Received: by 2002:a05:6808:2f16:b0:3b8:5c24:80da with SMTP id gu22-20020a0568082f1600b003b85c2480damr4948636oib.58.1702026009928; Fri, 08 Dec 2023 01:00:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702026009; cv=none; d=google.com; s=arc-20160816; b=bRS/RM2PeemSlwv00Oukuh3z8PdGlVRtxfJBT9V1ZwQUN7wj2sdqxrwANcE2JaHO28 HIv50XIJnYv0ZjyUtpR2RLXHCjGggOCDF+D6CuCxfzPBd6BHD3NrVDD/Z50jSpzlwfPr Xxe1hxM8XpUxAbvchg91lOo6C2Edt6PCGzhP11GnEgx4uEVWHr9xe0CKarNevWqRdHrz gFoTSPj0lDa9nCTTKESS+8zpekKHhCh43nmSkDHzaKqXQ8w44DvazhE/cScrpuqvVKNs LAsii5XLMTdCsfhu/igkEjvHF4fgbfu/OJu7DN+P/UbjoNjCPEYiRnrZOW2fM2+rRnf/ LAeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=0YirU130AHjttOPDVOT6WGnKAkIzz+9DhGJ18TNXwlo=; fh=uOkwOqUb5TYeOqRP888AXi4zE2qE/45mxMbeXnPj7qk=; b=uHZt5i87hWlkBy2huw6YKuVKjkiSzFgPj1p90Ivf2PuWm273hbOqJ2lEt2kMUVdTyd KNLGiPsey/LHfni/qvuOgF4aGDHW6GvjDzG112GSSkp+0POKm8+9gUqqePZxzIjPNMqs lDjqgqtH0yaGuazLwOz6u9aCDx2J67CqU8WoTZ7FTHqk15PYSFOmJilMQOXl7KAxHWLg 3nwkUiUOXN8lPi67iQ/ISDyqNegVJvwIaJlSBNjBwSjJz6MHt1q8/DZDHTcXZqRZqDRB 8Ma43Y2+UrJ2NC78KkP1LCh3uC5zHjFIs25FAwjr9oMJubudzOAwa2JVZeC68Z3+sPmW cllQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id u12-20020a056a00124c00b006ce50011c9asi1214836pfi.345.2023.12.08.01.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 01:00:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 779DF80A6BDE; Fri, 8 Dec 2023 01:00:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233312AbjLHI7u (ORCPT + 99 others); Fri, 8 Dec 2023 03:59:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232968AbjLHI7t (ORCPT ); Fri, 8 Dec 2023 03:59:49 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C87C10F1 for ; Fri, 8 Dec 2023 00:59:54 -0800 (PST) X-UUID: 1802c3bb5ed24c5e9c1f08ab8e1e3091-20231208 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33,REQID:af98fde9-2795-4a43-b1b3-12ea01001784,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-5 X-CID-INFO: VERSION:1.1.33,REQID:af98fde9-2795-4a43-b1b3-12ea01001784,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:364b77b,CLOUDID:47c8f760-c89d-4129-91cb-8ebfae4653fc,B ulkID:231208165944LJR4L0VC,BulkQuantity:0,Recheck:0,SF:24|17|19|44|66|38|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil ,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_FSI,TF_CID_SPAM_ULN,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS, TF_CID_SPAM_FSD X-UUID: 1802c3bb5ed24c5e9c1f08ab8e1e3091-20231208 X-User: chentao@kylinos.cn Received: from vt.. [(116.128.244.171)] by mailgw (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 615465568; Fri, 08 Dec 2023 16:59:42 +0800 From: Kunwu Chan To: mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, ajd@linux.ibm.com Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, mirimmad17@gmail.com, Kunwu Chan , Kunwu Chan Subject: [PATCH] powerpc/powernv: Add a null pointer check to scom_debug_init_one Date: Fri, 8 Dec 2023 16:59:37 +0800 Message-Id: <20231208085937.107210-1-chentao@kylinos.cn> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 08 Dec 2023 01:00:06 -0800 (PST) kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Add a null pointer check, and release 'ent' to avoid memory leaks. Fixes: bfd2f0d49aef ("powerpc/powernv: Get rid of old scom_controller abstraction") Cc: Kunwu Chan Signed-off-by: Kunwu Chan --- arch/powerpc/platforms/powernv/opal-xscom.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/powerpc/platforms/powernv/opal-xscom.c b/arch/powerpc/platforms/powernv/opal-xscom.c index 262cd6fac907..748c2b97fa53 100644 --- a/arch/powerpc/platforms/powernv/opal-xscom.c +++ b/arch/powerpc/platforms/powernv/opal-xscom.c @@ -165,6 +165,11 @@ static int scom_debug_init_one(struct dentry *root, struct device_node *dn, ent->chip = chip; snprintf(ent->name, 16, "%08x", chip); ent->path.data = (void *)kasprintf(GFP_KERNEL, "%pOF", dn); + if (!ent->path.data) { + kfree(ent); + return -ENOMEM; + } + ent->path.size = strlen((char *)ent->path.data); dir = debugfs_create_dir(ent->name, root); -- 2.39.2