Skip to contentSkip to conversation

staging: comedi: rewrite macro function with GNU extension

PATCH Superseded Jules Irenge 4 participants 8 messages Nov 3, 2019 – Nov 4, 2019 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: comedi: rewrite macro function with GNU extension

Rewrite macro function with GNU extension
to remove a possible side-effects of MACRO argument reuse "x". Issue detected by checkpatch tool

---
 drivers/staging/comedi/comedi.h | 6 ++++--
 drivers/staging/wfx/queue.c     | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/staging/comedi/comedi.h +4 -2
index 09a940066c0e..d8a8eec82930 100644
@@ -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
drivers/staging/wfx/queue.c +1 -1
index ef3ee55cf621..5d29bce65f71 100644
@@ -565,7 +565,7 @@ struct hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev)
 		}
 
 		if (ret)
-			return 0;
+			return NULL;
 
 		queue_num = queue - wdev->tx_queue;
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 15 lines · Jules Irenge

Rewrite macro function with GNU extension
to remove a possible side-effects of MACRO argument reuse "x". Issue detected by checkpatch tool

---
 drivers/staging/comedi/comedi.h | 6 ++++--
 drivers/staging/wfx/queue.c     | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/staging/comedi/comedi.h +0 -0
index 09a940066c0e..d8a8eec82930 100644

drivers/staging/comedi/comedi.h enum ni_common_signal_names { · line 1109

Quoted 9 lines
drivers/staging/comedi/comedi.h +4 -2
@@ -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; })

It seems like a clever idea, but could these be functions? The only problem could be if the arguments have different types a the different uses. If that is the case, it would be good to mention that in the log message.

drivers/staging/wfx/queue.c struct hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev) · line 568

Quoted 13 lines
drivers/staging/comedi/comedi.h +0 -0
 /*
  * mode bits for NI general-purpose counters, set with
drivers/staging/wfx/queue.c +1 -1
index ef3ee55cf621..5d29bce65f71 100644
@@ -565,7 +565,7 @@ struct hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev)
 		}
 
 		if (ret)
-			return 0;
+			return NULL;

This seems to be left over from some other change.

julia

Quoted 11 lines
drivers/staging/wfx/queue.c +0 -1
 		queue_num = queue - wdev->tx_queue;
 
--

2.17.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20191103201740.25415-1-jbi.octave%40gmail.com.

#2 lore raw
Quoted 22 lines · Julia Lawall
Quoted 18 lines · Jules Irenge

Rewrite macro function with GNU extension
to remove a possible side-effects of MACRO argument reuse "x". Issue detected by checkpatch tool

---
  drivers/staging/comedi/comedi.h | 6 ++++--
  drivers/staging/wfx/queue.c     | 2 +-
  2 files changed, 5 insertions(+), 3 deletions(-)
drivers/staging/comedi/comedi.h +0 -0
index 09a940066c0e..d8a8eec82930 100644
@@ -1103,8 +1103,10 @@ enum ni_common_signal_names {
 
  /* *** END GLOBALLY-NAMED NI TERMINALS/SIGNALS *** */
 
Quoted 11 lines

drivers/staging/comedi/comedi.h enum ni_common_signal_names { · line 1109

Quoted 6 lines
drivers/staging/comedi/comedi.h +4 -2
-#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; })

It seems like a clever idea, but could these be functions? The only problem could be if the arguments have different types a the different uses. If that is the case, it would be good to mention that in the log message.

Since the stuff in "comedi.h" is intended to be UAPI, I think it would be preferable to avoid GNU extensions. static inline functions would be more acceptable.

Quoted 11 lines
Quoted 11 lines
drivers/staging/comedi/comedi.h +0 -0
  /*
   * mode bits for NI general-purpose counters, set with
drivers/staging/wfx/queue.c +0 -0
index ef3ee55cf621..5d29bce65f71 100644
@@ -565,7 +565,7 @@ struct hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev)
  		}
 
Quoted 5 lines

drivers/staging/wfx/queue.c struct hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev) · line 568

Quoted 3 lines
drivers/staging/wfx/queue.c +1 -1
  		if (ret)
-			return 0;
+			return NULL;

This seems to be left over from some other change.

Indeed, it seems so!

Signature · 4 lines
-=( Ian Abbott <[email protected]> || 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. )=-
#3 lore raw
In reply to Julia Lawall
Quoted 55 lines · Julia Lawall
Quoted 15 lines · Jules Irenge

Rewrite macro function with GNU extension
to remove a possible side-effects of MACRO argument reuse "x". Issue detected by checkpatch tool

---
 drivers/staging/comedi/comedi.h | 6 ++++--
 drivers/staging/wfx/queue.c     | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/staging/comedi/comedi.h +0 -0
index 09a940066c0e..d8a8eec82930 100644

drivers/staging/comedi/comedi.h enum ni_common_signal_names { · line 1109

Quoted 9 lines
drivers/staging/comedi/comedi.h +4 -2
@@ -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; })

It seems like a clever idea, but could these be functions? The only problem could be if the arguments have different types a the different uses. If that is the case, it would be good to mention that in the log message.

drivers/staging/wfx/queue.c struct hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev) · line 568

Quoted 13 lines
drivers/staging/comedi/comedi.h +0 -0
 /*
  * mode bits for NI general-purpose counters, set with
drivers/staging/wfx/queue.c +1 -1
index ef3ee55cf621..5d29bce65f71 100644
@@ -565,7 +565,7 @@ struct hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev)
 		}
 
 		if (ret)
-			return 0;
+			return NULL;

This seems to be left over from some other change.

julia

Quoted 3 lines
drivers/staging/wfx/queue.c +0 -0
 		queue_num = queue - wdev->tx_queue;
 
Quoted 14 lines
Quoted 8 lines
drivers/staging/wfx/queue.c +0 -1
--

2.17.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20191103201740.25415-1-jbi.octave%40gmail.com.

Signature · 3 lines
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1911032119140.2557%40hadrien.

Thanks for the feedback. I think it is best I move on to another driver. Kind regards
Jules

maintainer
#4 lore raw
In reply to Jules Irenge
Quoted 8 lines · Jules Irenge

Rewrite macro function with GNU extension
to remove a possible side-effects of MACRO argument reuse "x". Issue detected by checkpatch tool

---
 drivers/staging/comedi/comedi.h | 6 ++++--
 drivers/staging/wfx/queue.c     | 2 +-

Why are you modifying the wfx driver in a patch for the comedi code?

:(

greg k-h

#5 lore raw
Quoted 10 lines · Greg KH
Quoted 8 lines · Jules Irenge

Rewrite macro function with GNU extension
to remove a possible side-effects of MACRO argument reuse "x". Issue detected by checkpatch tool

---
 drivers/staging/comedi/comedi.h | 6 ++++--
 drivers/staging/wfx/queue.c     | 2 +-
Quoted 6 lines

Why are you modifying the wfx driver in a patch for the comedi code?

:(

greg k-h

Apology, the mixing will not happen again. I will try the same patch on different driver as this one has an LGPL license and seems not likely to accept any GNU extension.
Thank you for the feedback.
Kind regards
Jules

maintainer
#6 lore raw
Quoted 16 lines · Jules Irenge
Quoted 12 lines · Greg KH
Quoted 8 lines · Jules Irenge

Rewrite macro function with GNU extension
to remove a possible side-effects of MACRO argument reuse "x". Issue detected by checkpatch tool

---
 drivers/staging/comedi/comedi.h | 6 ++++--
 drivers/staging/wfx/queue.c     | 2 +-

Why are you modifying the wfx driver in a patch for the comedi code?

Quoted 7 lines
Quoted 4 lines

:(

greg k-h

Apology, the mixing will not happen again. I will try the same patch on different driver as this one has an LGPL license and seems not likely to accept any GNU extension.

That doesn't matter. The kernel is built with many different compilers, clang and gcc are both open source compilers that can build the kernel, and there are some closed source ones as well. The license of the code has nothing to do with the compiler involved :)

good luck!

greg k-h

#7 lore raw
Quoted 25 lines · Greg KH
Quoted 16 lines · Jules Irenge
Quoted 12 lines · Greg KH
Quoted 8 lines · Jules Irenge

Rewrite macro function with GNU extension
to remove a possible side-effects of MACRO argument reuse "x". Issue detected by checkpatch tool

---
 drivers/staging/comedi/comedi.h | 6 ++++--
 drivers/staging/wfx/queue.c     | 2 +-

Why are you modifying the wfx driver in a patch for the comedi code?

Quoted 7 lines
Quoted 4 lines

:(

greg k-h

Apology, the mixing will not happen again. I will try the same patch on different driver as this one has an LGPL license and seems not likely to accept any GNU extension.

Quoted 9 lines

That doesn't matter. The kernel is built with many different compilers, clang and gcc are both open source compilers that can build the kernel, and there are some closed source ones as well. The license of the code has nothing to do with the compiler involved :)

good luck!

greg k-h

Thanks, I will update soon