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 87ABC359A78; Sat, 28 Feb 2026 17:37:18 +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=1772300238; cv=none; b=oukA/FaMH+luBNwA1ND2E6jYHqLC4mHQRJ2Hl5Yp8ZMY9CqHjp7MVtmZTHizUN2HYxjvoyB17hxqii1wwnTs2PlGCh4OikuMtjnIIgxMm8wCobunzyvMDw1oPHZixbMtLK1Td/PjeyTURs77H1a8p82orLXG4HBzKtqzLnma36E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772300238; c=relaxed/simple; bh=5aKzeXcYaYo4MCLQ1Ws0WHCxrUeX6gnyX7HcxQxb8KA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rm96ciCUdgvUIkg9W5ZBWmhv9DrDf3GXqBA/Pj3pjFk1M+uLFFrJUNEJGnyqjipWctetTpU7l9jo2y0nQvJhxNL160fptKP8zaDsHITKBtqde71ubc26hkFrhjp/0U4prFSd1sEe6TgAZIbXg4jbfI3ZMP6Ya0a3O9oWpUtJi60= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ETiRpB33; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ETiRpB33" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB47AC19424; Sat, 28 Feb 2026 17:37:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772300238; bh=5aKzeXcYaYo4MCLQ1Ws0WHCxrUeX6gnyX7HcxQxb8KA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ETiRpB33UY4ZskLNZ4SXjSsPuR/b7iX+bfi9UrpcaMNTLPyBzksKaKV5z/zEhuEvV QmFsRmUDwRuFzasBQX2I6cTyvCcITtcgRWlG0Tk8obohOUDeiFYnNRls+upxhSpOar 1uvRm4+61/5p9ktodqjJdJNWgbumgDDJJokbqF8jsK/FF85ZdUv16GSupELyBXcBQV Zf9iPxyvyy7IrieB9PJJ/Cn5FKGdNwgl6fipX0ZpaerbkO8mL4WLkdJB79P7yQtphm 5GO1YI2U3FTh9uFBgWNfkId5ShzVKy+8mNeohNPxOxR4KtmvVoR2WZrzhmeAH6LwcN acKR47ytYelBg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ian Rogers , Manivannan Sadhasivam , Bjorn Helgaas , Sasha Levin Subject: [PATCH 6.19 261/844] PCI: cadence: Avoid signed 64-bit truncation and invalid sort Date: Sat, 28 Feb 2026 12:22:54 -0500 Message-ID: <20260228173244.1509663-262-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260228173244.1509663-1-sashal@kernel.org> References: <20260228173244.1509663-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Ian Rogers [ Upstream commit 0297dce758a021ccf2c0f4e164d5403ef722961c ] The cdns_pcie_host_dma_ranges_cmp() element comparison function used by list_sort() is of type list_cmp_func_t, so it returns a 32-bit int. cdns_pcie_host_dma_ranges_cmp() computes a resource_size_t difference that may be a 64-bit value, and truncating that difference to a 32-bit return value may change the sign and result in an invalid sort order. Avoid the truncation and invalid sort order by returning -1, 0, or 1. Signed-off-by: Ian Rogers Signed-off-by: Manivannan Sadhasivam [bhelgaas: commit log] Signed-off-by: Bjorn Helgaas Link: https://patch.msgid.link/20251209223756.2321578-1-irogers@google.com Signed-off-by: Sasha Levin --- .../controller/cadence/pcie-cadence-host-common.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/cadence/pcie-cadence-host-common.c b/drivers/pci/controller/cadence/pcie-cadence-host-common.c index 15415d7f35ee9..2b0211870f02a 100644 --- a/drivers/pci/controller/cadence/pcie-cadence-host-common.c +++ b/drivers/pci/controller/cadence/pcie-cadence-host-common.c @@ -173,11 +173,21 @@ int cdns_pcie_host_dma_ranges_cmp(void *priv, const struct list_head *a, const struct list_head *b) { struct resource_entry *entry1, *entry2; + u64 size1, size2; entry1 = container_of(a, struct resource_entry, node); entry2 = container_of(b, struct resource_entry, node); - return resource_size(entry2->res) - resource_size(entry1->res); + size1 = resource_size(entry1->res); + size2 = resource_size(entry2->res); + + if (size1 > size2) + return -1; + + if (size1 < size2) + return 1; + + return 0; } EXPORT_SYMBOL_GPL(cdns_pcie_host_dma_ranges_cmp); -- 2.51.0