Skip to contentSkip to conversation

Staging: fwserial: Convert macro into an inline function

PATCH In review Madhumitha Prabakaran 3 participants 5 messages Mar 6, 2019 – Mar 7, 2019 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: fwserial: Convert macro into an inline function

Convert macro into an inline function to make codebase better

---
 drivers/staging/fwserial/fwserial.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/fwserial/fwserial.c +4 -1
index a1b90ea7fcb8..aec0f19597a9 100644
@@ -19,7 +19,10 @@
 
 #include "fwserial.h"
 
-#define be32_to_u64(hi, lo)  ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo))
+inline u64 be32_to_u64(__be32 hi, __be32 lo)
+{
+	return ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo));
+}
 
 #define LINUX_VENDOR_ID   0xd00d1eU  /* same id used in card root directory   */
 #define FWSERIAL_VERSION  0x00e81cU  /* must be unique within LINUX_VENDOR_ID */
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 12 lines · Madhumitha Prabakaran

Convert macro into an inline function to make codebase better

---
 drivers/staging/fwserial/fwserial.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/fwserial/fwserial.c +0 -0
index a1b90ea7fcb8..aec0f19597a9 100644

drivers/staging/fwserial/fwserial.c line 25

Quoted 8 lines
drivers/staging/fwserial/fwserial.c +4 -1
@@ -19,7 +19,10 @@
 
 #include "fwserial.h"
 
-#define be32_to_u64(hi, lo)  ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo))
+inline u64 be32_to_u64(__be32 hi, __be32 lo)
+{
+	return ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo));
+}

For some reason I thought the kernel had a function that already did this, but it doesn't, which is really odd. Anyway, that's something that could be done in the future, as this is done all over the place in different drivers.

thanks,

greg k-h

#2 lore raw
Quoted 16 lines · Greg KH
Quoted 15 lines · Madhumitha Prabakaran

Convert macro into an inline function to make codebase better

---
 drivers/staging/fwserial/fwserial.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/fwserial/fwserial.c +0 -0
index a1b90ea7fcb8..aec0f19597a9 100644
@@ -19,7 +19,10 @@
 
 #include "fwserial.h"
 
Quoted 10 lines

drivers/staging/fwserial/fwserial.c line 25

Quoted 5 lines
drivers/staging/fwserial/fwserial.c +4 -1
-#define be32_to_u64(hi, lo)  ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo))
+inline u64 be32_to_u64(__be32 hi, __be32 lo)
+{
+	return ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo));
+}

For some reason I thought the kernel had a function that already did this, but it doesn't, which is really odd. Anyway, that's something that could be done in the future, as this is done all over the place in different drivers.

Actually, as far as I can see, only two occurrences, in drivers/target/sbp/sbp_target.c and drivers/net/ethernet/mellanox/mlxfw/mlxfw_mfa2.c

Perhaps there are some other variants that are more popular.

julia

maintainer
#3 lore raw
Quoted 31 lines · Julia Lawall
Quoted 16 lines · Greg KH
Quoted 15 lines · Madhumitha Prabakaran

Convert macro into an inline function to make codebase better

---
 drivers/staging/fwserial/fwserial.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/fwserial/fwserial.c +0 -0
index a1b90ea7fcb8..aec0f19597a9 100644
@@ -19,7 +19,10 @@
 
 #include "fwserial.h"
 
Quoted 10 lines

drivers/staging/fwserial/fwserial.c line 25

Quoted 5 lines
drivers/staging/fwserial/fwserial.c +4 -1
-#define be32_to_u64(hi, lo)  ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo))
+inline u64 be32_to_u64(__be32 hi, __be32 lo)
+{
+	return ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo));
+}

For some reason I thought the kernel had a function that already did this, but it doesn't, which is really odd. Anyway, that's something that could be done in the future, as this is done all over the place in different drivers.

Quoted 5 lines

Actually, as far as I can see, only two occurrences, in drivers/target/sbp/sbp_target.c and drivers/net/ethernet/mellanox/mlxfw/mlxfw_mfa2.c

Perhaps there are some other variants that are more popular.

The file include/linux/io-64-nonatomic-hi-lo.h open-codes this 4 different times, as does include/linux/ml5/device.h and then there is HILO_GEN() which tries to do the right thing for this type of macro, but it's specific to a single driver.

Odds are it is also open-coded in many other drivers as well :(

thanks,

greg k-h

#4 lore raw
Quoted 32 lines · Greg KH
Quoted 31 lines · Julia Lawall
Quoted 26 lines · Greg KH
Quoted 12 lines · Madhumitha Prabakaran

Convert macro into an inline function to make codebase better

---
 drivers/staging/fwserial/fwserial.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/fwserial/fwserial.c +0 -0
index a1b90ea7fcb8..aec0f19597a9 100644

drivers/staging/fwserial/fwserial.c line 25

Quoted 8 lines
drivers/staging/fwserial/fwserial.c +4 -1
@@ -19,7 +19,10 @@
 
 #include "fwserial.h"
 
-#define be32_to_u64(hi, lo)  ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo))
+inline u64 be32_to_u64(__be32 hi, __be32 lo)
+{
+	return ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo));
+}

For some reason I thought the kernel had a function that already did this, but it doesn't, which is really odd. Anyway, that's something that could be done in the future, as this is done all over the place in different drivers.

Quoted 8 lines
Quoted 5 lines

Actually, as far as I can see, only two occurrences, in drivers/target/sbp/sbp_target.c and drivers/net/ethernet/mellanox/mlxfw/mlxfw_mfa2.c

Perhaps there are some other variants that are more popular.

The file include/linux/io-64-nonatomic-hi-lo.h open-codes this 4 different times, as does include/linux/ml5/device.h and then there is

Ah, I only looked at .c files :)

julia

Quoted 9 lines

HILO_GEN() which tries to do the right thing for this type of macro, but it's specific to a single driver.

Odds are it is also open-coded in many other drivers as well :(

thanks,

greg k-h