All of lore.kernel.org
 help / color / mirror / Atom feed
From: nicolas.ferre@atmel.com (Nicolas Ferre)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] irqdomain: protect macro variable in domain iterators
Date: Fri, 02 Dec 2011 14:25:12 +0100	[thread overview]
Message-ID: <4ED8D1B8.1010009@atmel.com> (raw)
In-Reply-To: <20111202125932.GB2892@localhost.localdomain>

On 12/02/2011 01:59 PM, Dave Martin :
> On Fri, Dec 02, 2011 at 02:53:17PM +0100, Nicolas Ferre wrote:
>> Signed-off-by: Nicolas Ferre<nicolas.ferre@atmel.com>
>> ---
>> Error found while using those iterators in an irq controller
>> initialization function.
>>
>> May also need protection around irq and hwirq macro variables
>> but those values are usually plain "int" anyway... Tell me if you
>> feel that it should be done.
>>
>>   include/linux/irqdomain.h |    8 ++++----
>>   1 files changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
>> index 99834e58..a553004 100644
>> --- a/include/linux/irqdomain.h
>> +++ b/include/linux/irqdomain.h
>> @@ -82,12 +82,12 @@ static inline unsigned int irq_domain_to_irq(struct irq_domain *d,
>>   }
>>
>>   #define irq_domain_for_each_hwirq(d, hw) \
>> -	for (hw = d->hwirq_base; hw<  d->hwirq_base + d->nr_irq; hw++)
>> +	for (hw = (d)->hwirq_base; hw<  (d)->hwirq_base + (d)->nr_irq; hw++)
>>
>>   #define irq_domain_for_each_irq(d, hw, irq) \
>> -	for (hw = d->hwirq_base, irq = irq_domain_to_irq(d, hw); \
>> -	     hw<  d->hwirq_base + d->nr_irq; \
>> -	     hw++, irq = irq_domain_to_irq(d, hw))
>> +	for (hw = (d)->hwirq_base, irq = irq_domain_to_irq((d), hw); \
>> +	     hw<  (d)->hwirq_base + (d)->nr_irq; \
>> +	     hw++, irq = irq_domain_to_irq((d), hw))
>
> I suggest just putting all the brackets in -- if having spotted this
> problem you only half-fix the macros, an opportunity is being missed;
> someone have to come and fix it again later:

Exactly, this is why I added a little comment to the patch:

"May also need protection around irq and hwirq macro variables
but those values are usually plain "int" anyway... Tell me if you
feel that it should be done."

> #define irq_domain_for_each_hwirq(d, hw) \
> 	for ((hw) = (d)->hwirq_base; (hw)<  (d)->hwirq_base + (d)->nr_irq; (hw)++)
>
> #define irq_domain_for_each_irq(d, hw, irq) \
> 	for ((hw) = (d)->hwirq_base, (irq) = irq_domain_to_irq(d, hw); \
> 	     (hw)<  (d)->hwirq_base + (d)->nr_irq; \
> 	     (hw)++, (irq) = irq_domain_to_irq(d, hw))
>
>
> If you feel happier though, you can harmlessly add the extra brackets round
> the arguments to irq_domain_to_irq(), without changing the behaviour.
> Arguably the "always add brackets" rule is simpler to understand.
>
> In fact, where a macro argument is not part of a larger expression, or is an
> operand to a comma-expression, there's no need for extra brackets -- all
> possible operators parse at higher priority than commas.  A macro argument
> which itself is a comma-expression whould have to be explicitly bracketed
> in the macro invocation anyway, so there is no extra risk of the macro
> expansion being parsed in an unexpected way in that case.

Thanks for the detailed explanation. I resend the patch with the "always 
add brackets" corrections.

Best regards,
-- 
Nicolas Ferre

WARNING: multiple messages have this Message-ID (diff)
From: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
To: Dave Martin <dave.martin-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH] irqdomain: protect macro variable in domain iterators
Date: Fri, 02 Dec 2011 14:25:12 +0100	[thread overview]
Message-ID: <4ED8D1B8.1010009@atmel.com> (raw)
In-Reply-To: <20111202125932.GB2892-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>

On 12/02/2011 01:59 PM, Dave Martin :
> On Fri, Dec 02, 2011 at 02:53:17PM +0100, Nicolas Ferre wrote:
>> Signed-off-by: Nicolas Ferre<nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
>> ---
>> Error found while using those iterators in an irq controller
>> initialization function.
>>
>> May also need protection around irq and hwirq macro variables
>> but those values are usually plain "int" anyway... Tell me if you
>> feel that it should be done.
>>
>>   include/linux/irqdomain.h |    8 ++++----
>>   1 files changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
>> index 99834e58..a553004 100644
>> --- a/include/linux/irqdomain.h
>> +++ b/include/linux/irqdomain.h
>> @@ -82,12 +82,12 @@ static inline unsigned int irq_domain_to_irq(struct irq_domain *d,
>>   }
>>
>>   #define irq_domain_for_each_hwirq(d, hw) \
>> -	for (hw = d->hwirq_base; hw<  d->hwirq_base + d->nr_irq; hw++)
>> +	for (hw = (d)->hwirq_base; hw<  (d)->hwirq_base + (d)->nr_irq; hw++)
>>
>>   #define irq_domain_for_each_irq(d, hw, irq) \
>> -	for (hw = d->hwirq_base, irq = irq_domain_to_irq(d, hw); \
>> -	     hw<  d->hwirq_base + d->nr_irq; \
>> -	     hw++, irq = irq_domain_to_irq(d, hw))
>> +	for (hw = (d)->hwirq_base, irq = irq_domain_to_irq((d), hw); \
>> +	     hw<  (d)->hwirq_base + (d)->nr_irq; \
>> +	     hw++, irq = irq_domain_to_irq((d), hw))
>
> I suggest just putting all the brackets in -- if having spotted this
> problem you only half-fix the macros, an opportunity is being missed;
> someone have to come and fix it again later:

Exactly, this is why I added a little comment to the patch:

"May also need protection around irq and hwirq macro variables
but those values are usually plain "int" anyway... Tell me if you
feel that it should be done."

> #define irq_domain_for_each_hwirq(d, hw) \
> 	for ((hw) = (d)->hwirq_base; (hw)<  (d)->hwirq_base + (d)->nr_irq; (hw)++)
>
> #define irq_domain_for_each_irq(d, hw, irq) \
> 	for ((hw) = (d)->hwirq_base, (irq) = irq_domain_to_irq(d, hw); \
> 	     (hw)<  (d)->hwirq_base + (d)->nr_irq; \
> 	     (hw)++, (irq) = irq_domain_to_irq(d, hw))
>
>
> If you feel happier though, you can harmlessly add the extra brackets round
> the arguments to irq_domain_to_irq(), without changing the behaviour.
> Arguably the "always add brackets" rule is simpler to understand.
>
> In fact, where a macro argument is not part of a larger expression, or is an
> operand to a comma-expression, there's no need for extra brackets -- all
> possible operators parse at higher priority than commas.  A macro argument
> which itself is a comma-expression whould have to be explicitly bracketed
> in the macro invocation anyway, so there is no extra risk of the macro
> expansion being parsed in an unexpected way in that case.

Thanks for the detailed explanation. I resend the patch with the "always 
add brackets" corrections.

Best regards,
-- 
Nicolas Ferre

  reply	other threads:[~2011-12-02 13:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-02 13:53 [PATCH] irqdomain: protect macro variable in domain iterators Nicolas Ferre
2011-12-02 13:53 ` Nicolas Ferre
2011-12-02 12:59 ` Dave Martin
2011-12-02 12:59   ` Dave Martin
2011-12-02 13:25   ` Nicolas Ferre [this message]
2011-12-02 13:25     ` Nicolas Ferre
2011-12-02 13:51   ` Rob Herring
2011-12-02 13:51     ` Rob Herring
2011-12-02 14:30     ` Dave Martin
2011-12-02 14:30       ` Dave Martin
2011-12-02 13:30 ` [PATCH v2] " Nicolas Ferre
2011-12-02 13:30   ` Nicolas Ferre
2011-12-02 13:30   ` Nicolas Ferre
2011-12-02 13:44   ` Dave Martin
2011-12-02 13:44     ` Dave Martin
2011-12-02 13:44     ` Dave Martin
2011-12-08  9:37     ` Nicolas Ferre
2011-12-08  9:37       ` Nicolas Ferre
2011-12-08  9:37       ` Nicolas Ferre
2011-12-08 13:30       ` Rob Herring
2011-12-08 13:30         ` Rob Herring

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=4ED8D1B8.1010009@atmel.com \
    --to=nicolas.ferre@atmel.com \
    --cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.