From 41283a02ac6837f01e1e67fca859ffd552c3ede0 Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Mon, 11 Sep 2017 06:13:38 -0700 Subject: gpu: nvgpu: fix UBSAN warning of signed integer overflow Fix below warning reported by UBSAN by explicitly type casting both the operators in multiplication as unsigned long [ 69.470802] UBSAN: Undefined behaviour in drivers/gpu/../../../nvgpu/drivers/gpu/nvgpu/gk20a/gk20a_scale.c:60:49 [ 69.485519] signed integer overflow: [ 69.489104] 2147483647 * 1000 cannot be represented in type 'int' [ 69.504424] Hardware name: quill (DT) [ 69.508088] Call trace: [ 69.510579] [] dump_backtrace+0x0/0x4f0 [ 69.515987] [] show_stack+0x28/0x38 [ 69.521050] [] dump_stack+0x154/0x1c4 [ 69.526291] [] ubsan_epilogue+0x18/0xb0 [ 69.531720] [] handle_overflow+0x1c0/0x21c [ 69.537416] [] __ubsan_handle_mul_overflow+0x34/0x50 [ 69.544410] [] gk20a_scale_qos_notify+0x210/0x2f0 [nvgpu] [ 69.551415] [] __blocking_notifier_call_chain+0xec/0x240 [ 69.558299] [] blocking_notifier_call_chain+0x40/0x50 [ 69.564928] [] pm_qos_update_bounded_target+0x738/0x1038 [ 69.571812] [] pm_qos_update_bounded_req+0x148/0x280 [ 69.578348] [] pm_qos_bounded_write+0x484/0x990 Bug 200342586 Change-Id: I35ee59a95b2e3625fb42f256d2877558be9e51cf Signed-off-by: Deepak Nibade Reviewed-on: https://git-master.nvidia.com/r/1557156 Reviewed-by: svc-mobile-coverity Reviewed-by: svccoveritychecker GVS: Gerrit_Virtual_Submit Reviewed-by: Pritesh Raithatha Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/gk20a_scale.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/nvgpu/gk20a/gk20a_scale.c b/drivers/gpu/nvgpu/gk20a/gk20a_scale.c index 3e6fead6..4ee4f8ab 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a_scale.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a_scale.c @@ -55,9 +55,9 @@ int gk20a_scale_qos_notify(struct notifier_block *nb, mutex_lock(&devfreq->lock); /* check for pm_qos min and max frequency requirement */ profile->qos_min_freq = - pm_qos_read_min_bound(PM_QOS_GPU_FREQ_BOUNDS) * 1000; + (unsigned long)pm_qos_read_min_bound(PM_QOS_GPU_FREQ_BOUNDS) * 1000UL; profile->qos_max_freq = - pm_qos_read_max_bound(PM_QOS_GPU_FREQ_BOUNDS) * 1000; + (unsigned long)pm_qos_read_max_bound(PM_QOS_GPU_FREQ_BOUNDS) * 1000UL; if (profile->qos_min_freq > profile->qos_max_freq) { nvgpu_err(g, -- cgit v1.2.2