virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 09/14] xen: events: Remove redundant check on unsigned variable
       [not found] <1353048646-10935-1-git-send-email-tushar.behera@linaro.org>
@ 2012-11-16  6:50 ` Tushar Behera
       [not found] ` <1353048646-10935-10-git-send-email-tushar.behera@linaro.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-16  6:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jeremy Fitzhardinge, Konrad Rzeszutek Wilk, virtualization,
	xen-devel, patches

No need to check whether unsigned variable is less than 0.

CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
CC: Jeremy Fitzhardinge <jeremy@goop.org>
CC: xen-devel@lists.xensource.com
CC: virtualization@lists.linux-foundation.org
Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
---
 drivers/xen/events.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/xen/events.c b/drivers/xen/events.c
index 4293c57..cadd7d1 100644
--- a/drivers/xen/events.c
+++ b/drivers/xen/events.c
@@ -216,7 +216,7 @@ static void xen_irq_info_pirq_init(unsigned irq,
  */
 static unsigned int evtchn_from_irq(unsigned irq)
 {
-	if (unlikely(WARN(irq < 0 || irq >= nr_irqs, "Invalid irq %d!\n", irq)))
+	if (unlikely(WARN(irq >= nr_irqs, "Invalid irq %d!\n", irq)))
 		return 0;
 
 	return info_for_irq(irq)->evtchn;
-- 
1.7.4.1

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

* Re: [PATCH 09/14] xen: events: Remove redundant check on unsigned variable
       [not found] ` <1353048646-10935-10-git-send-email-tushar.behera@linaro.org>
@ 2012-11-16 16:09   ` Konrad Rzeszutek Wilk
  2012-11-16 16:53     ` Jeremy Fitzhardinge
       [not found]     ` <b0cd27cf-919f-46b0-afa1-4566f6ea0f61@email.android.com>
  0 siblings, 2 replies; 6+ messages in thread
From: Konrad Rzeszutek Wilk @ 2012-11-16 16:09 UTC (permalink / raw)
  To: Tushar Behera
  Cc: Jeremy Fitzhardinge, xen-devel, virtualization, linux-kernel,
	patches

On Fri, Nov 16, 2012 at 12:20:41PM +0530, Tushar Behera wrote:
> No need to check whether unsigned variable is less than 0.
> 
> CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

> CC: Jeremy Fitzhardinge <jeremy@goop.org>
> CC: xen-devel@lists.xensource.com
> CC: virtualization@lists.linux-foundation.org
> Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
> ---
>  drivers/xen/events.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/xen/events.c b/drivers/xen/events.c
> index 4293c57..cadd7d1 100644
> --- a/drivers/xen/events.c
> +++ b/drivers/xen/events.c
> @@ -216,7 +216,7 @@ static void xen_irq_info_pirq_init(unsigned irq,
>   */
>  static unsigned int evtchn_from_irq(unsigned irq)
>  {
> -	if (unlikely(WARN(irq < 0 || irq >= nr_irqs, "Invalid irq %d!\n", irq)))
> +	if (unlikely(WARN(irq >= nr_irqs, "Invalid irq %d!\n", irq)))
>  		return 0;
>  
>  	return info_for_irq(irq)->evtchn;
> -- 
> 1.7.4.1

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

* Re: [PATCH 09/14] xen: events: Remove redundant check on unsigned variable
  2012-11-16 16:09   ` Konrad Rzeszutek Wilk
@ 2012-11-16 16:53     ` Jeremy Fitzhardinge
       [not found]     ` <b0cd27cf-919f-46b0-afa1-4566f6ea0f61@email.android.com>
  1 sibling, 0 replies; 6+ messages in thread
From: Jeremy Fitzhardinge @ 2012-11-16 16:53 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk, Tushar Behera
  Cc: xen-devel, virtualization, linux-kernel, patches


[-- Attachment #1.1: Type: text/plain, Size: 1501 bytes --]

To be honest I'd nack this kind of patch. The test is only redundant in the most trivial sense that the compiler can easily optimise away. The point of the test is to make sure that the range is OK even if the type subsequently becomes signed (to hold a -ve error, for example).

J

Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> wrote:

>On Fri, Nov 16, 2012 at 12:20:41PM +0530, Tushar Behera wrote:
>> No need to check whether unsigned variable is less than 0.
>> 
>> CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
>
>Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
>
>> CC: Jeremy Fitzhardinge <jeremy@goop.org>
>> CC: xen-devel@lists.xensource.com
>> CC: virtualization@lists.linux-foundation.org
>> Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
>> ---
>>  drivers/xen/events.c |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>> 
>> diff --git a/drivers/xen/events.c b/drivers/xen/events.c
>> index 4293c57..cadd7d1 100644
>> --- a/drivers/xen/events.c
>> +++ b/drivers/xen/events.c
>> @@ -216,7 +216,7 @@ static void xen_irq_info_pirq_init(unsigned irq,
>>   */
>>  static unsigned int evtchn_from_irq(unsigned irq)
>>  {
>> -	if (unlikely(WARN(irq < 0 || irq >= nr_irqs, "Invalid irq %d!\n",
>irq)))
>> +	if (unlikely(WARN(irq >= nr_irqs, "Invalid irq %d!\n", irq)))
>>  		return 0;
>>  
>>  	return info_for_irq(irq)->evtchn;
>> -- 
>> 1.7.4.1

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

[-- Attachment #1.2: Type: text/html, Size: 2231 bytes --]

[-- Attachment #2: Type: text/plain, Size: 183 bytes --]

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH 09/14] xen: events: Remove redundant check on unsigned variable
       [not found]     ` <b0cd27cf-919f-46b0-afa1-4566f6ea0f61@email.android.com>
@ 2012-11-19  3:52       ` Tushar Behera
  2012-11-19 10:31         ` [Xen-devel] " Ian Campbell
       [not found]         ` <1353321075.18229.29.camel@zakaz.uk.xensource.com>
  0 siblings, 2 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-19  3:52 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: xen-devel, patches, virtualization, linux-kernel,
	Konrad Rzeszutek Wilk

On 11/16/2012 10:23 PM, Jeremy Fitzhardinge wrote:
> To be honest I'd nack this kind of patch. The test is only redundant in the most trivial sense that the compiler can easily optimise away. The point of the test is to make sure that the range is OK even if the type subsequently becomes signed (to hold a -ve error, for example).
> 
> J
> 

The check is on the function argument which is unsigned, so checking '<
0' doesn't make sense. We should force signed check only if the argument
is of signed type. In any case, even if irq has been assigned some error
value, that would be caught by the check irq >= nr_irqs.

> Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> wrote:
> 
>> On Fri, Nov 16, 2012 at 12:20:41PM +0530, Tushar Behera wrote:
>>> No need to check whether unsigned variable is less than 0.
>>>
>>> CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
>>
>> Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
>>
>>> CC: Jeremy Fitzhardinge <jeremy@goop.org>
>>> CC: xen-devel@lists.xensource.com
>>> CC: virtualization@lists.linux-foundation.org
>>> Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
>>> ---
>>>  drivers/xen/events.c |    2 +-
>>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/drivers/xen/events.c b/drivers/xen/events.c
>>> index 4293c57..cadd7d1 100644
>>> --- a/drivers/xen/events.c
>>> +++ b/drivers/xen/events.c
>>> @@ -216,7 +216,7 @@ static void xen_irq_info_pirq_init(unsigned irq,
>>>   */
>>>  static unsigned int evtchn_from_irq(unsigned irq)
>>>  {
>>> -	if (unlikely(WARN(irq < 0 || irq >= nr_irqs, "Invalid irq %d!\n",
>> irq)))
>>> +	if (unlikely(WARN(irq >= nr_irqs, "Invalid irq %d!\n", irq)))
>>>  		return 0;
>>>  
>>>  	return info_for_irq(irq)->evtchn;
>>> -- 
>>> 1.7.4.1
> 


-- 
Tushar Behera

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

* Re: [Xen-devel] [PATCH 09/14] xen: events: Remove redundant check on unsigned variable
  2012-11-19  3:52       ` Tushar Behera
@ 2012-11-19 10:31         ` Ian Campbell
       [not found]         ` <1353321075.18229.29.camel@zakaz.uk.xensource.com>
  1 sibling, 0 replies; 6+ messages in thread
From: Ian Campbell @ 2012-11-19 10:31 UTC (permalink / raw)
  To: Tushar Behera
  Cc: Jeremy Fitzhardinge, xen-devel@lists.xensource.com,
	Konrad Rzeszutek Wilk, patches@linaro.org,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org

On Mon, 2012-11-19 at 03:52 +0000, Tushar Behera wrote:
> On 11/16/2012 10:23 PM, Jeremy Fitzhardinge wrote:
> > To be honest I'd nack this kind of patch. The test is only redundant in the most trivial sense that the compiler can easily optimise away. The point of the test is to make sure that the range is OK even if the type subsequently becomes signed (to hold a -ve error, for example).
> > 
> > J
> > 
> 
> The check is on the function argument which is unsigned, so checking '<
> 0' doesn't make sense. We should force signed check only if the argument
> is of signed type. In any case, even if irq has been assigned some error
> value, that would be caught by the check irq >= nr_irqs.

Jeremy is (I think) arguing that this check is not redundant because
someone might change the type of the argument to be signed and until
then the compiler can trivially optimise the check away, so what's the
harm in it?

I'm somewhat inclined to agree with him.

Ian.

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

* Re: [Xen-devel] [PATCH 09/14] xen: events: Remove redundant check on unsigned variable
       [not found]         ` <1353321075.18229.29.camel@zakaz.uk.xensource.com>
@ 2012-11-19 11:00           ` Tushar Behera
  0 siblings, 0 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-19 11:00 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Jeremy Fitzhardinge, xen-devel@lists.xensource.com,
	Konrad Rzeszutek Wilk, patches@linaro.org,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org

On 11/19/2012 04:01 PM, Ian Campbell wrote:
> On Mon, 2012-11-19 at 03:52 +0000, Tushar Behera wrote:
>> On 11/16/2012 10:23 PM, Jeremy Fitzhardinge wrote:
>>> To be honest I'd nack this kind of patch. The test is only redundant in the most trivial sense that the compiler can easily optimise away. The point of the test is to make sure that the range is OK even if the type subsequently becomes signed (to hold a -ve error, for example).
>>>
>>> J
>>>
>>
>> The check is on the function argument which is unsigned, so checking '<
>> 0' doesn't make sense. We should force signed check only if the argument
>> is of signed type. In any case, even if irq has been assigned some error
>> value, that would be caught by the check irq >= nr_irqs.
> 
> Jeremy is (I think) arguing that this check is not redundant because
> someone might change the type of the argument to be signed and until
> then the compiler can trivially optimise the check away, so what's the
> harm in it?
> 
> I'm somewhat inclined to agree with him.
> 
> Ian.
> 
Ok, I don't have much argument against this.

-- 
Tushar Behera

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

end of thread, other threads:[~2012-11-19 11:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1353048646-10935-1-git-send-email-tushar.behera@linaro.org>
2012-11-16  6:50 ` [PATCH 09/14] xen: events: Remove redundant check on unsigned variable Tushar Behera
     [not found] ` <1353048646-10935-10-git-send-email-tushar.behera@linaro.org>
2012-11-16 16:09   ` Konrad Rzeszutek Wilk
2012-11-16 16:53     ` Jeremy Fitzhardinge
     [not found]     ` <b0cd27cf-919f-46b0-afa1-4566f6ea0f61@email.android.com>
2012-11-19  3:52       ` Tushar Behera
2012-11-19 10:31         ` [Xen-devel] " Ian Campbell
     [not found]         ` <1353321075.18229.29.camel@zakaz.uk.xensource.com>
2012-11-19 11:00           ` Tushar Behera

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).