Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp13631888rwl; Wed, 4 Jan 2023 10:42:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXtJhw2lPVZ2YLczGZEuuX9LKT3EqZHYzKELASkb/ehMszypokc2eBzZLmILEjFsi/lPDy8z X-Received: by 2002:a17:906:c18d:b0:843:770e:777d with SMTP id g13-20020a170906c18d00b00843770e777dmr40367334ejz.11.1672857773222; Wed, 04 Jan 2023 10:42:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672857773; cv=none; d=google.com; s=arc-20160816; b=AcL7g8TOyw0DYFmH7GYINxRWk7761i22EDGFNNFin1V8dL90hW1jE0CzRKZxnTYP4v qOihCCLuztZUhx2eHdrv6yKhJW0sFyORxMZ1ZpUy2d4bBiAyfU1k+THt6TWXStBSKJ1s RADlMbFETOietOEf7FcoItwTsz/Njh1aZO98ukpT3oaHTyh8rM0YzUu29wvJnmHtvtCz GcgejkQMmbiFtjlboYwOxh7b9JuNyQpG/j7qqkrM16EPobydZtoyj+hsvgm+5xAvObwH vmhpzjHObJTacH5VzhsRV5X+oTJ48cK5dG5zm8VS+bJrNIejGA7QUdGUxrTSIrKlAEq4 oCIA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oCkn+8Btv0Eo6NyFZ0yioB/fDiascCWvqyByFV9+o+Y=; b=XVJRXZv/Gy249OYhLqRo5nJVVyXfOeynyExCYM8Uvwsu65nytfcIwPY2sZg3yCBIyI oxHdMJCx2bOSEF+h+Ox9XWgyUk56YayT+f6kkirf26ElTo8FtcSEQcLYYCJ3px8Djhzx 5Nft+zafwvJqgCd7KfCldTw+4ZnidWUxhxZsNH08GQELFbh84jASTai+TtnT0lstue0e oqM7vevLvag3LuWa1AaOSnWPGm8BVRa4uyAaa9rpprj9lAZ+opT5TuIiAXnDMxb7J2Bc I1pj/X+XRh0EZXU50w/9u2DwFmLcmCh7PYsrcfvvlnU794Xm/Q8u5uV/k8a1Qme2TCZ1 obIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd22-20020a1709076e1600b0083c1a5b39b2si33351834ejc.574.2023.01.04.10.42.22; Wed, 04 Jan 2023 10:42:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239853AbjADSbn (ORCPT + 58 others); Wed, 4 Jan 2023 13:31:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239845AbjADSbh (ORCPT ); Wed, 4 Jan 2023 13:31:37 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A34071573E; Wed, 4 Jan 2023 10:31:29 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 215671682; Wed, 4 Jan 2023 10:32:11 -0800 (PST) Received: from pierre123.arm.com (unknown [10.57.44.105]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B7A963F663; Wed, 4 Jan 2023 10:31:25 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Pierre Gondois , Sudeep Holla , Palmer Dabbelt , Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Jeremy Linton , Conor Dooley , Gavin Shan , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org Subject: [PATCH v4 2/6] cacheinfo: Return error code in init_of_cache_level() Date: Wed, 4 Jan 2023 19:30:25 +0100 Message-Id: <20230104183033.755668-3-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230104183033.755668-1-pierre.gondois@arm.com> References: <20230104183033.755668-1-pierre.gondois@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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-kernel@vger.kernel.org Make init_of_cache_level() return an error code when the cache information parsing fails to help detecting missing information. init_of_cache_level() is only called for riscv. Returning an error code instead of 0 will prevent detect_cache_attributes() to allocate memory if an incomplete DT is parsed. Signed-off-by: Pierre Gondois Reviewed-by: Sudeep Holla Acked-by: Palmer Dabbelt --- drivers/base/cacheinfo.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index 5ae58e32a77f..3e965ef6ee42 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -246,11 +246,11 @@ int init_of_cache_level(unsigned int cpu) of_node_put(prev); prev = np; if (!of_device_is_compatible(np, "cache")) - break; + goto err_out; if (of_property_read_u32(np, "cache-level", &level)) - break; + goto err_out; if (level <= levels) - break; + goto err_out; if (of_property_read_bool(np, "cache-size")) ++leaves; if (of_property_read_bool(np, "i-cache-size")) @@ -265,6 +265,10 @@ int init_of_cache_level(unsigned int cpu) this_cpu_ci->num_leaves = leaves; return 0; + +err_out: + of_node_put(np); + return -EINVAL; } #else -- 2.25.1