2023-10-20 06:54:54

by kenechukwu maduechesi

[permalink] [raw]
Subject: [PATCH] staging: rts5208: Add parenthesis to macro arguments

Checkpatch suggests using (reg) and (host) instead of reg and host

The use of parenthesis in the macro argument '(reg)' ensures proper
precedence and resolves potential issues that may arise due to the
surrounding code context. This modification adheres to the recommended
coding style and improves the readability or maintainability of the
code.

Signed-off-by: kenechukwu maduechesi <[email protected]>
---
drivers/staging/rts5208/rtsx.h | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/rts5208/rtsx.h b/drivers/staging/rts5208/rtsx.h
index 2e101da83220..7d3373797eb4 100644
--- a/drivers/staging/rts5208/rtsx.h
+++ b/drivers/staging/rts5208/rtsx.h
@@ -39,17 +39,17 @@
/*
* macros for easy use
*/
-#define rtsx_writel(chip, reg, value) \
+#define rtsx_writel(chip, (reg), value) \
iowrite32(value, (chip)->rtsx->remap_addr + reg)
-#define rtsx_readl(chip, reg) \
+#define rtsx_readl(chip, (reg) \
ioread32((chip)->rtsx->remap_addr + reg)
-#define rtsx_writew(chip, reg, value) \
+#define rtsx_writew(chip, (reg), value) \
iowrite16(value, (chip)->rtsx->remap_addr + reg)
-#define rtsx_readw(chip, reg) \
+#define rtsx_readw(chip, (reg)) \
ioread16((chip)->rtsx->remap_addr + reg)
-#define rtsx_writeb(chip, reg, value) \
+#define rtsx_writeb(chip, (reg), value) \
iowrite8(value, (chip)->rtsx->remap_addr + reg)
-#define rtsx_readb(chip, reg) \
+#define rtsx_readb(chip, (reg)) \
ioread8((chip)->rtsx->remap_addr + reg)

#define rtsx_read_config_byte(chip, where, val) \
@@ -131,8 +131,8 @@ static inline struct rtsx_dev *host_to_rtsx(struct Scsi_Host *host)
* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
* single queue element srb for write access
*/
-#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
-#define scsi_lock(host) spin_lock_irq(host->host_lock)
+#define scsi_unlock(host) spin_unlock_irq((host)->host_lock)
+#define scsi_lock(host) spin_lock_irq((host)->host_lock)

#define lock_state(chip) spin_lock_irq(&((chip)->rtsx->reg_lock))
#define unlock_state(chip) spin_unlock_irq(&((chip)->rtsx->reg_lock))
--
2.25.1


2023-10-20 07:38:50

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] staging: rts5208: Add parenthesis to macro arguments

On Thu, Oct 19, 2023 at 11:54:39PM -0700, kenechukwu maduechesi wrote:
> Checkpatch suggests using (reg) and (host) instead of reg and host
>
> The use of parenthesis in the macro argument '(reg)' ensures proper
> precedence and resolves potential issues that may arise due to the
> surrounding code context. This modification adheres to the recommended
> coding style and improves the readability or maintainability of the
> code.
>
> Signed-off-by: kenechukwu maduechesi <[email protected]>
> ---
> drivers/staging/rts5208/rtsx.h | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/staging/rts5208/rtsx.h b/drivers/staging/rts5208/rtsx.h
> index 2e101da83220..7d3373797eb4 100644
> --- a/drivers/staging/rts5208/rtsx.h
> +++ b/drivers/staging/rts5208/rtsx.h
> @@ -39,17 +39,17 @@
> /*
> * macros for easy use
> */
> -#define rtsx_writel(chip, reg, value) \
> +#define rtsx_writel(chip, (reg), value) \

This will break the build. But also someone already fixed this in
linux-next.

> iowrite32(value, (chip)->rtsx->remap_addr + reg)

regards,
dan carpenter

2023-10-20 07:49:04

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH] staging: rts5208: Add parenthesis to macro arguments



On Thu, 19 Oct 2023, kenechukwu maduechesi wrote:

> Checkpatch suggests using (reg) and (host) instead of reg and host
>
> The use of parenthesis in the macro argument '(reg)' ensures proper
> precedence and resolves potential issues that may arise due to the
> surrounding code context. This modification adheres to the recommended
> coding style and improves the readability or maintainability of the
> code.
>
> Signed-off-by: kenechukwu maduechesi <[email protected]>
> ---
> drivers/staging/rts5208/rtsx.h | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/staging/rts5208/rtsx.h b/drivers/staging/rts5208/rtsx.h
> index 2e101da83220..7d3373797eb4 100644
> --- a/drivers/staging/rts5208/rtsx.h
> +++ b/drivers/staging/rts5208/rtsx.h
> @@ -39,17 +39,17 @@
> /*
> * macros for easy use
> */
> -#define rtsx_writel(chip, reg, value) \
> +#define rtsx_writel(chip, (reg), value) \
> iowrite32(value, (chip)->rtsx->remap_addr + reg)

I don't think this code has been subjected to the compiler. Note that you
can't comiple a .h file directly; you have to find some other file that
includes it. It may be useful to run make path/to/cfile.i (for some
cfile.c) to see if the specific code you changed it included in the
configuration or is discarded by the preprocessor.

In any case, you have put () in the argument list of a macro, for reg,
which is not correct. The parentheses for chip are ok.

> -#define rtsx_readl(chip, reg) \
> +#define rtsx_readl(chip, (reg) \

Here you have broken the argument list of the macro completely, because
the parentheses are not balanced.

> ioread32((chip)->rtsx->remap_addr + reg)
> -#define rtsx_writew(chip, reg, value) \
> +#define rtsx_writew(chip, (reg), value) \
> iowrite16(value, (chip)->rtsx->remap_addr + reg)
> -#define rtsx_readw(chip, reg) \
> +#define rtsx_readw(chip, (reg)) \
> ioread16((chip)->rtsx->remap_addr + reg)
> -#define rtsx_writeb(chip, reg, value) \
> +#define rtsx_writeb(chip, (reg), value) \
> iowrite8(value, (chip)->rtsx->remap_addr + reg)
> -#define rtsx_readb(chip, reg) \
> +#define rtsx_readb(chip, (reg)) \
> ioread8((chip)->rtsx->remap_addr + reg)
>
> #define rtsx_read_config_byte(chip, where, val) \
> @@ -131,8 +131,8 @@ static inline struct rtsx_dev *host_to_rtsx(struct Scsi_Host *host)
> * The scsi_lock() and scsi_unlock() macros protect the sm_state and the
> * single queue element srb for write access
> */
> -#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
> -#define scsi_lock(host) spin_lock_irq(host->host_lock)
> +#define scsi_unlock(host) spin_unlock_irq((host)->host_lock)
> +#define scsi_lock(host) spin_lock_irq((host)->host_lock)

I also wonder if someone has worked on this code already? There was
a suggestion to just drop these macros and use the standard kernel
functions. Maybe your kernel tree is not up to date.

julia

> #define lock_state(chip) spin_lock_irq(&((chip)->rtsx->reg_lock))
> #define unlock_state(chip) spin_unlock_irq(&((chip)->rtsx->reg_lock))
> --
> 2.25.1
>
>
>

2023-10-22 06:21:38

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] staging: rts5208: Add parenthesis to macro arguments

Hi kenechukwu,

kernel test robot noticed the following build errors:

[auto build test ERROR on staging/staging-linus]
[also build test ERROR on linus/master v6.6-rc6]
[cannot apply to staging/staging-testing staging/staging-next next-20231020]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/kenechukwu-maduechesi/staging-rts5208-Add-parenthesis-to-macro-arguments/20231020-145549
base: staging/staging-linus
patch link: https://lore.kernel.org/r/20231020065439.GA3579%40ubuntu
patch subject: [PATCH] staging: rts5208: Add parenthesis to macro arguments
config: arc-randconfig-001-20231022 (https://download.01.org/0day-ci/archive/20231022/[email protected]/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231022/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from drivers/staging/rts5208/rtsx_scsi.c:17:
>> drivers/staging/rts5208/rtsx.h:42:27: error: expected parameter name, found "("
42 | #define rtsx_writel(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:44:26: error: expected parameter name, found "("
44 | #define rtsx_readl(chip, (reg) \
| ^
drivers/staging/rts5208/rtsx.h:46:27: error: expected parameter name, found "("
46 | #define rtsx_writew(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:48:26: error: expected parameter name, found "("
48 | #define rtsx_readw(chip, (reg)) \
| ^
drivers/staging/rts5208/rtsx.h:50:27: error: expected parameter name, found "("
50 | #define rtsx_writeb(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:52:26: error: expected parameter name, found "("
52 | #define rtsx_readb(chip, (reg)) \
| ^
drivers/staging/rts5208/rtsx_scsi.c: In function 'read_host_reg':
>> drivers/staging/rts5208/rtsx_scsi.c:1350:15: error: implicit declaration of function 'rtsx_readl'; did you mean 'rtsx_dev'? [-Werror=implicit-function-declaration]
1350 | val = rtsx_readl(chip, addr);
| ^~~~~~~~~~
| rtsx_dev
drivers/staging/rts5208/rtsx_scsi.c: In function 'write_host_reg':
>> drivers/staging/rts5208/rtsx_scsi.c:1388:9: error: implicit declaration of function 'rtsx_writel' [-Werror=implicit-function-declaration]
1388 | rtsx_writel(chip, addr, val);
| ^~~~~~~~~~~
cc1: some warnings being treated as errors
--
In file included from drivers/staging/rts5208/spi.c:16:
>> drivers/staging/rts5208/rtsx.h:42:27: error: expected parameter name, found "("
42 | #define rtsx_writel(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:44:26: error: expected parameter name, found "("
44 | #define rtsx_readl(chip, (reg) \
| ^
drivers/staging/rts5208/rtsx.h:46:27: error: expected parameter name, found "("
46 | #define rtsx_writew(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:48:26: error: expected parameter name, found "("
48 | #define rtsx_readw(chip, (reg)) \
| ^
drivers/staging/rts5208/rtsx.h:50:27: error: expected parameter name, found "("
50 | #define rtsx_writeb(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:52:26: error: expected parameter name, found "("
52 | #define rtsx_readb(chip, (reg)) \
| ^
--
In file included from drivers/staging/rts5208/sd.c:16:
>> drivers/staging/rts5208/rtsx.h:42:27: error: expected parameter name, found "("
42 | #define rtsx_writel(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:44:26: error: expected parameter name, found "("
44 | #define rtsx_readl(chip, (reg) \
| ^
drivers/staging/rts5208/rtsx.h:46:27: error: expected parameter name, found "("
46 | #define rtsx_writew(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:48:26: error: expected parameter name, found "("
48 | #define rtsx_readw(chip, (reg)) \
| ^
drivers/staging/rts5208/rtsx.h:50:27: error: expected parameter name, found "("
50 | #define rtsx_writeb(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:52:26: error: expected parameter name, found "("
52 | #define rtsx_readb(chip, (reg)) \
| ^
drivers/staging/rts5208/sd.c: In function 'sd_check_wp_state':
>> drivers/staging/rts5208/sd.c:2278:15: error: implicit declaration of function 'rtsx_readl'; did you mean 'rtsx_dev'? [-Werror=implicit-function-declaration]
2278 | val = rtsx_readl(chip, RTSX_BIPR);
| ^~~~~~~~~~
| rtsx_dev
cc1: some warnings being treated as errors
--
In file included from drivers/staging/rts5208/rtsx_transport.c:16:
>> drivers/staging/rts5208/rtsx.h:42:27: error: expected parameter name, found "("
42 | #define rtsx_writel(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:44:26: error: expected parameter name, found "("
44 | #define rtsx_readl(chip, (reg) \
| ^
drivers/staging/rts5208/rtsx.h:46:27: error: expected parameter name, found "("
46 | #define rtsx_writew(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:48:26: error: expected parameter name, found "("
48 | #define rtsx_readw(chip, (reg)) \
| ^
drivers/staging/rts5208/rtsx.h:50:27: error: expected parameter name, found "("
50 | #define rtsx_writeb(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:52:26: error: expected parameter name, found "("
52 | #define rtsx_readb(chip, (reg)) \
| ^
drivers/staging/rts5208/rtsx_transport.c: In function 'rtsx_send_cmd_no_wait':
>> drivers/staging/rts5208/rtsx_transport.c:215:9: error: implicit declaration of function 'rtsx_writel'; did you mean 'vfs_write'? [-Werror=implicit-function-declaration]
215 | rtsx_writel(chip, RTSX_HCBAR, chip->host_cmds_addr);
| ^~~~~~~~~~~
| vfs_write
cc1: some warnings being treated as errors
--
In file included from drivers/staging/rts5208/rtsx_chip.c:18:
>> drivers/staging/rts5208/rtsx.h:42:27: error: expected parameter name, found "("
42 | #define rtsx_writel(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:44:26: error: expected parameter name, found "("
44 | #define rtsx_readl(chip, (reg) \
| ^
drivers/staging/rts5208/rtsx.h:46:27: error: expected parameter name, found "("
46 | #define rtsx_writew(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:48:26: error: expected parameter name, found "("
48 | #define rtsx_readw(chip, (reg)) \
| ^
drivers/staging/rts5208/rtsx.h:50:27: error: expected parameter name, found "("
50 | #define rtsx_writeb(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:52:26: error: expected parameter name, found "("
52 | #define rtsx_readb(chip, (reg)) \
| ^
drivers/staging/rts5208/rtsx_chip.c: In function 'rtsx_enable_card_int':
>> drivers/staging/rts5208/rtsx_chip.c:37:19: error: implicit declaration of function 'rtsx_readl'; did you mean 'rtsx_dev'? [-Werror=implicit-function-declaration]
37 | u32 reg = rtsx_readl(chip, RTSX_BIER);
| ^~~~~~~~~~
| rtsx_dev
>> drivers/staging/rts5208/rtsx_chip.c:51:9: error: implicit declaration of function 'rtsx_writel'; did you mean 'vfs_write'? [-Werror=implicit-function-declaration]
51 | rtsx_writel(chip, RTSX_BIER, reg);
| ^~~~~~~~~~~
| vfs_write
cc1: some warnings being treated as errors
--
In file included from drivers/staging/rts5208/rtsx_card.c:18:
>> drivers/staging/rts5208/rtsx.h:42:27: error: expected parameter name, found "("
42 | #define rtsx_writel(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:44:26: error: expected parameter name, found "("
44 | #define rtsx_readl(chip, (reg) \
| ^
drivers/staging/rts5208/rtsx.h:46:27: error: expected parameter name, found "("
46 | #define rtsx_writew(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:48:26: error: expected parameter name, found "("
48 | #define rtsx_readw(chip, (reg)) \
| ^
drivers/staging/rts5208/rtsx.h:50:27: error: expected parameter name, found "("
50 | #define rtsx_writeb(chip, (reg), value) \
| ^
drivers/staging/rts5208/rtsx.h:52:26: error: expected parameter name, found "("
52 | #define rtsx_readb(chip, (reg)) \
| ^
drivers/staging/rts5208/rtsx_card.c: In function 'rtsx_release_cards':
>> drivers/staging/rts5208/rtsx_card.c:328:25: error: implicit declaration of function 'rtsx_readl'; did you mean 'rtsx_dev'? [-Werror=implicit-function-declaration]
328 | chip->int_reg = rtsx_readl(chip, RTSX_BIPR);
| ^~~~~~~~~~
| rtsx_dev
cc1: some warnings being treated as errors


vim +42 drivers/staging/rts5208/rtsx.h

38
39 /*
40 * macros for easy use
41 */
> 42 #define rtsx_writel(chip, (reg), value) \
43 iowrite32(value, (chip)->rtsx->remap_addr + reg)
44 #define rtsx_readl(chip, (reg) \
45 ioread32((chip)->rtsx->remap_addr + reg)
46 #define rtsx_writew(chip, (reg), value) \
47 iowrite16(value, (chip)->rtsx->remap_addr + reg)
48 #define rtsx_readw(chip, (reg)) \
49 ioread16((chip)->rtsx->remap_addr + reg)
50 #define rtsx_writeb(chip, (reg), value) \
51 iowrite8(value, (chip)->rtsx->remap_addr + reg)
52 #define rtsx_readb(chip, (reg)) \
53 ioread8((chip)->rtsx->remap_addr + reg)
54

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki