* [PATCH] agp: check for index out of range before accessing maxes_table[index]
@ 2018-09-06 11:19 Colin King
0 siblings, 0 replies; only message in thread
From: Colin King @ 2018-09-06 11:19 UTC (permalink / raw)
To: David Airlie, Arnd Bergmann, Greg Kroah-Hartman
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Currently maxes_table[index] is accessed before index is checked to
be out of range. Fix this by performing the out of range check on
index first. Also don't check against a hard-coded maximum value
but use the array size instead.
Detected by static analysis with cppcheck:
"Array index 'index' is used before limits check"
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/char/agp/backend.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
index 38ffb281df97..4e07f01833a2 100644
--- a/drivers/char/agp/backend.c
+++ b/drivers/char/agp/backend.c
@@ -121,7 +121,8 @@ static int agp_find_max(void)
#endif
index = 1;
- while ((memory > maxes_table[index].mem) && (index < 8))
+ while ((index < ARRAY_SIZE(maxes_table) - 1) &&
+ (memory > maxes_table[index].mem))
index++;
result = maxes_table[index - 1].agp +
--
2.17.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-09-06 11:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-06 11:19 [PATCH] agp: check for index out of range before accessing maxes_table[index] Colin King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).