Linux-i2c Archive on lore.kernel.org
 help / color / Atom feed
* [next] i2c: mediatek: Use div_u64 for 64-bit division to fix 32-bit kernels
@ 2020-05-20 10:31 qii.wang
  2020-05-20 13:29 ` Wolfram Sang
  2020-05-20 16:15 ` Randy Dunlap
  0 siblings, 2 replies; 3+ messages in thread
From: qii.wang @ 2020-05-20 10:31 UTC (permalink / raw)
  To: wsa
  Cc: linux-i2c, devicetree, linux-arm-kernel, linux-kernel,
	linux-mediatek, srv_heupstream, leilk.liu, qii.wang

From: Qii Wang <qii.wang@mediatek.com>

Use div_u64 for 64-bit division, and change sample_ns type to
unsigned int. Otherwise, the module will reference __udivdi3
under 32-bit kernels, which is not allowed in kernel space.

Signed-off-by: Qii Wang <qii.wang@mediatek.com>
---
 drivers/i2c/busses/i2c-mt65xx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index 7020618..deef69e 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -551,7 +551,8 @@ static int mtk_i2c_check_ac_timing(struct mtk_i2c *i2c,
 	const struct i2c_spec_values *spec;
 	unsigned int su_sta_cnt, low_cnt, high_cnt, max_step_cnt;
 	unsigned int sda_max, sda_min, clk_ns, max_sta_cnt = 0x3f;
-	long long sample_ns = (1000000000 * (sample_cnt + 1)) / clk_src;
+	unsigned int sample_ns = div_u64(1000000000ULL * (sample_cnt + 1),
+					 clk_src);
 
 	if (!i2c->dev_comp->timing_adjust)
 		return 0;
-- 
1.9.1

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

* Re: [next] i2c: mediatek: Use div_u64 for 64-bit division to fix 32-bit kernels
  2020-05-20 10:31 [next] i2c: mediatek: Use div_u64 for 64-bit division to fix 32-bit kernels qii.wang
@ 2020-05-20 13:29 ` Wolfram Sang
  2020-05-20 16:15 ` Randy Dunlap
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2020-05-20 13:29 UTC (permalink / raw)
  To: qii.wang
  Cc: linux-i2c, devicetree, linux-arm-kernel, linux-kernel,
	linux-mediatek, srv_heupstream, leilk.liu


[-- Attachment #1: Type: text/plain, Size: 440 bytes --]

On Wed, May 20, 2020 at 06:31:53PM +0800, qii.wang@mediatek.com wrote:
> From: Qii Wang <qii.wang@mediatek.com>
> 
> Use div_u64 for 64-bit division, and change sample_ns type to
> unsigned int. Otherwise, the module will reference __udivdi3
> under 32-bit kernels, which is not allowed in kernel space.
> 
> Signed-off-by: Qii Wang <qii.wang@mediatek.com>

Applied to for-next by squashing it into the relevant commit, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [next] i2c: mediatek: Use div_u64 for 64-bit division to fix 32-bit kernels
  2020-05-20 10:31 [next] i2c: mediatek: Use div_u64 for 64-bit division to fix 32-bit kernels qii.wang
  2020-05-20 13:29 ` Wolfram Sang
@ 2020-05-20 16:15 ` Randy Dunlap
  1 sibling, 0 replies; 3+ messages in thread
From: Randy Dunlap @ 2020-05-20 16:15 UTC (permalink / raw)
  To: qii.wang, wsa
  Cc: linux-i2c, devicetree, linux-arm-kernel, linux-kernel,
	linux-mediatek, srv_heupstream, leilk.liu

On 5/20/20 3:31 AM, qii.wang@mediatek.com wrote:
> From: Qii Wang <qii.wang@mediatek.com>
> 
> Use div_u64 for 64-bit division, and change sample_ns type to
> unsigned int. Otherwise, the module will reference __udivdi3
> under 32-bit kernels, which is not allowed in kernel space.
> 
> Signed-off-by: Qii Wang <qii.wang@mediatek.com>

Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested

thanks.

> ---
>  drivers/i2c/busses/i2c-mt65xx.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
> index 7020618..deef69e 100644
> --- a/drivers/i2c/busses/i2c-mt65xx.c
> +++ b/drivers/i2c/busses/i2c-mt65xx.c
> @@ -551,7 +551,8 @@ static int mtk_i2c_check_ac_timing(struct mtk_i2c *i2c,
>  	const struct i2c_spec_values *spec;
>  	unsigned int su_sta_cnt, low_cnt, high_cnt, max_step_cnt;
>  	unsigned int sda_max, sda_min, clk_ns, max_sta_cnt = 0x3f;
> -	long long sample_ns = (1000000000 * (sample_cnt + 1)) / clk_src;
> +	unsigned int sample_ns = div_u64(1000000000ULL * (sample_cnt + 1),
> +					 clk_src);
>  
>  	if (!i2c->dev_comp->timing_adjust)
>  		return 0;
> 


-- 
~Randy

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-20 10:31 [next] i2c: mediatek: Use div_u64 for 64-bit division to fix 32-bit kernels qii.wang
2020-05-20 13:29 ` Wolfram Sang
2020-05-20 16:15 ` Randy Dunlap

Linux-i2c Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-i2c/0 linux-i2c/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-i2c linux-i2c/ https://lore.kernel.org/linux-i2c \
		linux-i2c@vger.kernel.org
	public-inbox-index linux-i2c

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-i2c


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git