From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6003017A2F0 for ; Mon, 20 Oct 2025 17:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760981828; cv=none; b=TYRLr1aB2ipcrbyz6MwVqBr2BYEraS7Qp7u0dKyttVcHO06zj8QjzVkgbuxGFM4uSjbSf91CpOmhr4N0HRk4Nj4UoL87ncygvY+HgWovIL4RgpJyML+z73mUfDc9D4e52SMhIlwysrHCfcXVVO7KwM0xZaViSbqeMuYJribQUlw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760981828; c=relaxed/simple; bh=WzbtSK2GUnyggs7dMkmA5dwg5+W3cvVCoBChUVQbEg4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FwYcyPWm8mmB2ugcQcPKoSfw3A80Qsr9ylOauIIASpwCabaqfcZ7MCo8yUU4nYdZ2aw/AxN80Kg+zyAM85kXFW5PDT+GIFDPswSLTG6bysyt+kP/4/Ymxc37oD9FkkVlVqJk9UI+uskhIIhGXs0lawsSijRopUxhi2Q7JqtRo/o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=uQ4GS7T2; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="uQ4GS7T2" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1760981824; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZCDBr4k8S5btgO2DUj4st0tcx0178+FkWEqZvBZn6ts=; b=uQ4GS7T2x0ivHqryQ18URAYnMTub95//VWIDT/pC9iyhF9B4kI32EjanTW36Uto05L49Ww i3/Xna66YiTH42Hz9OSouaNzcRS5y5kKeQBXzDPR5iSPYHn4yX3rg+/Et13+KAhCvK8U2L +KMEKX8SCoWFSYALroFBeEN3WG9D9jo= From: Wen Yang To: Greg Kroah-Hartman , Jon Hunter Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org, Pierre Gondois , Palmer Dabbelt , Sudeep Holla , Wen Yang Subject: [PATCH 6.1 02/10] cacheinfo: Return error code in init_of_cache_level() Date: Tue, 21 Oct 2025 01:36:16 +0800 Message-Id: <20251020173624.20228-3-wen.yang@linux.dev> In-Reply-To: <20251020173624.20228-1-wen.yang@linux.dev> References: <20251020173624.20228-1-wen.yang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Pierre Gondois [ Upstream commit 8844c3df001bc1d8397fddea341308da63855d53 ] 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 Acked-by: Palmer Dabbelt Link: https://lore.kernel.org/r/20230104183033.755668-3-pierre.gondois@arm.com Signed-off-by: Sudeep Holla Signed-off-by: Wen Yang --- 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 7663eaddd168..480007210bcc 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -245,11 +245,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")) @@ -264,6 +264,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