[PATCH v4 1/2] dmaengine: tegra210-adma: Fix build error due to 64-by-32 division

Mohan Kumar D posted 2 patches 1 year ago
There is a newer version of this series
[PATCH v4 1/2] dmaengine: tegra210-adma: Fix build error due to 64-by-32 division
Posted by Mohan Kumar D 1 year ago
Kernel test robot reported the build errors on 32-bit platforms due to
plain 64-by-32 division. Following build erros were reported.

   "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'"

This can be fixed by using div_u64() for the adma address space

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>
---
 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
Re: [PATCH v4 1/2] dmaengine: tegra210-adma: Fix build error due to 64-by-32 division
Posted by Vinod Koul 12 months ago
Hi Mohan,

On 05-02-25, 09:01, Mohan Kumar D wrote:
> Kernel test robot reported the build errors on 32-bit platforms due to
> plain 64-by-32 division. Following build erros were reported.

Patch should describe the change! Please revise subject to describe that
and not fix build error... This can come in changelog and below para is
apt

> 
>    "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'"
> 
> This can be fixed by using div_u64() for the adma address space
> 
> 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>
> ---
>  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

-- 
~Vinod
Re: [PATCH v4 1/2] dmaengine: tegra210-adma: Fix build error due to 64-by-32 division
Posted by Mohan Kumar D 12 months ago
On 10-02-2025 16:32, Vinod Koul wrote:
> External email: Use caution opening links or attachments
>
>
> Hi Mohan,
>
> On 05-02-25, 09:01, Mohan Kumar D wrote:
>> Kernel test robot reported the build errors on 32-bit platforms due to
>> plain 64-by-32 division. Following build erros were reported.
> Patch should describe the change! Please revise subject to describe that
> and not fix build error... This can come in changelog and below para is
> apt
Sure, Will update the subject and resend the updated patch
>>     "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'"
>>
>> This can be fixed by using div_u64() for the adma address space
>>
>> 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>
>> ---
>>   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
> --
> ~Vinod
Re: [PATCH v4 1/2] dmaengine: tegra210-adma: Fix build error due to 64-by-32 division
Posted by Vinod Koul 12 months ago
On 10-02-25, 16:45, Mohan Kumar D wrote:
> 
> On 10-02-2025 16:32, Vinod Koul wrote:
> > External email: Use caution opening links or attachments
> > 
> > 
> > Hi Mohan,
> > 
> > On 05-02-25, 09:01, Mohan Kumar D wrote:
> > > Kernel test robot reported the build errors on 32-bit platforms due to
> > > plain 64-by-32 division. Following build erros were reported.
> > Patch should describe the change! Please revise subject to describe that
> > and not fix build error... This can come in changelog and below para is
> > apt
> Sure, Will update the subject and resend the updated patch

Please collect the acks as well

-- 
~Vinod
Re: [PATCH v4 1/2] dmaengine: tegra210-adma: Fix build error due to 64-by-32 division
Posted by Thierry Reding 1 year ago
On Wed, Feb 05, 2025 at 09:01:30AM +0530, Mohan Kumar D wrote:
> Kernel test robot reported the build errors on 32-bit platforms due to
> plain 64-by-32 division. Following build erros were reported.
> 
>    "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'"
> 
> This can be fixed by using div_u64() for the adma address space
> 
> 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>
> ---
>  drivers/dma/tegra210-adma.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)

Acked-by: Thierry Reding <treding@nvidia.com>
Re: [PATCH v4 1/2] dmaengine: tegra210-adma: Fix build error due to 64-by-32 division
Posted by Jon Hunter 1 year ago

On 05/02/2025 03:31, Mohan Kumar D wrote:
> Kernel test robot reported the build errors on 32-bit platforms due to
> plain 64-by-32 division. Following build erros were reported.
> 
>     "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'"
> 
> This can be fixed by using div_u64() for the adma address space
> 
> 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>
> ---
>   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;

Sorry to be pedantic but should this now be ...

if (WARN_ON((page_no == 0) || (page_no > UINT_MAX)))

Jon

> +
> +			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);

-- 
nvpublic
Re: [PATCH v4 1/2] dmaengine: tegra210-adma: Fix build error due to 64-by-32 division
Posted by Jon Hunter 1 year ago

On 05/02/2025 11:27, Jon Hunter wrote:
> 
> 
> On 05/02/2025 03:31, Mohan Kumar D wrote:
>> Kernel test robot reported the build errors on 32-bit platforms due to
>> plain 64-by-32 division. Following build erros were reported.
>>
>>     "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'"
>>
>> This can be fixed by using div_u64() for the adma address space
>>
>> 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>
>> ---
>>   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;
> 
> Sorry to be pedantic but should this now be ...
> 
> if (WARN_ON((page_no == 0) || (page_no > UINT_MAX)))

Nevermind, patch 2/2 addresses this.

Jon

-- 
nvpublic