Remove macros and use BIT macros
Subsystems (2)
cover Remove macros and use BIT macros
This patchset does as follows :
1) Remove SETBIT macro and use BIT macro
2) Remove RESETBIT macro and use BIT macro
Madhumitha Prabakaran (2):
Staging: media: davinci_vpfe: Remove SETBIT macro and use BIT macro
Staging: media: davinci_vpfe: Remove RESETBIT macro and use BIT macro
.../staging/media/davinci_vpfe/dm365_ipipeif.c | 16 ++++++++-------- .../staging/media/davinci_vpfe/dm365_ipipeif.h | 2 -- 2 files changed, 8 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 Staging: media: davinci_vpfe: Remove SETBIT macro and use BIT macro
Remove SETBIT macro and use BIT(x) instead of (1 << x) to maintain Linux kernel coding style.
--- drivers/staging/media/davinci_vpfe/dm365_ipipeif.c | 8 ++++---- drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +4 -4
@@ -297,7 +297,7 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)case MEDIA_BUS_FMT_UYVY8_2X8 :case MEDIA_BUS_FMT_Y8_1X8 :RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); -SETBIT (val,IPIPEIF_CFG2_YUV16_SHIFT ); + val |=BIT (IPIPEIF_CFG2_YUV16_SHIFT );ipipeif_write (val, ipipeif_base_addr,IPIPEIF_CFG2 );break ;
@@ -345,15 +345,15 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)case MEDIA_BUS_FMT_YUYV8_1X16 :case MEDIA_BUS_FMT_YUYV10_1X20 :RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); -SETBIT (val,IPIPEIF_CFG2_YUV16_SHIFT ); + val |=BIT (IPIPEIF_CFG2_YUV16_SHIFT );break ;case MEDIA_BUS_FMT_YUYV8_2X8 :case MEDIA_BUS_FMT_UYVY8_2X8 :case MEDIA_BUS_FMT_Y8_1X8 :case MEDIA_BUS_FMT_YUYV10_2X10 : -SETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); -SETBIT (val,IPIPEIF_CFG2_YUV16_SHIFT ); + val |=BIT (IPIPEIF_CFG2_YUV8_SHIFT ); + val |=BIT (IPIPEIF_CFG2_YUV16_SHIFT ); val |=IPIPEIF_CBCR_Y <<IPIPEIF_CFG2_YUV8P_SHIFT ;break ;
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +0 -1
@@ -166,7 +166,6 @@ 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)))))#define IPIPEIF_ADOFS_LSB_MASK 0x1ff
Signature · 1 line
2.17.1
PATCH 2/2 Staging: media: davinci_vpfe: Remove RESETBIT macro and use BIT macro
In reply to Madhumitha PrabakaranRemove RESETBIT macro and use BIT(x) instead of (1 << x) to improve codebase.
--- drivers/staging/media/davinci_vpfe/dm365_ipipeif.c | 8 ++++---- drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +4 -4
@@ -296,14 +296,14 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)case MEDIA_BUS_FMT_YUYV8_1X16 :case MEDIA_BUS_FMT_UYVY8_2X8 :case MEDIA_BUS_FMT_Y8_1X8 : -RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); + val &= ~BIT (IPIPEIF_CFG2_YUV8_SHIFT ); val |=BIT (IPIPEIF_CFG2_YUV16_SHIFT );ipipeif_write (val, ipipeif_base_addr,IPIPEIF_CFG2 );break ;default : -RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); -RESETBIT (val,IPIPEIF_CFG2_YUV16_SHIFT ); + val &= ~BIT (IPIPEIF_CFG2_YUV8_SHIFT ); + val &= ~BIT (IPIPEIF_CFG2_YUV16_SHIFT );ipipeif_write (val, ipipeif_base_addr,IPIPEIF_CFG2 );break ; }
@@ -344,7 +344,7 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)switch (isif_port_if) {case MEDIA_BUS_FMT_YUYV8_1X16 :case MEDIA_BUS_FMT_YUYV10_1X20 : -RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); + val &= ~BIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); val |=BIT (IPIPEIF_CFG2_YUV16_SHIFT );break ;
drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +0 -1
@@ -166,7 +166,6 @@ struct vpfe_ipipeif_device {#define IPIPEIF_RSZ_MIN 16#define IPIPEIF_RSZ_MAX 112#define IPIPEIF_RSZ_CONST 16 -#define RESETBIT (reg, bit) (reg = ((reg) & (~(0x00000001<<(bit)))))#define IPIPEIF_ADOFS_LSB_MASK 0x1ff#define IPIPEIF_ADOFS_LSB_SHIFT 5
Signature · 1 line
2.17.1
Greg KH
maintainerRe: [PATCH 1/2] Staging: media: davinci_vpfe: Remove SETBIT macro and use BIT macro
In reply to Madhumitha PrabakaranQuoted 14 lines · Madhumitha Prabakaran
Remove SETBIT macro and use BIT(x) instead of (1 << x) to maintain Linux kernel coding style.
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/media/davinci_vpfe/dm365_ipipeif.c | 8 ++++---- drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-)drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +0
-0
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c static int ipipeif_hw_setup(struct v4l2_subdev *sd) · line 300
Quoted 5 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +1
-1@@ -297,7 +297,7 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)case MEDIA_BUS_FMT_UYVY8_2X8 :case MEDIA_BUS_FMT_Y8_1X8 :RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); -SETBIT (val,IPIPEIF_CFG2_YUV16_SHIFT ); + val |=BIT (IPIPEIF_CFG2_YUV16_SHIFT );
Ick, that's harder to read now, right?
Why not just use the set_bit() function instead? That seems like the easier thing to do here, right?
thanks,
greg k-h
Greg KH
maintainerRe: [PATCH 2/2] Staging: media: davinci_vpfe: Remove RESETBIT macro and use BIT macro
In reply to Madhumitha PrabakaranQuoted 14 lines · Madhumitha Prabakaran
Remove RESETBIT macro and use BIT(x) instead of (1 << x) to improve codebase.
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/media/davinci_vpfe/dm365_ipipeif.c | 8 ++++---- drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-)drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +0
-0
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c static int ipipeif_hw_setup(struct v4l2_subdev *sd) · line 299
Quoted 5 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +1
-1@@ -296,14 +296,14 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)case MEDIA_BUS_FMT_YUYV8_1X16 :case MEDIA_BUS_FMT_UYVY8_2X8 :case MEDIA_BUS_FMT_Y8_1X8 : -RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); + val &= ~BIT (IPIPEIF_CFG2_YUV8_SHIFT );
clear_bit()?
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c static int ipipeif_hw_setup(struct v4l2_subdev *sd) · line 300
Quoted 1 line
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +0
-0val |=BIT (IPIPEIF_CFG2_YUV16_SHIFT );
set_bit()?
thanks,
greg k-h
Re: [Outreachy kernel] [PATCH 2/2] Staging: media: davinci_vpfe: Remove RESETBIT macro and use BIT macro
In reply to Madhumitha PrabakaranQuoted 2 lines · Madhumitha Prabakaran
Remove RESETBIT macro and use BIT(x) instead of (1 << x) to improve codebase.
These could be just one patch, since it is basically the same thing.
The reason offered is not very clear. Probably all patches have the goal of improving the codebase.
The original reason was that it is not very convenient to turn the macro into a function. You could, however, have just left it as a macro. Or you could have changed the macro to use BIT. The proposed approach makes it more apparent in the source code what is going on. There are a lot of occurrences of eg ... |= BIT(...) in the kernel, and there doesn't seem to be an established macro for this, so the change is probably fine.
julia
Quoted 60 lines
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/media/davinci_vpfe/dm365_ipipeif.c | 8 ++++---- drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-)drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +4
-4@@ -296,14 +296,14 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)case MEDIA_BUS_FMT_YUYV8_1X16 :case MEDIA_BUS_FMT_UYVY8_2X8 :case MEDIA_BUS_FMT_Y8_1X8 : -RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); + val &= ~BIT (IPIPEIF_CFG2_YUV8_SHIFT ); val |=BIT (IPIPEIF_CFG2_YUV16_SHIFT );ipipeif_write (val, ipipeif_base_addr,IPIPEIF_CFG2 );break ;default : -RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); -RESETBIT (val,IPIPEIF_CFG2_YUV16_SHIFT ); + val &= ~BIT (IPIPEIF_CFG2_YUV8_SHIFT ); + val &= ~BIT (IPIPEIF_CFG2_YUV16_SHIFT );ipipeif_write (val, ipipeif_base_addr,IPIPEIF_CFG2 );break ; }@@ -344,7 +344,7 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)switch (isif_port_if) {case MEDIA_BUS_FMT_YUYV8_1X16 :case MEDIA_BUS_FMT_YUYV10_1X20 : -RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); + val &= ~BIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); val |=BIT (IPIPEIF_CFG2_YUV16_SHIFT );break ;drivers/staging/media/davinci_vpfe/dm365_ipipeif.h +0
-2@@ -166,7 +166,6 @@ struct vpfe_ipipeif_device {#define IPIPEIF_RSZ_MIN 16#define IPIPEIF_RSZ_MAX 112#define IPIPEIF_RSZ_CONST 16 -#define RESETBIT (reg, bit) (reg = ((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/a64c7dd0bf44cc3ac0270a382209e592c8a05987.1553217781.git.madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] Re: [PATCH 2/2] Staging: media: davinci_vpfe: Remove RESETBIT macro and use BIT macro
In reply to Greg KHQuoted 23 lines · Greg KH
Quoted 14 lines · Madhumitha Prabakaran
Remove RESETBIT macro and use BIT(x) instead of (1 << x) to improve codebase.
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/media/davinci_vpfe/dm365_ipipeif.c | 8 ++++---- drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-)drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +0
-0drivers/staging/media/davinci_vpfe/dm365_ipipeif.c static int ipipeif_hw_setup(struct v4l2_subdev *sd) · line 299
Quoted 5 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +1
-1@@ -296,14 +296,14 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)case MEDIA_BUS_FMT_YUYV8_1X16 :case MEDIA_BUS_FMT_UYVY8_2X8 :case MEDIA_BUS_FMT_Y8_1X8 : -RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); + val &= ~BIT (IPIPEIF_CFG2_YUV8_SHIFT );
clear_bit()?
Quoted 3 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c static int ipipeif_hw_setup(struct v4l2_subdev *sd) · line 300
Quoted 1 line
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +0
-0val |=BIT (IPIPEIF_CFG2_YUV16_SHIFT );
set_bit()?
OK, I see that the definition of these things is much more complicated than what I was looking for. These are atomic operations. There is also __set_bit, which is not atomic. But set_bit does seem to be commonly used.
julia
Greg KH
maintainerRe: [Outreachy kernel] Re: [PATCH 2/2] Staging: media: davinci_vpfe: Remove RESETBIT macro and use BIT macro
Quoted 27 lines · Julia Lawall
Quoted 23 lines · Greg KH
Quoted 14 lines · Madhumitha Prabakaran
Remove RESETBIT macro and use BIT(x) instead of (1 << x) to improve codebase.
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/media/davinci_vpfe/dm365_ipipeif.c | 8 ++++---- drivers/staging/media/davinci_vpfe/dm365_ipipeif.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-)drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +0
-0drivers/staging/media/davinci_vpfe/dm365_ipipeif.c static int ipipeif_hw_setup(struct v4l2_subdev *sd) · line 299
Quoted 5 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +1
-1@@ -296,14 +296,14 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd)case MEDIA_BUS_FMT_YUYV8_1X16 :case MEDIA_BUS_FMT_UYVY8_2X8 :case MEDIA_BUS_FMT_Y8_1X8 : -RESETBIT (val,IPIPEIF_CFG2_YUV8_SHIFT ); + val &= ~BIT (IPIPEIF_CFG2_YUV8_SHIFT );
clear_bit()?
Quoted 8 lines
Quoted 3 lines
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c static int ipipeif_hw_setup(struct v4l2_subdev *sd) · line 300
Quoted 1 line
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +0
-0val |=BIT (IPIPEIF_CFG2_YUV16_SHIFT );
set_bit()?OK, I see that the definition of these things is much more complicated than what I was looking for. These are atomic operations. There is also
__set_bit, which is not atomic. Butset_bitdoes seem to be commonly used.
Only use __set_bit() if you know you are safe doing the operation in an "unordered" fashion. Given that these originally were "open coded", it's probably safe, but it's simpler to use the ordered calls for now.
thanks,
greg k-h