Re: [patch] gru: fix a sanity test in gru_set_context_option()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, May 19, 2013 at 03:59:50PM +0300, Dan Carpenter wrote:
> "req.val1 == -1" is valid but it doesn't make sense to check
> gru_base[-1].  gru_base[] is a global array.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
> 
> diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c
> index c4acac7..e7c37b2 100644
> --- a/drivers/misc/sgi-gru/grufault.c
> +++ b/drivers/misc/sgi-gru/grufault.c
> @@ -876,7 +876,8 @@ int gru_set_context_option(unsigned long arg)
>  	switch (req.op) {
>  	case sco_blade_chiplet:
>  		/* Select blade/chiplet for GRU context */
> -		if (req.val1 < -1 || req.val1 >= GRU_MAX_BLADES || !gru_base[req.val1] ||
> +		if (req.val1 < -1 || req.val1 >= GRU_MAX_BLADES ||
> +		    (req.val1 != -1 && !gru_base[req.val1]) ||
>  		    req.val0 < -1 || req.val0 >= GRU_CHIPLETS_PER_HUB) {
>  			ret = -EINVAL;
>  		} else {

Since we're here, maybe we should neaten this up a little?

Signed-off-by: Dimitri Sivanich <sivanich@xxxxxxx>
---
 drivers/misc/sgi-gru/grufault.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Index: linux/drivers/misc/sgi-gru/grufault.c
===================================================================
--- linux.orig/drivers/misc/sgi-gru/grufault.c
+++ linux/drivers/misc/sgi-gru/grufault.c
@@ -876,8 +876,9 @@ int gru_set_context_option(unsigned long
 	switch (req.op) {
 	case sco_blade_chiplet:
 		/* Select blade/chiplet for GRU context */
-		if (req.val1 < -1 || req.val1 >= GRU_MAX_BLADES || !gru_base[req.val1] ||
-		    req.val0 < -1 || req.val0 >= GRU_CHIPLETS_PER_HUB) {
+		if (req.val0 < -1 || req.val0 >= GRU_CHIPLETS_PER_HUB ||
+			req.val1 < -1 || req.val1 >= GRU_MAX_BLADES ||
+			(req.val1 >= 0 && !gru_base[req.val1])) {
 			ret = -EINVAL;
 		} else {
 			gts->ts_user_blade_id = req.val1;
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux