Skip to contentSkip to conversation

staging: rts5208: Add parenthesis to macro arguments

PATCH In review kenechukwu maduechesi 4 participants 4 messages Oct 20, 2023 – Oct 22, 2023 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/staging/rts5208/rtsx.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/staging/rts5208/rtsx.h +8 -8
index 2e101da83220..7d3373797eb4 100644
@@ -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))
Signature · 1 line
2.25.1
#1 lore raw
Quoted 18 lines · kenechukwu maduechesi

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.

---
 drivers/staging/rts5208/rtsx.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/staging/rts5208/rtsx.h +0 -0
index 2e101da83220..7d3373797eb4 100644

drivers/staging/rts5208/rtsx.h line 42

Quoted 5 lines
drivers/staging/rts5208/rtsx.h +1 -1
@@ -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.

drivers/staging/rts5208/rtsx.h line 43

Quoted 1 line
drivers/staging/rts5208/rtsx.h +0 -0
 	iowrite32(value, (chip)->rtsx->remap_addr + reg)

regards,
dan carpenter

#2 lore raw
In reply to kenechukwu maduechesi
Quoted 18 lines · kenechukwu maduechesi

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.

---
 drivers/staging/rts5208/rtsx.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/staging/rts5208/rtsx.h +0 -0
index 2e101da83220..7d3373797eb4 100644

drivers/staging/rts5208/rtsx.h line 43

Quoted 6 lines
drivers/staging/rts5208/rtsx.h +1 -1
@@ -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.

drivers/staging/rts5208/rtsx.h line 44

Quoted 2 lines
drivers/staging/rts5208/rtsx.h +1 -1
-#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.

Quoted 16 lines
drivers/staging/rts5208/rtsx.h +4 -4
 	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) \

drivers/staging/rts5208/rtsx.h static inline struct rtsx_dev *host_to_rtsx(struct Scsi_Host *host) · line 135

Quoted 7 lines
drivers/staging/rts5208/rtsx.h +2 -2
@@ -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

Quoted 7 lines
drivers/staging/rts5208/rtsx.h +0 -1
 #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

#3 lore raw
In reply to kenechukwu maduechesi
kernel test robot noticed the following build errors:

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	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki