public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: David Airlie <airlied@linux.ie>
Cc: kernel-janitors@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: [patch] drm/radeon/r600_cs: off by one errors
Date: Sat, 26 Feb 2011 01:48:18 +0000	[thread overview]
Message-ID: <20110226014818.GB18043@bicker> (raw)

There are a bunch of off by one errors in the sanity checks here.

Signed-off-by: Dan Carpenter <error27@gmail.com>

diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
index 79ac676..41da786 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[] = {
 
 static inline bool fmt_is_valid_color(u32 format)
 {
-	if (format > ARRAY_SIZE(color_formats_table))
+	if (format >= ARRAY_SIZE(color_formats_table))
 		return false;
 	
 	if (color_formats_table[format].valid_color)
@@ -170,7 +170,7 @@ static inline bool fmt_is_valid_color(u32 format)
 
 static inline bool fmt_is_valid_texture(u32 format)
 {
-	if (format > ARRAY_SIZE(color_formats_table))
+	if (format >= ARRAY_SIZE(color_formats_table))
 		return false;
 	
 	if (color_formats_table[format].blockwidth > 0)
@@ -181,7 +181,7 @@ static inline bool fmt_is_valid_texture(u32 format)
 
 static inline int fmt_get_blocksize(u32 format)
 {
-	if (format > ARRAY_SIZE(color_formats_table))
+	if (format >= ARRAY_SIZE(color_formats_table))
 		return 0;
 
 	return color_formats_table[format].blocksize;
@@ -190,7 +190,8 @@ static inline int fmt_get_blocksize(u32 format)
 static inline int fmt_get_nblocksx(u32 format, u32 w)
 {
 	unsigned bw;
-	if (format > ARRAY_SIZE(color_formats_table))
+
+	if (format >= ARRAY_SIZE(color_formats_table))
 		return 0;
 
 	bw = color_formats_table[format].blockwidth;
@@ -203,7 +204,8 @@ static inline int fmt_get_nblocksx(u32 format, u32 w)
 static inline int fmt_get_nblocksy(u32 format, u32 h)
 {
 	unsigned bh;
-	if (format > ARRAY_SIZE(color_formats_table))
+
+	if (format >= ARRAY_SIZE(color_formats_table))
 		return 0;
 
 	bh = color_formats_table[format].blockheight;
@@ -216,7 +218,8 @@ static inline int fmt_get_nblocksy(u32 format, u32 h)
 static inline int r600_bpe_from_format(u32 *bpe, u32 format)
 {
  	unsigned res;
-	if (format > ARRAY_SIZE(color_formats_table))
+
+	if (format >= ARRAY_SIZE(color_formats_table))
 		goto fail;
 
 	res = color_formats_table[format].blocksize;

                 reply	other threads:[~2011-02-26  1:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110226014818.GB18043@bicker \
    --to=error27@gmail.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel-janitors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox