diff options
author | Thomas Hellstrom <thellstrom@vmware.com> | 2014-02-12 06:56:48 -0500 |
---|---|---|
committer | Thomas Hellstrom <thellstrom@vmware.com> | 2014-02-12 13:30:45 -0500 |
commit | b055211d941eb6cb7b285be580cf6e51a01d2f44 (patch) | |
tree | 1d04d63c2aff94dd294a1529df6a7caf957bf9d3 /drivers/gpu/drm/vmwgfx | |
parent | 4fbd9d2ec2f12ffb292c1489d1402e8b956afc01 (diff) |
drm/vmwgfx: Fix possible integer overflow
Cc: stable@vger.kernel.org
Reported-by: Brian Paul <brianp@vmware.com>
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
Diffstat (limited to 'drivers/gpu/drm/vmwgfx')
-rw-r--r-- | drivers/gpu/drm/vmwgfx/svga3d_surfacedefs.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/drivers/gpu/drm/vmwgfx/svga3d_surfacedefs.h b/drivers/gpu/drm/vmwgfx/svga3d_surfacedefs.h index 8369c3ba10fe..ef3385096145 100644 --- a/drivers/gpu/drm/vmwgfx/svga3d_surfacedefs.h +++ b/drivers/gpu/drm/vmwgfx/svga3d_surfacedefs.h | |||
@@ -38,8 +38,11 @@ | |||
38 | 38 | ||
39 | #define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y)) | 39 | #define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y)) |
40 | #define max_t(type, x, y) ((x) > (y) ? (x) : (y)) | 40 | #define max_t(type, x, y) ((x) > (y) ? (x) : (y)) |
41 | #define min_t(type, x, y) ((x) < (y) ? (x) : (y)) | ||
41 | #define surf_size_struct SVGA3dSize | 42 | #define surf_size_struct SVGA3dSize |
42 | #define u32 uint32 | 43 | #define u32 uint32 |
44 | #define u64 uint64_t | ||
45 | #define U32_MAX ((u32)~0U) | ||
43 | 46 | ||
44 | #endif /* __KERNEL__ */ | 47 | #endif /* __KERNEL__ */ |
45 | 48 | ||
@@ -704,8 +707,8 @@ static const struct svga3d_surface_desc svga3d_surface_descs[] = { | |||
704 | 707 | ||
705 | static inline u32 clamped_umul32(u32 a, u32 b) | 708 | static inline u32 clamped_umul32(u32 a, u32 b) |
706 | { | 709 | { |
707 | uint64_t tmp = (uint64_t) a*b; | 710 | u64 tmp = (u64) a*b; |
708 | return (tmp > (uint64_t) ((u32) -1)) ? (u32) -1 : tmp; | 711 | return (tmp > (u64) U32_MAX) ? U32_MAX : tmp; |
709 | } | 712 | } |
710 | 713 | ||
711 | static inline const struct svga3d_surface_desc * | 714 | static inline const struct svga3d_surface_desc * |
@@ -834,7 +837,7 @@ svga3dsurface_get_serialized_size(SVGA3dSurfaceFormat format, | |||
834 | bool cubemap) | 837 | bool cubemap) |
835 | { | 838 | { |
836 | const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(format); | 839 | const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(format); |
837 | u32 total_size = 0; | 840 | u64 total_size = 0; |
838 | u32 mip; | 841 | u32 mip; |
839 | 842 | ||
840 | for (mip = 0; mip < num_mip_levels; mip++) { | 843 | for (mip = 0; mip < num_mip_levels; mip++) { |
@@ -847,7 +850,7 @@ svga3dsurface_get_serialized_size(SVGA3dSurfaceFormat format, | |||
847 | if (cubemap) | 850 | if (cubemap) |
848 | total_size *= SVGA3D_MAX_SURFACE_FACES; | 851 | total_size *= SVGA3D_MAX_SURFACE_FACES; |
849 | 852 | ||
850 | return total_size; | 853 | return (u32) min_t(u64, total_size, (u64) U32_MAX); |
851 | } | 854 | } |
852 | 855 | ||
853 | 856 | ||