* [PATCH] drm/modes: Fix division by zero error
2023-06-21 15:11 [syzbot] [dri?] divide error in drm_mode_vrefresh syzbot
@ 2023-07-09 1:12 ` Ziqi Zhao
2023-07-09 4:09 ` [syzbot] [dri?] divide error in drm_mode_vrefresh syzbot
2023-07-21 16:07 ` [PATCH] drm/modes: Fix division by zero error Ziqi Zhao
2023-08-01 21:55 ` [PATCH v2] " Ziqi Zhao
2023-08-02 17:47 ` [PATCH v3] drm/modes: Fix division by zero due to overflow Ziqi Zhao
2 siblings, 2 replies; 10+ messages in thread
From: Ziqi Zhao @ 2023-07-09 1:12 UTC (permalink / raw)
To: syzbot+622bba18029bcde672e1
Cc: airlied, daniel, davem, dri-devel, dsahern, edumazet,
jacob.e.keller, jiri, kuba, linux-kernel, maarten.lankhorst,
mripard, netdev, pabeni, syzkaller-bugs, tzimmermann, skhan,
ivan.orlov0322, Ziqi Zhao
In the bug reported by Syzbot, the variable `den == (1 << 22)` and
`mode->vscan == (1 << 10)`, causing the multiplication to overflow and
accidentally make `den == 0`. To prevent any chance of overflow, we
replace `num` and `den` with 64-bit unsigned integers, and explicitly
check if the divisor `den` will overflow. If so, we employ full 64-bit
division with rounding; otherwise we keep the 64-bit to 32-bit division
that could potentially be better optimized.
In order to minimize the performance overhead, the overflow check for
`den` is wrapped with an `unlikely` condition. Please let me know if
this usage is appropriate.
#syz test:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
Signed-off-by: Ziqi Zhao <astrajoan@yahoo.com>
---
drivers/gpu/drm/drm_modes.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index ac9a406250c5..aa98bd7b8bc9 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -1285,13 +1285,13 @@ EXPORT_SYMBOL(drm_mode_set_name);
*/
int drm_mode_vrefresh(const struct drm_display_mode *mode)
{
- unsigned int num, den;
+ unsigned long long num, den;
if (mode->htotal == 0 || mode->vtotal == 0)
return 0;
- num = mode->clock;
- den = mode->htotal * mode->vtotal;
+ num = mul_u32_u32(mode->clock, 1000);
+ den = mul_u32_u32(mode->htotal, mode->vtotal);
if (mode->flags & DRM_MODE_FLAG_INTERLACE)
num *= 2;
@@ -1300,7 +1300,10 @@ int drm_mode_vrefresh(const struct drm_display_mode *mode)
if (mode->vscan > 1)
den *= mode->vscan;
- return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
+ if (unlikely(den >> 32))
+ return div64_u64(num + (den >> 1), den);
+ else
+ return DIV_ROUND_CLOSEST_ULL(num, (unsigned int) den);
}
EXPORT_SYMBOL(drm_mode_vrefresh);
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [syzbot] [dri?] divide error in drm_mode_vrefresh
2023-07-09 1:12 ` [PATCH] drm/modes: Fix division by zero error Ziqi Zhao
@ 2023-07-09 4:09 ` syzbot
2023-07-21 16:07 ` [PATCH] drm/modes: Fix division by zero error Ziqi Zhao
1 sibling, 0 replies; 10+ messages in thread
From: syzbot @ 2023-07-09 4:09 UTC (permalink / raw)
To: airlied, astrajoan, daniel, davem, dri-devel, dsahern, edumazet,
ivan.orlov0322, jacob.e.keller, jiri, kuba, linux-kernel,
maarten.lankhorst, mripard, netdev, pabeni, skhan, syzkaller-bugs,
tzimmermann
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Reported-and-tested-by: syzbot+622bba18029bcde672e1@syzkaller.appspotmail.com
Tested on:
commit: 1c7873e3 mm: lock newly mapped VMA with corrected orde..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=101196d2a80000
kernel config: https://syzkaller.appspot.com/x/.config?x=8f6b0c7ae2c9c303
dashboard link: https://syzkaller.appspot.com/bug?extid=622bba18029bcde672e1
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=10e44354a80000
Note: testing is done by a robot and is best-effort only.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] drm/modes: Fix division by zero error
2023-07-09 1:12 ` [PATCH] drm/modes: Fix division by zero error Ziqi Zhao
2023-07-09 4:09 ` [syzbot] [dri?] divide error in drm_mode_vrefresh syzbot
@ 2023-07-21 16:07 ` Ziqi Zhao
2023-08-01 9:30 ` Jani Nikula
1 sibling, 1 reply; 10+ messages in thread
From: Ziqi Zhao @ 2023-07-21 16:07 UTC (permalink / raw)
To: astrajoan, airlied, daniel, dri-devel, ivan.orlov0322,
maarten.lankhorst, mripard, skhan, tzimmermann
Cc: davem, dsahern, edumazet, jacob.e.keller, jiri, kuba,
linux-kernel, netdev, pabeni, syzbot+622bba18029bcde672e1,
syzkaller-bugs
In the bug reported by Syzbot, the variable `den == (1 << 22)` and
`mode->vscan == (1 << 10)`, causing the multiplication to overflow and
accidentally make `den == 0`. To prevent any chance of overflow, we
replace `num` and `den` with 64-bit unsigned integers, and explicitly
check if the divisor `den` will overflow. If so, we employ full 64-bit
division with rounding; otherwise we keep the 64-bit to 32-bit division
that could potentially be better optimized.
In order to minimize the performance overhead, the overflow check for
`den` is wrapped with an `unlikely` condition. Please let me know if
this usage is appropriate.
Reported-by: syzbot+622bba18029bcde672e1@syzkaller.appspotmail.com
Signed-off-by: Ziqi Zhao <astrajoan@yahoo.com>
---
drivers/gpu/drm/drm_modes.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index ac9a406250c5..aa98bd7b8bc9 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -1285,13 +1285,13 @@ EXPORT_SYMBOL(drm_mode_set_name);
*/
int drm_mode_vrefresh(const struct drm_display_mode *mode)
{
- unsigned int num, den;
+ unsigned long long num, den;
if (mode->htotal == 0 || mode->vtotal == 0)
return 0;
- num = mode->clock;
- den = mode->htotal * mode->vtotal;
+ num = mul_u32_u32(mode->clock, 1000);
+ den = mul_u32_u32(mode->htotal, mode->vtotal);
if (mode->flags & DRM_MODE_FLAG_INTERLACE)
num *= 2;
@@ -1300,7 +1300,10 @@ int drm_mode_vrefresh(const struct drm_display_mode *mode)
if (mode->vscan > 1)
den *= mode->vscan;
- return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
+ if (unlikely(den >> 32))
+ return div64_u64(num + (den >> 1), den);
+ else
+ return DIV_ROUND_CLOSEST_ULL(num, (unsigned int) den);
}
EXPORT_SYMBOL(drm_mode_vrefresh);
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH] drm/modes: Fix division by zero error
2023-07-21 16:07 ` [PATCH] drm/modes: Fix division by zero error Ziqi Zhao
@ 2023-08-01 9:30 ` Jani Nikula
0 siblings, 0 replies; 10+ messages in thread
From: Jani Nikula @ 2023-08-01 9:30 UTC (permalink / raw)
To: Ziqi Zhao, astrajoan, airlied, daniel, dri-devel, ivan.orlov0322,
maarten.lankhorst, mripard, skhan, tzimmermann
Cc: netdev, dsahern, syzkaller-bugs, linux-kernel, edumazet, jiri,
jacob.e.keller, kuba, pabeni, davem, syzbot+622bba18029bcde672e1
On Fri, 21 Jul 2023, Ziqi Zhao <astrajoan@yahoo.com> wrote:
> In the bug reported by Syzbot, the variable `den == (1 << 22)` and
> `mode->vscan == (1 << 10)`, causing the multiplication to overflow and
> accidentally make `den == 0`. To prevent any chance of overflow, we
> replace `num` and `den` with 64-bit unsigned integers, and explicitly
> check if the divisor `den` will overflow. If so, we employ full 64-bit
> division with rounding; otherwise we keep the 64-bit to 32-bit division
> that could potentially be better optimized.
>
> In order to minimize the performance overhead, the overflow check for
> `den` is wrapped with an `unlikely` condition. Please let me know if
> this usage is appropriate.
>
> Reported-by: syzbot+622bba18029bcde672e1@syzkaller.appspotmail.com
> Signed-off-by: Ziqi Zhao <astrajoan@yahoo.com>
> ---
> drivers/gpu/drm/drm_modes.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index ac9a406250c5..aa98bd7b8bc9 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -1285,13 +1285,13 @@ EXPORT_SYMBOL(drm_mode_set_name);
> */
> int drm_mode_vrefresh(const struct drm_display_mode *mode)
> {
> - unsigned int num, den;
> + unsigned long long num, den;
I think making them u64 would be more clear.
>
> if (mode->htotal == 0 || mode->vtotal == 0)
> return 0;
>
> - num = mode->clock;
> - den = mode->htotal * mode->vtotal;
> + num = mul_u32_u32(mode->clock, 1000);
> + den = mul_u32_u32(mode->htotal, mode->vtotal);
>
> if (mode->flags & DRM_MODE_FLAG_INTERLACE)
> num *= 2;
> @@ -1300,7 +1300,10 @@ int drm_mode_vrefresh(const struct drm_display_mode *mode)
> if (mode->vscan > 1)
> den *= mode->vscan;
>
> - return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
> + if (unlikely(den >> 32))
More intuitively, den > UINT_MAX.
> + return div64_u64(num + (den >> 1), den);
More intuitively, DIV64_U64_ROUND_CLOSEST(num, den).
> + else
The else after a branch with return is unnecessary. Someone's going to
send a patch to remove it later if you leave it in.
BR,
Jani.
> + return DIV_ROUND_CLOSEST_ULL(num, (unsigned int) den);
> }
> EXPORT_SYMBOL(drm_mode_vrefresh);
--
Jani Nikula, Intel Open Source Graphics Center
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2] drm/modes: Fix division by zero error
2023-06-21 15:11 [syzbot] [dri?] divide error in drm_mode_vrefresh syzbot
2023-07-09 1:12 ` [PATCH] drm/modes: Fix division by zero error Ziqi Zhao
@ 2023-08-01 21:55 ` Ziqi Zhao
2023-08-02 10:04 ` Jani Nikula
2023-08-02 17:47 ` [PATCH v3] drm/modes: Fix division by zero due to overflow Ziqi Zhao
2 siblings, 1 reply; 10+ messages in thread
From: Ziqi Zhao @ 2023-08-01 21:55 UTC (permalink / raw)
To: syzbot+622bba18029bcde672e1, astrajoan, jani.nikula, airlied,
daniel, dri-devel, ivan.orlov0322, maarten.lankhorst, mripard,
skhan, tzimmermann
Cc: davem, dsahern, edumazet, jacob.e.keller, jiri, kuba,
linux-kernel, netdev, pabeni, syzkaller-bugs
In the bug reported by Syzbot, the variable `den == (1 << 22)` and
`mode->vscan == (1 << 10)`, causing the multiplication to overflow and
accidentally make `den == 0`. To prevent any chance of overflow, we
replace `num` and `den` with 64-bit unsigned integers, and explicitly
check if the divisor `den` will overflow. If so, we employ full 64-bit
division with rounding; otherwise we keep the 64-bit to 32-bit division
that could potentially be better optimized.
In order to minimize the performance overhead, the overflow check for
`den` is wrapped with an `unlikely` condition. Please let me know if
this usage is appropriate.
Reported-by: syzbot+622bba18029bcde672e1@syzkaller.appspotmail.com
Signed-off-by: Ziqi Zhao <astrajoan@yahoo.com>
---
V1 -> V2: address style comments suggested by Jani Nikula
<jani.nikula@linux.intel.com>
drivers/gpu/drm/drm_modes.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index ac9a406250c5..137101960690 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -1285,13 +1285,13 @@ EXPORT_SYMBOL(drm_mode_set_name);
*/
int drm_mode_vrefresh(const struct drm_display_mode *mode)
{
- unsigned int num, den;
+ u64 num, den;
if (mode->htotal == 0 || mode->vtotal == 0)
return 0;
- num = mode->clock;
- den = mode->htotal * mode->vtotal;
+ num = mul_u32_u32(mode->clock, 1000);
+ den = mul_u32_u32(mode->htotal, mode->vtotal);
if (mode->flags & DRM_MODE_FLAG_INTERLACE)
num *= 2;
@@ -1300,7 +1300,10 @@ int drm_mode_vrefresh(const struct drm_display_mode *mode)
if (mode->vscan > 1)
den *= mode->vscan;
- return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
+ if (unlikely(den > UINT_MAX))
+ return DIV64_U64_ROUND_CLOSEST(num, den);
+
+ return DIV_ROUND_CLOSEST_ULL(num, (u32) den);
}
EXPORT_SYMBOL(drm_mode_vrefresh);
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2] drm/modes: Fix division by zero error
2023-08-01 21:55 ` [PATCH v2] " Ziqi Zhao
@ 2023-08-02 10:04 ` Jani Nikula
0 siblings, 0 replies; 10+ messages in thread
From: Jani Nikula @ 2023-08-02 10:04 UTC (permalink / raw)
To: Ziqi Zhao, syzbot+622bba18029bcde672e1, astrajoan, airlied,
daniel, dri-devel, ivan.orlov0322, maarten.lankhorst, mripard,
skhan, tzimmermann
Cc: davem, dsahern, edumazet, jacob.e.keller, jiri, kuba,
linux-kernel, netdev, pabeni, syzkaller-bugs
On Tue, 01 Aug 2023, Ziqi Zhao <astrajoan@yahoo.com> wrote:
> In the bug reported by Syzbot, the variable `den == (1 << 22)` and
> `mode->vscan == (1 << 10)`, causing the multiplication to overflow and
> accidentally make `den == 0`. To prevent any chance of overflow, we
> replace `num` and `den` with 64-bit unsigned integers, and explicitly
> check if the divisor `den` will overflow. If so, we employ full 64-bit
> division with rounding; otherwise we keep the 64-bit to 32-bit division
> that could potentially be better optimized.
>
> In order to minimize the performance overhead, the overflow check for
> `den` is wrapped with an `unlikely` condition. Please let me know if
> this usage is appropriate.
>
> Reported-by: syzbot+622bba18029bcde672e1@syzkaller.appspotmail.com
> Signed-off-by: Ziqi Zhao <astrajoan@yahoo.com>
Come to think of it, maybe the subject should mention "fix overflow"
instead, but no biggie.
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
> ---
> V1 -> V2: address style comments suggested by Jani Nikula
> <jani.nikula@linux.intel.com>
>
> drivers/gpu/drm/drm_modes.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index ac9a406250c5..137101960690 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -1285,13 +1285,13 @@ EXPORT_SYMBOL(drm_mode_set_name);
> */
> int drm_mode_vrefresh(const struct drm_display_mode *mode)
> {
> - unsigned int num, den;
> + u64 num, den;
>
> if (mode->htotal == 0 || mode->vtotal == 0)
> return 0;
>
> - num = mode->clock;
> - den = mode->htotal * mode->vtotal;
> + num = mul_u32_u32(mode->clock, 1000);
> + den = mul_u32_u32(mode->htotal, mode->vtotal);
>
> if (mode->flags & DRM_MODE_FLAG_INTERLACE)
> num *= 2;
> @@ -1300,7 +1300,10 @@ int drm_mode_vrefresh(const struct drm_display_mode *mode)
> if (mode->vscan > 1)
> den *= mode->vscan;
>
> - return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
> + if (unlikely(den > UINT_MAX))
> + return DIV64_U64_ROUND_CLOSEST(num, den);
> +
> + return DIV_ROUND_CLOSEST_ULL(num, (u32) den);
> }
> EXPORT_SYMBOL(drm_mode_vrefresh);
--
Jani Nikula, Intel Open Source Graphics Center
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3] drm/modes: Fix division by zero due to overflow
2023-06-21 15:11 [syzbot] [dri?] divide error in drm_mode_vrefresh syzbot
2023-07-09 1:12 ` [PATCH] drm/modes: Fix division by zero error Ziqi Zhao
2023-08-01 21:55 ` [PATCH v2] " Ziqi Zhao
@ 2023-08-02 17:47 ` Ziqi Zhao
2023-08-03 9:35 ` Jani Nikula
2 siblings, 1 reply; 10+ messages in thread
From: Ziqi Zhao @ 2023-08-02 17:47 UTC (permalink / raw)
To: syzbot+622bba18029bcde672e1, astrajoan, jani.nikula, airlied,
daniel, dri-devel, ivan.orlov0322, maarten.lankhorst, mripard,
skhan, tzimmermann
Cc: davem, dsahern, edumazet, jacob.e.keller, jiri, kuba,
linux-kernel, netdev, pabeni, syzkaller-bugs
In the bug reported by Syzbot, the variable `den == (1 << 22)` and
`mode->vscan == (1 << 10)`, causing the multiplication to overflow and
accidentally make `den == 0`. To prevent any chance of overflow, we
replace `num` and `den` with 64-bit unsigned integers, and explicitly
check if the divisor `den` will overflow. If so, we employ full 64-bit
division with rounding; otherwise we keep the 64-bit to 32-bit division
that could potentially be better optimized.
In order to minimize the performance overhead, the overflow check for
`den` is wrapped with an `unlikely` condition. Please let me know if
this usage is appropriate.
Reported-by: syzbot+622bba18029bcde672e1@syzkaller.appspotmail.com
Signed-off-by: Ziqi Zhao <astrajoan@yahoo.com>
---
V1 -> V2: address style comments suggested by Jani Nikula
<jani.nikula@linux.intel.com>
V2 -> V3: change title to include context on overflow causing the
division by zero
drivers/gpu/drm/drm_modes.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index ac9a406250c5..137101960690 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -1285,13 +1285,13 @@ EXPORT_SYMBOL(drm_mode_set_name);
*/
int drm_mode_vrefresh(const struct drm_display_mode *mode)
{
- unsigned int num, den;
+ u64 num, den;
if (mode->htotal == 0 || mode->vtotal == 0)
return 0;
- num = mode->clock;
- den = mode->htotal * mode->vtotal;
+ num = mul_u32_u32(mode->clock, 1000);
+ den = mul_u32_u32(mode->htotal, mode->vtotal);
if (mode->flags & DRM_MODE_FLAG_INTERLACE)
num *= 2;
@@ -1300,7 +1300,10 @@ int drm_mode_vrefresh(const struct drm_display_mode *mode)
if (mode->vscan > 1)
den *= mode->vscan;
- return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
+ if (unlikely(den > UINT_MAX))
+ return DIV64_U64_ROUND_CLOSEST(num, den);
+
+ return DIV_ROUND_CLOSEST_ULL(num, (u32) den);
}
EXPORT_SYMBOL(drm_mode_vrefresh);
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v3] drm/modes: Fix division by zero due to overflow
2023-08-02 17:47 ` [PATCH v3] drm/modes: Fix division by zero due to overflow Ziqi Zhao
@ 2023-08-03 9:35 ` Jani Nikula
0 siblings, 0 replies; 10+ messages in thread
From: Jani Nikula @ 2023-08-03 9:35 UTC (permalink / raw)
To: Ziqi Zhao, syzbot+622bba18029bcde672e1, astrajoan, airlied,
daniel, dri-devel, ivan.orlov0322, maarten.lankhorst, mripard,
skhan, tzimmermann
Cc: davem, dsahern, edumazet, jacob.e.keller, jiri, kuba,
linux-kernel, netdev, pabeni, syzkaller-bugs
On Wed, 02 Aug 2023, Ziqi Zhao <astrajoan@yahoo.com> wrote:
> In the bug reported by Syzbot, the variable `den == (1 << 22)` and
> `mode->vscan == (1 << 10)`, causing the multiplication to overflow and
> accidentally make `den == 0`. To prevent any chance of overflow, we
> replace `num` and `den` with 64-bit unsigned integers, and explicitly
> check if the divisor `den` will overflow. If so, we employ full 64-bit
> division with rounding; otherwise we keep the 64-bit to 32-bit division
> that could potentially be better optimized.
>
> In order to minimize the performance overhead, the overflow check for
> `den` is wrapped with an `unlikely` condition. Please let me know if
> this usage is appropriate.
>
> Reported-by: syzbot+622bba18029bcde672e1@syzkaller.appspotmail.com
> Signed-off-by: Ziqi Zhao <astrajoan@yahoo.com>
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
> ---
> V1 -> V2: address style comments suggested by Jani Nikula
> <jani.nikula@linux.intel.com>
> V2 -> V3: change title to include context on overflow causing the
> division by zero
>
> drivers/gpu/drm/drm_modes.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index ac9a406250c5..137101960690 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -1285,13 +1285,13 @@ EXPORT_SYMBOL(drm_mode_set_name);
> */
> int drm_mode_vrefresh(const struct drm_display_mode *mode)
> {
> - unsigned int num, den;
> + u64 num, den;
>
> if (mode->htotal == 0 || mode->vtotal == 0)
> return 0;
>
> - num = mode->clock;
> - den = mode->htotal * mode->vtotal;
> + num = mul_u32_u32(mode->clock, 1000);
> + den = mul_u32_u32(mode->htotal, mode->vtotal);
>
> if (mode->flags & DRM_MODE_FLAG_INTERLACE)
> num *= 2;
> @@ -1300,7 +1300,10 @@ int drm_mode_vrefresh(const struct drm_display_mode *mode)
> if (mode->vscan > 1)
> den *= mode->vscan;
>
> - return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
> + if (unlikely(den > UINT_MAX))
> + return DIV64_U64_ROUND_CLOSEST(num, den);
> +
> + return DIV_ROUND_CLOSEST_ULL(num, (u32) den);
> }
> EXPORT_SYMBOL(drm_mode_vrefresh);
--
Jani Nikula, Intel Open Source Graphics Center
^ permalink raw reply [flat|nested] 10+ messages in thread