public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] ipmi: make static checkers happy about range checks
@ 2010-09-17 19:26 Dan Carpenter
  2010-09-18 19:19 ` Corey Minyard
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2010-09-17 19:26 UTC (permalink / raw)
  To: kernel-janitors

I'm working on a Smatch check that complains that addr->channel comes
from the user and it might be negative.  It actually can *not* be
negative because we already checked that when we called
ipmi_validate_addr() from handle_send_req().  Also it can't be greater
than or equal to IPMI_MAX_CHANNELS because we already verified that as
well.

Although this change doesn't do anything, it's still a cleanup because
it makes the checking consistent and also it silences the static
analysis warnings.

Signed-off-by: Dan Carpenter <error27@gmail.com>
---
Really, I would prefer to just make ->channel unsigned but the type
comes from the IPMI spec.

diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 4f3f8c9..57f4c80 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -1527,7 +1527,7 @@ static int i_ipmi_request(ipmi_user_t          user,
 		long                  seqid;
 		int                   broadcast = 0;
 
-		if (addr->channel >= IPMI_MAX_CHANNELS) {
+		if (addr->channel < 0 || addr->channel >= IPMI_MAX_CHANNELS) {
 			ipmi_inc_stat(intf, sent_invalid_commands);
 			rv = -EINVAL;
 			goto out_err;
@@ -1657,7 +1657,7 @@ static int i_ipmi_request(ipmi_user_t          user,
 		unsigned char         ipmb_seq;
 		long                  seqid;
 
-		if (addr->channel >= IPMI_MAX_CHANNELS) {
+		if (addr->channel < 0 || addr->channel >= IPMI_MAX_CHANNELS) {
 			ipmi_inc_stat(intf, sent_invalid_commands);
 			rv = -EINVAL;
 			goto out_err;
@@ -1797,7 +1797,7 @@ static int check_addr(ipmi_smi_t       intf,
 		      unsigned char    *saddr,
 		      unsigned char    *lun)
 {
-	if (addr->channel >= IPMI_MAX_CHANNELS)
+	if (addr->channel < 0 || addr->channel >= IPMI_MAX_CHANNELS)
 		return -EINVAL;
 	*lun = intf->channels[addr->channel].lun;
 	*saddr = intf->channels[addr->channel].address;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch] ipmi: make static checkers happy about range checks
  2010-09-17 19:26 [patch] ipmi: make static checkers happy about range checks Dan Carpenter
@ 2010-09-18 19:19 ` Corey Minyard
  0 siblings, 0 replies; 2+ messages in thread
From: Corey Minyard @ 2010-09-18 19:19 UTC (permalink / raw)
  To: kernel-janitors

I'm ok with this, I don't think it will make any real difference besides 
the compiler converting that comparison to unsigned.  I wish I had made 
that unsigned.

-corey

On 09/17/2010 02:26 PM, Dan Carpenter wrote:
> I'm working on a Smatch check that complains that addr->channel comes
> from the user and it might be negative.  It actually can *not* be
> negative because we already checked that when we called
> ipmi_validate_addr() from handle_send_req().  Also it can't be greater
> than or equal to IPMI_MAX_CHANNELS because we already verified that as
> well.
>
> Although this change doesn't do anything, it's still a cleanup because
> it makes the checking consistent and also it silences the static
> analysis warnings.
>
> Signed-off-by: Dan Carpenter<error27@gmail.com>
> ---
> Really, I would prefer to just make ->channel unsigned but the type
> comes from the IPMI spec.
>
> diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
> index 4f3f8c9..57f4c80 100644
> --- a/drivers/char/ipmi/ipmi_msghandler.c
> +++ b/drivers/char/ipmi/ipmi_msghandler.c
> @@ -1527,7 +1527,7 @@ static int i_ipmi_request(ipmi_user_t          user,
>   		long                  seqid;
>   		int                   broadcast = 0;
>
> -		if (addr->channel>= IPMI_MAX_CHANNELS) {
> +		if (addr->channel<  0 || addr->channel>= IPMI_MAX_CHANNELS) {
>   			ipmi_inc_stat(intf, sent_invalid_commands);
>   			rv = -EINVAL;
>   			goto out_err;
> @@ -1657,7 +1657,7 @@ static int i_ipmi_request(ipmi_user_t          user,
>   		unsigned char         ipmb_seq;
>   		long                  seqid;
>
> -		if (addr->channel>= IPMI_MAX_CHANNELS) {
> +		if (addr->channel<  0 || addr->channel>= IPMI_MAX_CHANNELS) {
>   			ipmi_inc_stat(intf, sent_invalid_commands);
>   			rv = -EINVAL;
>   			goto out_err;
> @@ -1797,7 +1797,7 @@ static int check_addr(ipmi_smi_t       intf,
>   		      unsigned char    *saddr,
>   		      unsigned char    *lun)
>   {
> -	if (addr->channel>= IPMI_MAX_CHANNELS)
> +	if (addr->channel<  0 || addr->channel>= IPMI_MAX_CHANNELS)
>   		return -EINVAL;
>   	*lun = intf->channels[addr->channel].lun;
>   	*saddr = intf->channels[addr->channel].address;
>    


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-09-18 19:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-17 19:26 [patch] ipmi: make static checkers happy about range checks Dan Carpenter
2010-09-18 19:19 ` Corey Minyard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox