drm/imagination: avoid -Woverflow warning
Subsystems (3)
PATCH RESEND 1/1 drm/imagination: avoid -Woverflow warning
From: Arnd Bergmann <[email protected]>
The array size calculation in pvr_vm_mips_fini() appears to be incorrect based on taking the size of the pointer rather than the size of the array, which manifests as a warning about signed integer overflow:
In file included from include/linux/kernel.h:16,
from drivers/gpu/drm/imagination/pvr_rogue_fwif.h:10,
from drivers/gpu/drm/imagination/pvr_ccb.h:7,
from drivers/gpu/drm/imagination/pvr_device.h:7,
from drivers/gpu/drm/imagination/pvr_vm_mips.c:4:drivers/gpu/drm/imagination/pvr_vm_mips.c: In function 'pvr_vm_mips_fini':include/linux/array_size.h:11:25: error: overflow in conversion from 'long unsigned int' to 'int' changes value from '18446744073709551615' to '-1' [-Werror=overflow]
11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
| ^drivers/gpu/drm/imagination/pvr_vm_mips.c:106:24: note: in expansion of macro 'ARRAY_SIZE'
106 | for (page_nr = ARRAY_SIZE(mips_data->pt_pages) - 1; page_nr >= 0; page_nr--) {
| ^~~~~~~~~~Just use the number of array elements directly here, and in the corresponding init function for consistency.
---
I sent this one last year when the warning appeared, it looks like it got lost in the meantime, resending it unchanged.
--- drivers/gpu/drm/imagination/pvr_vm_mips.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/imagination/pvr_vm_mips.c +2 -2
@@ -46,7 +46,7 @@ pvr_vm_mips_init(struct pvr_device *pvr_dev)if (!mips_data)return -ENOMEM ; -for (page_nr =0 ; page_nr <ARRAY_SIZE (mips_data->pt_pages); page_nr++) { +for (page_nr =0 ; page_nr <PVR_MIPS_PT_PAGE_COUNT ; page_nr++) { mips_data->pt_pages[page_nr] =alloc_page (GFP_KERNEL | __GFP_ZERO);if (!mips_data->pt_pages[page_nr]) { err = -ENOMEM ;
@@ -102,7 +102,7 @@ pvr_vm_mips_fini(struct pvr_device *pvr_dev)int page_nr;vunmap (mips_data->pt); -for (page_nr =ARRAY_SIZE (mips_data->pt_pages) -1 ; page_nr >=0 ; page_nr--) { +for (page_nr =PVR_MIPS_PT_PAGE_COUNT -1 ; page_nr >=0 ; page_nr--) {dma_unmap_page (from_pvr_device (pvr_dev)->dev, mips_data->pt_dma_addr[page_nr],PAGE_SIZE ,DMA_TO_DEVICE );
Signature · 1 line
2.39.2
Quoted 22 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The array size calculation in
pvr_vm_mips_fini()appears to be incorrect based on taking the size of the pointer rather than the size of the array, which manifests as a warning about signed integer overflow:In file included from
include/linux/kernel.h:16,
fromdrivers/gpu/drm/imagination/pvr_rogue_fwif.h:10,
fromdrivers/gpu/drm/imagination/pvr_ccb.h:7,
fromdrivers/gpu/drm/imagination/pvr_device.h:7,
fromdrivers/gpu/drm/imagination/pvr_vm_mips.c:4:drivers/gpu/drm/imagination/pvr_vm_mips.c: In function 'pvr_vm_mips_fini':include/linux/array_size.h:11:25: error: overflow in conversion from 'long unsigned int' to 'int' changes value from '18446744073709551615' to '-1' [-Werror=overflow]
11 | #defineARRAY_SIZE(arr)(sizeof(arr) / sizeof((arr)[0]) +__must_be_array(arr))
| ^drivers/gpu/drm/imagination/pvr_vm_mips.c:106:24: note: in expansion of macro 'ARRAY_SIZE'106 | for (page_nr = ARRAY_SIZE(mips_data->pt_pages) - 1; page_nr >= 0; page_nr--) { | ^~~~~~~~~~Just use the number of array elements directly here, and in the corresponding init function for consistency.
Quoted 7 lines
Fixes 927f3e0253c1 ("drm/imagination: Implement MIPS firmware processor and MMU support")Reviewed-by Donald Robson <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>---
I sent this one last year when the warning appeared, it looks like it got lost in the meantime, resending it unchanged.
Apologies for letting this slip through the cracks last year - applied to drm-misc-next.
Thanks for resending!
Cheers,
Matt
Quoted 26 lines
--- drivers/gpu/drm/imagination/pvr_vm_mips.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/imagination/pvr_vm_mips.c +2
-2@@ -46,7 +46,7 @@ pvr_vm_mips_init(struct pvr_device *pvr_dev)if (!mips_data)return -ENOMEM ; -for (page_nr =0 ; page_nr <ARRAY_SIZE (mips_data->pt_pages); page_nr++) { +for (page_nr =0 ; page_nr <PVR_MIPS_PT_PAGE_COUNT ; page_nr++) { mips_data->pt_pages[page_nr] =alloc_page (GFP_KERNEL | __GFP_ZERO);if (!mips_data->pt_pages[page_nr]) { err = -ENOMEM ;@@ -102,7 +102,7 @@ pvr_vm_mips_fini(struct pvr_device *pvr_dev)int page_nr;vunmap (mips_data->pt); -for (page_nr =ARRAY_SIZE (mips_data->pt_pages) -1 ; page_nr >=0 ; page_nr--) { +for (page_nr =PVR_MIPS_PT_PAGE_COUNT -1 ; page_nr >=0 ; page_nr--) {dma_unmap_page (from_pvr_device (pvr_dev)->dev, mips_data->pt_dma_addr[page_nr],PAGE_SIZE ,DMA_TO_DEVICE );