mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v5 0/2] Tegra ADMA fixes
@ 2025-02-10 13:54 Mohan Kumar D
  2025-02-10 13:54 ` [PATCH v5 1/2] dmaengine: tegra210-adma: Use div_u64 for 64 bit division Mohan Kumar D
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mohan Kumar D @ 2025-02-10 13:54 UTC (permalink / raw)
  To: vkoul, thierry.reding, jonathanh
  Cc: dmaengine, linux-tegra, linux-kernel, stable, Mohan Kumar D

- Kernel test robot reported the build errors on 32-bit platforms due to
plain 64-by-32 division. Fix build error by using div_u64()

- Additional check for adma max page

Changelog
=========

v1 -> v2:
   * Used lower_32_bits() to truncate the 64-bit address space for
     division
   * Included additional patch to check for adma max page

v2 -> v3:
   * Removed unwanter file change

v3 -> v4:
   * Used div_u64() to perform the 64-bit division of adma address
     differences

v4 -> v5:
   * Updated commit message of the patchsets

Mohan Kumar D (2):
  dmaengine: tegra210-adma: Use div_u64 for 64 bit division
  dmaengine: tegra210-adma: check for adma max page

 drivers/dma/tegra210-adma.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v5 1/2] dmaengine: tegra210-adma: Use div_u64 for 64 bit division
  2025-02-10 13:54 [PATCH v5 0/2] Tegra ADMA fixes Mohan Kumar D
@ 2025-02-10 13:54 ` Mohan Kumar D
  2025-02-10 13:54 ` [PATCH v5 2/2] dmaengine: tegra210-adma: check for adma max page Mohan Kumar D
  2025-02-10 14:34 ` [PATCH v5 0/2] Tegra ADMA fixes Vinod Koul
  2 siblings, 0 replies; 4+ messages in thread
From: Mohan Kumar D @ 2025-02-10 13:54 UTC (permalink / raw)
  To: vkoul, thierry.reding, jonathanh
  Cc: dmaengine, linux-tegra, linux-kernel, stable, Mohan Kumar D,
	kernel test robot, Thierry Reding

The ADMA base and page address are represented using a 64-bit variable.
To accurately derive the exact ADMA page number provided from the DT
properties, use the div_u64() to divide the address difference between
adma page and base address by the page offset.

This change fixes the below error
   "ERROR: modpost: "__udivdi3" [drivers/dma/tegra210-adma.ko] undefined!
    ld: drivers/dma/tegra210-adma.o: in function `tegra_adma_probe':
    tegra210-adma.c:(.text+0x12cf): undefined reference to `__udivdi3'"

Fixes: 68811c928f88 ("dmaengine: tegra210-adma: Support channel page")
Cc: stable@vger.kernel.org
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202412250204.GCQhdKe3-lkp@intel.com/
Signed-off-by: Mohan Kumar D <mkumard@nvidia.com>
Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
Acked-by: Thierry Reding <treding@nvidia.com>
---
 drivers/dma/tegra210-adma.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/tegra210-adma.c b/drivers/dma/tegra210-adma.c
index 6896da8ac7ef..a0bd4822ed80 100644
--- a/drivers/dma/tegra210-adma.c
+++ b/drivers/dma/tegra210-adma.c
@@ -887,7 +887,8 @@ static int tegra_adma_probe(struct platform_device *pdev)
 	const struct tegra_adma_chip_data *cdata;
 	struct tegra_adma *tdma;
 	struct resource *res_page, *res_base;
-	int ret, i, page_no;
+	u64 page_no, page_offset;
+	int ret, i;
 
 	cdata = of_device_get_match_data(&pdev->dev);
 	if (!cdata) {
@@ -914,10 +915,16 @@ static int tegra_adma_probe(struct platform_device *pdev)
 
 		res_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "global");
 		if (res_base) {
-			page_no = (res_page->start - res_base->start) / cdata->ch_base_offset;
-			if (page_no <= 0)
+			if (WARN_ON(res_page->start <= res_base->start))
 				return -EINVAL;
-			tdma->ch_page_no = page_no - 1;
+
+			page_offset = res_page->start - res_base->start;
+			page_no = div_u64(page_offset, cdata->ch_base_offset);
+
+			if (WARN_ON(page_no == 0))
+				return -EINVAL;
+
+			tdma->ch_page_no = lower_32_bits(page_no) - 1;
 			tdma->base_addr = devm_ioremap_resource(&pdev->dev, res_base);
 			if (IS_ERR(tdma->base_addr))
 				return PTR_ERR(tdma->base_addr);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v5 2/2] dmaengine: tegra210-adma: check for adma max page
  2025-02-10 13:54 [PATCH v5 0/2] Tegra ADMA fixes Mohan Kumar D
  2025-02-10 13:54 ` [PATCH v5 1/2] dmaengine: tegra210-adma: Use div_u64 for 64 bit division Mohan Kumar D
@ 2025-02-10 13:54 ` Mohan Kumar D
  2025-02-10 14:34 ` [PATCH v5 0/2] Tegra ADMA fixes Vinod Koul
  2 siblings, 0 replies; 4+ messages in thread
From: Mohan Kumar D @ 2025-02-10 13:54 UTC (permalink / raw)
  To: vkoul, thierry.reding, jonathanh
  Cc: dmaengine, linux-tegra, linux-kernel, stable, Mohan Kumar D,
	Thierry Reding

Have additional check for max channel page during the probe
to cover if any offset overshoot happens due to wrong DT
configuration.

Fixes: 68811c928f88 ("dmaengine: tegra210-adma: Support channel page")
Cc: stable@vger.kernel.org
Signed-off-by: Mohan Kumar D <mkumard@nvidia.com>
Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
Acked-by: Thierry Reding <treding@nvidia.com>
---
 drivers/dma/tegra210-adma.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/tegra210-adma.c b/drivers/dma/tegra210-adma.c
index a0bd4822ed80..801740ad8e0d 100644
--- a/drivers/dma/tegra210-adma.c
+++ b/drivers/dma/tegra210-adma.c
@@ -83,7 +83,9 @@ struct tegra_adma;
  * @nr_channels: Number of DMA channels available.
  * @ch_fifo_size_mask: Mask for FIFO size field.
  * @sreq_index_offset: Slave channel index offset.
+ * @max_page: Maximum ADMA Channel Page.
  * @has_outstanding_reqs: If DMA channel can have outstanding requests.
+ * @set_global_pg_config: Global page programming.
  */
 struct tegra_adma_chip_data {
 	unsigned int (*adma_get_burst_config)(unsigned int burst_size);
@@ -99,6 +101,7 @@ struct tegra_adma_chip_data {
 	unsigned int nr_channels;
 	unsigned int ch_fifo_size_mask;
 	unsigned int sreq_index_offset;
+	unsigned int max_page;
 	bool has_outstanding_reqs;
 	void (*set_global_pg_config)(struct tegra_adma *tdma);
 };
@@ -854,6 +857,7 @@ static const struct tegra_adma_chip_data tegra210_chip_data = {
 	.nr_channels		= 22,
 	.ch_fifo_size_mask	= 0xf,
 	.sreq_index_offset	= 2,
+	.max_page		= 0,
 	.has_outstanding_reqs	= false,
 	.set_global_pg_config	= NULL,
 };
@@ -871,6 +875,7 @@ static const struct tegra_adma_chip_data tegra186_chip_data = {
 	.nr_channels		= 32,
 	.ch_fifo_size_mask	= 0x1f,
 	.sreq_index_offset	= 4,
+	.max_page		= 4,
 	.has_outstanding_reqs	= true,
 	.set_global_pg_config	= tegra186_adma_global_page_config,
 };
@@ -921,7 +926,7 @@ static int tegra_adma_probe(struct platform_device *pdev)
 			page_offset = res_page->start - res_base->start;
 			page_no = div_u64(page_offset, cdata->ch_base_offset);
 
-			if (WARN_ON(page_no == 0))
+			if (WARN_ON(page_no == 0 || page_no > cdata->max_page))
 				return -EINVAL;
 
 			tdma->ch_page_no = lower_32_bits(page_no) - 1;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v5 0/2] Tegra ADMA fixes
  2025-02-10 13:54 [PATCH v5 0/2] Tegra ADMA fixes Mohan Kumar D
  2025-02-10 13:54 ` [PATCH v5 1/2] dmaengine: tegra210-adma: Use div_u64 for 64 bit division Mohan Kumar D
  2025-02-10 13:54 ` [PATCH v5 2/2] dmaengine: tegra210-adma: check for adma max page Mohan Kumar D
@ 2025-02-10 14:34 ` Vinod Koul
  2 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2025-02-10 14:34 UTC (permalink / raw)
  To: thierry.reding, jonathanh, Mohan Kumar D
  Cc: dmaengine, linux-tegra, linux-kernel, stable


On Mon, 10 Feb 2025 19:24:11 +0530, Mohan Kumar D wrote:
> - Kernel test robot reported the build errors on 32-bit platforms due to
> plain 64-by-32 division. Fix build error by using div_u64()
> 
> - Additional check for adma max page
> 
> Changelog
> =========
> 
> [...]

Applied, thanks!

[1/2] dmaengine: tegra210-adma: Use div_u64 for 64 bit division
      commit: 17987453a9d997c4d0749abc52f047bfa275427a
[2/2] dmaengine: tegra210-adma: check for adma max page
      commit: 76ed9b7d177ed5aa161a824ea857619b88542de1

Best regards,
-- 
~Vinod



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-10 14:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-10 13:54 [PATCH v5 0/2] Tegra ADMA fixes Mohan Kumar D
2025-02-10 13:54 ` [PATCH v5 1/2] dmaengine: tegra210-adma: Use div_u64 for 64 bit division Mohan Kumar D
2025-02-10 13:54 ` [PATCH v5 2/2] dmaengine: tegra210-adma: check for adma max page Mohan Kumar D
2025-02-10 14:34 ` [PATCH v5 0/2] Tegra ADMA fixes Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®