aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Carpenter <error27@gmail.com>2011-02-25 20:48:18 -0500
committerDave Airlie <airlied@redhat.com>2011-02-27 18:17:59 -0500
commitcf8a47d1561a44f77f0269834a669e377b382f62 (patch)
treeafda20204b6cd3744db6d87f6df1009915d6853c
parentdc87eaf1771d15152ca379a0b7c32df57a0e87dc (diff)
drm/radeon/r600_cs: off by one errors
There are a bunch of off by one errors in the sanity checks here. Signed-off-by: Dan Carpenter <error27@gmail.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r--drivers/gpu/drm/radeon/r600_cs.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
index 4706294f0ae0..fa7c6e58205b 100644
--- a/drivers/gpu/drm/radeon/r600_cs.c
+++ b/drivers/gpu/drm/radeon/r600_cs.c
@@ -159,7 +159,7 @@ static const struct gpu_formats color_formats_table[] = {
159 159
160static inline bool fmt_is_valid_color(u32 format) 160static inline bool fmt_is_valid_color(u32 format)
161{ 161{
162 if (format > ARRAY_SIZE(color_formats_table)) 162 if (format >= ARRAY_SIZE(color_formats_table))
163 return false; 163 return false;
164 164
165 if (color_formats_table[format].valid_color) 165 if (color_formats_table[format].valid_color)
@@ -170,7 +170,7 @@ static inline bool fmt_is_valid_color(u32 format)
170 170
171static inline bool fmt_is_valid_texture(u32 format) 171static inline bool fmt_is_valid_texture(u32 format)
172{ 172{
173 if (format > ARRAY_SIZE(color_formats_table)) 173 if (format >= ARRAY_SIZE(color_formats_table))
174 return false; 174 return false;
175 175
176 if (color_formats_table[format].blockwidth > 0) 176 if (color_formats_table[format].blockwidth > 0)
@@ -181,7 +181,7 @@ static inline bool fmt_is_valid_texture(u32 format)
181 181
182static inline int fmt_get_blocksize(u32 format) 182static inline int fmt_get_blocksize(u32 format)
183{ 183{
184 if (format > ARRAY_SIZE(color_formats_table)) 184 if (format >= ARRAY_SIZE(color_formats_table))
185 return 0; 185 return 0;
186 186
187 return color_formats_table[format].blocksize; 187 return color_formats_table[format].blocksize;
@@ -190,7 +190,8 @@ static inline int fmt_get_blocksize(u32 format)
190static inline int fmt_get_nblocksx(u32 format, u32 w) 190static inline int fmt_get_nblocksx(u32 format, u32 w)
191{ 191{
192 unsigned bw; 192 unsigned bw;
193 if (format > ARRAY_SIZE(color_formats_table)) 193
194 if (format >= ARRAY_SIZE(color_formats_table))
194 return 0; 195 return 0;
195 196
196 bw = color_formats_table[format].blockwidth; 197 bw = color_formats_table[format].blockwidth;
@@ -203,7 +204,8 @@ static inline int fmt_get_nblocksx(u32 format, u32 w)
203static inline int fmt_get_nblocksy(u32 format, u32 h) 204static inline int fmt_get_nblocksy(u32 format, u32 h)
204{ 205{
205 unsigned bh; 206 unsigned bh;
206 if (format > ARRAY_SIZE(color_formats_table)) 207
208 if (format >= ARRAY_SIZE(color_formats_table))
207 return 0; 209 return 0;
208 210
209 bh = color_formats_table[format].blockheight; 211 bh = color_formats_table[format].blockheight;
@@ -216,7 +218,8 @@ static inline int fmt_get_nblocksy(u32 format, u32 h)
216static inline int r600_bpe_from_format(u32 *bpe, u32 format) 218static inline int r600_bpe_from_format(u32 *bpe, u32 format)
217{ 219{
218 unsigned res; 220 unsigned res;
219 if (format > ARRAY_SIZE(color_formats_table)) 221
222 if (format >= ARRAY_SIZE(color_formats_table))
220 goto fail; 223 goto fail;
221 224
222 res = color_formats_table[format].blocksize; 225 res = color_formats_table[format].blocksize;