From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9C0831CAA6C; Wed, 19 Feb 2025 09:06:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739956000; cv=none; b=T1orJ4V1VyseebEj7qUH2gVT2fJb3z3Q/RmG1C/VxHdfYmbClx56dNdgKKhMrHlI1cmtb7h2I5ulpwFmNrfFUrCQ9f9PVMg5KQqcNm7QaL9GDfVAPZe6xj5x+N+il8fCOCAOpEKHBOuGYKLDaiNdKVjAU6/MeWosdYI1QEdjsE8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739956000; c=relaxed/simple; bh=LEr4bO2SG4JFV2ED0K5mO+bKeBtowosaclBAXMrRHjU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sn7Fj3hGuS7HUrGpEWuZ4YoaXZBnmL4j44I/K/BPAPUmW/u2t9lLsSqgfd9IOWiqDERPXAM9eyLcKrkmqVr6/8CZgDPGDkzK7JceV8pEkAZ/xTxXs8iIri6cei+/hHJQ19vNQjUyMghFbVqsRynjhvv+ndcerP/ehM4Wat0FDF0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xPK6LAxS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="xPK6LAxS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26851C4CED1; Wed, 19 Feb 2025 09:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739956000; bh=LEr4bO2SG4JFV2ED0K5mO+bKeBtowosaclBAXMrRHjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xPK6LAxSW33PbTJic7BFaJoybYOSu2WGWu11y7PwscikddW32bXb5UbPxoY03kYKh avFllRNzE6vjBNtrVMTdnxT1r9RYy75O+2fMrNa6TWKKuRrbd3RvlMMEClSABWgXRh JxkcFUbNsMnCYVuTcvRV/qSulCqHgPHM4PAyYTtw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Neil Armstrong , Viresh Kumar , Sasha Levin Subject: [PATCH 6.1 031/578] OPP: fix dev_pm_opp_find_bw_*() when bandwidth table not initialized Date: Wed, 19 Feb 2025 09:20:35 +0100 Message-ID: <20250219082654.120783230@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219082652.891560343@linuxfoundation.org> References: <20250219082652.891560343@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Neil Armstrong [ Upstream commit b44b9bc7cab2967c3d6a791b1cd542c89fc07f0e ] If a driver calls dev_pm_opp_find_bw_ceil/floor() the retrieve bandwidth from the OPP table but the bandwidth table was not created because the interconnect properties were missing in the OPP consumer node, the kernel will crash with: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000004 ... pc : _read_bw+0x8/0x10 lr : _opp_table_find_key+0x9c/0x174 ... Call trace: _read_bw+0x8/0x10 (P) _opp_table_find_key+0x9c/0x174 (L) _find_key+0x98/0x168 dev_pm_opp_find_bw_ceil+0x50/0x88 ... In order to fix the crash, create an assert function to check if the bandwidth table was created before trying to get a bandwidth with _read_bw(). Fixes: add1dc094a74 ("OPP: Use generic key finding helpers for bandwidth key") Signed-off-by: Neil Armstrong Signed-off-by: Viresh Kumar Signed-off-by: Sasha Levin --- drivers/opp/core.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 53286063df558..4211cfb27350f 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -119,6 +119,15 @@ static bool assert_clk_index(struct opp_table *opp_table, return opp_table->clk_count > index; } +/* + * Returns true if bandwidth table is large enough to contain the bandwidth index. + */ +static bool assert_bandwidth_index(struct opp_table *opp_table, + unsigned int index) +{ + return opp_table->path_count > index; +} + /** * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp * @opp: opp for which voltage has to be returned for @@ -847,7 +856,8 @@ struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, unsigned int *bw, unsigned long temp = *bw; struct dev_pm_opp *opp; - opp = _find_key_ceil(dev, &temp, index, true, _read_bw, NULL); + opp = _find_key_ceil(dev, &temp, index, true, _read_bw, + assert_bandwidth_index); *bw = temp; return opp; } @@ -878,7 +888,8 @@ struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, unsigned long temp = *bw; struct dev_pm_opp *opp; - opp = _find_key_floor(dev, &temp, index, true, _read_bw, NULL); + opp = _find_key_floor(dev, &temp, index, true, _read_bw, + assert_bandwidth_index); *bw = temp; return opp; } -- 2.39.5