driverdev-devel.linuxdriverproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: Jules Irenge <jbi.octave@gmail.com>, outreachy-kernel@googlegroups.com
Cc: devel@driverdev.osuosl.org, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] staging: comedi: rewrite macro function with GNU extension typeof
Date: Mon, 4 Nov 2019 17:03:04 +0000	[thread overview]
Message-ID: <84a2d50f-a1ac-bdc5-989c-b0294e9dea22@mev.co.uk> (raw)
In-Reply-To: <20191104163331.68173-1-jbi.octave@gmail.com>

On 04/11/2019 16:33, Jules Irenge wrote:
> Rewrite macro function with the GNU extension typeof
> to remove a possible side-effects of MACRO argument reuse "x".
>   - Problem could rise if arguments have different types
> and different use though.
> 
> Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
> ---
> v1 - had no full commit log message, with changes not intended to be in the patch
> v2 - remove some changes not intended to be in this driver
>       include note of a potential problem
>   drivers/staging/comedi/comedi.h | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h
> index 09a940066c0e..a57691a2e8d8 100644
> --- a/drivers/staging/comedi/comedi.h
> +++ b/drivers/staging/comedi/comedi.h
> @@ -1103,8 +1103,10 @@ enum ni_common_signal_names {
>   
>   /* *** END GLOBALLY-NAMED NI TERMINALS/SIGNALS *** */
>   
> -#define NI_USUAL_PFI_SELECT(x)	(((x) < 10) ? (0x1 + (x)) : (0xb + (x)))
> -#define NI_USUAL_RTSI_SELECT(x)	(((x) < 7) ? (0xb + (x)) : 0x1b)
> +#define NI_USUAL_PFI_SELECT(x)\
> +	({typeof(x) x_ = (x); (x_ < 10) ? (0x1 + x_) : (0xb + x_); })
> +#define NI_USUAL_RTSI_SELECT(x)\
> +	({typeof(x) x_ = (x); (x_ < 7) ? (0xb + x_) : 0x1b; })
>   
>   /*
>    * mode bits for NI general-purpose counters, set with
> 

I wasn't sure about this the first time around due to the use of GNU 
extensions in uapi header files, but I see there are a few, rare 
instances of this GNU extension elsewhere in other uapi headers (mainly 
in netfilter stuff), so I guess it's OK.  However, it  does mean that 
user code that uses these macros will no longer compile unless GNU 
extensions are enabled.

Does anyone know any "best practices" regarding use of GNU extensions in 
user header files under Linux?

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268.  Registered address:    )=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  parent reply	other threads:[~2019-11-04 17:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-04 16:33 [PATCH v2] staging: comedi: rewrite macro function with GNU extension typeof Jules Irenge
2019-11-04 16:46 ` Greg KH
2019-11-05 11:07   ` Jules Irenge
2019-11-04 17:03 ` Ian Abbott [this message]
2019-11-04 20:46   ` Greg KH
2019-11-05 11:00   ` Jules Irenge

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=84a2d50f-a1ac-bdc5-989c-b0294e9dea22@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbi.octave@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=outreachy-kernel@googlegroups.com \
    /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 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).