Skip to contentSkip to conversation

Staging: media: davinci_vpfe: Convert macros into inline functions

PATCH In review Madhumitha Prabakaran 3 participants 5 messages Mar 22, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Staging: media: davinci_vpfe: Convert macros into inline functions

Convert macros into inline functions, as inline functions are perferable to macros resembling function based on documentation of linux kernel coding style.

---
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +9 -2
index 4685d64016de..fe608be00154 100644
@@ -166,8 +166,15 @@ struct vpfe_ipipeif_device {
 #define IPIPEIF_RSZ_MIN			16
 #define IPIPEIF_RSZ_MAX			112
 #define IPIPEIF_RSZ_CONST		16
-#define SETBIT(reg, bit)   (reg = ((reg) | ((0x00000001)<<(bit))))
-#define RESETBIT(reg, bit) (reg = ((reg) & (~(0x00000001<<(bit)))))
+static inline void set_bit(u32 *reg, int bit)
+{
+	*reg |= (0x00000001 << bit);
+}
+
+static inline void clear_bit(u32 *reg, int bit)
+{
+	*reg &= ~(0x00000001 << bit);
+}
 
 #define IPIPEIF_ADOFS_LSB_MASK		0x1ff
 #define IPIPEIF_ADOFS_LSB_SHIFT		5
Signature · 1 line
2.17.1
#1 lore raw
Quoted 14 lines · Madhumitha Prabakaran

Convert macros into inline functions, as inline functions are perferable to macros resembling function based on documentation of linux kernel coding style.

---
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +0 -0
index 4685d64016de..fe608be00154 100644

drivers/staging/media/davinci_vpfe/dm365_ipipeif.h struct vpfe_ipipeif_device { · line 172

Quoted 9 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +4 -2
@@ -166,8 +166,15 @@ struct vpfe_ipipeif_device {
 #define IPIPEIF_RSZ_MIN			16
 #define IPIPEIF_RSZ_MAX			112
 #define IPIPEIF_RSZ_CONST		16
-#define SETBIT(reg, bit)   (reg = ((reg) | ((0x00000001)<<(bit))))
-#define RESETBIT(reg, bit) (reg = ((reg) & (~(0x00000001<<(bit)))))
+static inline void set_bit(u32 *reg, int bit)
+{
+	*reg |= (0x00000001 << bit);
+}

No, Greg suggested that you use the set_bit and clear_bit that already exist in the kernel.

julia

Quoted 18 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +5 -1
+
+static inline void clear_bit(u32 *reg, int bit)
+{
+	*reg &= ~(0x00000001 << bit);
+}
 
 #define IPIPEIF_ADOFS_LSB_MASK		0x1ff
 #define IPIPEIF_ADOFS_LSB_SHIFT		5
--

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 post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20190322181202.6289-1-madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw
Quoted 31 lines · Julia Lawall
Quoted 14 lines · Madhumitha Prabakaran

Convert macros into inline functions, as inline functions are perferable to macros resembling function based on documentation of linux kernel coding style.

---
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +0 -0
index 4685d64016de..fe608be00154 100644

drivers/staging/media/davinci_vpfe/dm365_ipipeif.h struct vpfe_ipipeif_device { · line 172

Quoted 9 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +4 -2
@@ -166,8 +166,15 @@ struct vpfe_ipipeif_device {
 #define IPIPEIF_RSZ_MIN			16
 #define IPIPEIF_RSZ_MAX			112
 #define IPIPEIF_RSZ_CONST		16
-#define SETBIT(reg, bit)   (reg = ((reg) | ((0x00000001)<<(bit))))
-#define RESETBIT(reg, bit) (reg = ((reg) & (~(0x00000001<<(bit)))))
+static inline void set_bit(u32 *reg, int bit)
+{
+	*reg |= (0x00000001 << bit);
+}

No, Greg suggested that you use the set_bit and clear_bit that already exist in the kernel.

Quoted 1 line

julia

I was checking on that

https://www.kernel.org/doc/htmldocs/kernel-api/API-set-bit.html

But, I wasn't sure about that.
I will fix it.

Thanks

Quoted 26 lines
Quoted 19 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +5 -1
+
+static inline void clear_bit(u32 *reg, int bit)
+{
+	*reg &= ~(0x00000001 << bit);
+}
 
 #define IPIPEIF_ADOFS_LSB_MASK		0x1ff
 #define IPIPEIF_ADOFS_LSB_SHIFT		5
--

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 post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20190322181202.6289-1-madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Signature · 5 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 post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.20.1903221912550.14339%40hadrien.
For more options, visit https://groups.google.com/d/optout.
maintainer
#3 lore raw
In reply to Madhumitha Prabakaran
Quoted 18 lines · Madhumitha Prabakaran

Convert macros into inline functions, as inline functions are perferable to macros resembling function based on documentation of linux kernel coding style.

---
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +0 -1
index 4685d64016de..fe608be00154 100644
@@ -166,8 +166,15 @@ struct vpfe_ipipeif_device {
 #define IPIPEIF_RSZ_MIN			16
 #define IPIPEIF_RSZ_MAX			112
 #define IPIPEIF_RSZ_CONST		16
-#define SETBIT(reg, bit)   (reg = ((reg) | ((0x00000001)<<(bit))))

drivers/staging/media/davinci_vpfe/dm365_ipipeif.h struct vpfe_ipipeif_device { · line 177

Quoted 10 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +9 -1
-#define RESETBIT(reg, bit) (reg = ((reg) & (~(0x00000001<<(bit)))))
+static inline void set_bit(u32 *reg, int bit)
+{
+	*reg |= (0x00000001 << bit);
+}
+
+static inline void clear_bit(u32 *reg, int bit)
+{
+	*reg &= ~(0x00000001 << bit);
+}

Did you try to build this and see if you use this function what happens? The compiler should complain :(

As Julia said, I asked that you _use_ those functions as the kernel already provides them (and does it better), these macros should not be needed at all.

thanks,

greg k-h

#4 lore raw
Quoted 24 lines · Greg KH
Quoted 23 lines · Madhumitha Prabakaran

Convert macros into inline functions, as inline functions are perferable to macros resembling function based on documentation of linux kernel coding style.

---
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +4 -2
index 4685d64016de..fe608be00154 100644
@@ -166,8 +166,15 @@ struct vpfe_ipipeif_device {
 #define IPIPEIF_RSZ_MIN			16
 #define IPIPEIF_RSZ_MAX			112
 #define IPIPEIF_RSZ_CONST		16
-#define SETBIT(reg, bit)   (reg = ((reg) | ((0x00000001)<<(bit))))
-#define RESETBIT(reg, bit) (reg = ((reg) & (~(0x00000001<<(bit)))))
+static inline void set_bit(u32 *reg, int bit)
+{
+	*reg |= (0x00000001 << bit);
+}
Quoted 8 lines

drivers/staging/media/davinci_vpfe/dm365_ipipeif.h struct vpfe_ipipeif_device { · line 177

Quoted 5 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +5 -0
+
+static inline void clear_bit(u32 *reg, int bit)
+{
+	*reg &= ~(0x00000001 << bit);
+}

Did you try to build this and see if you use this function what happens? The compiler should complain :(

Sorry, I didn't build it. I will remember it in future.

thanks

Quoted 8 lines

As Julia said, I asked that you _use_ those functions as the kernel already provides them (and does it better), these macros should not be needed at all.

thanks,

greg k-h