Improve code readability
cover Improve code readability
Improve code readability in wilc_spi_read_int function in wilc_spi.c file from wilc1000 driver.
Tamara Diaconita (3):
staging: wilc1000: Remove unnecessary brackets
staging: wilc1000: Declare variables at top of function
staging: wilc1000: Correct name of variables
drivers/staging/wilc1000/wilc_spi.c | 49 ++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 28 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/3 staging: wilc1000: Remove unnecessary brackets
Improved code readability by removing unnecessary brackets and deleting tabs to indent.
--- drivers/staging/wilc1000/wilc_spi.c | 44 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 24 deletions(-)
drivers/staging/wilc1000/wilc_spi.c +20 -24
@@ -946,39 +946,35 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) } tmp = (byte_cnt >>2 ) &IRQ_DMA_WD_CNT_MASK ; - { -int happended, j; +int happended, j; - j =0 ; -do { -u32 irq_flags; + j =0 ; +do { +u32 irq_flags; - happended =0 ; + happended =0 ; -wilc_spi_read_reg (wilc,0x1a90 , &irq_flags); - tmp |= ((irq_flags >>27 ) <<IRG_FLAGS_OFFSET ); +wilc_spi_read_reg (wilc,0x1a90 , &irq_flags); + tmp |= ((irq_flags >>27 ) <<IRG_FLAGS_OFFSET ); -if (g_spi.nint >5 ) { -wilc_spi_read_reg (wilc,0x1a94 , - &irq_flags); - tmp |= (((irq_flags >>0 ) &0x7 ) << (IRG_FLAGS_OFFSET +5 )); - } +if (g_spi.nint >5 ) { +wilc_spi_read_reg (wilc,0x1a94 , + &irq_flags); + tmp |= (((irq_flags >>0 ) &0x7 ) << (IRG_FLAGS_OFFSET +5 )); + } - { -u32 unkmown_mask; +u32 unkmown_mask; - unkmown_mask = ~((1ul << g_spi.nint) -1 ); + unkmown_mask = ~((1ul << g_spi.nint) -1 ); -if ((tmp >>IRG_FLAGS_OFFSET ) & unkmown_mask) { -dev_err (&spi->dev,"Unexpected interrupt (2): j=%d, tmp=%x, mask=%x\n" , j, tmp, unkmown_mask); - happended =1 ; - } +if ((tmp >>IRG_FLAGS_OFFSET ) & unkmown_mask) { +dev_err (&spi->dev,"Unexpected interrupt (2): j=%d, tmp=%x, mask=%x\n" , j, tmp, unkmown_mask); + happended =1 ; } - j++; - }while (happended); - } + j++; + }while (happended); - *int_status = tmp; + *int_status = tmp; } _fail_:
Signature · 1 line
2.9.3
Re: [Outreachy kernel] [PATCH 1/3] staging: wilc1000: Remove unnecessary brackets
Quoted 13 lines · Tamara Diaconita
Improved code readability by removing unnecessary brackets and deleting tabs to indent.
Signed-off-by Tamara Diaconita <[email protected]>--- drivers/staging/wilc1000/wilc_spi.c | 44 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 24 deletions(-)drivers/staging/wilc1000/wilc_spi.c +0
-0
drivers/staging/wilc1000/wilc_spi.c static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) · line 949
Quoted 6 lines
drivers/staging/wilc1000/wilc_spi.c +1
-2@@ -946,39 +946,35 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) } tmp = (byte_cnt >>2 ) &IRQ_DMA_WD_CNT_MASK ; - { -int happended, j; +int happended, j;
Not correct. The Linux kernel should not have variable declarations at random places in a block.
Organize the patches in a different way so that there is not this intermediate step.
julia
Quoted 63 lines
drivers/staging/wilc1000/wilc_spi.c +19
-23- j =0 ; -do { -u32 irq_flags; + j =0 ; +do { +u32 irq_flags; - happended =0 ; + happended =0 ; -wilc_spi_read_reg (wilc,0x1a90 , &irq_flags); - tmp |= ((irq_flags >>27 ) <<IRG_FLAGS_OFFSET ); +wilc_spi_read_reg (wilc,0x1a90 , &irq_flags); + tmp |= ((irq_flags >>27 ) <<IRG_FLAGS_OFFSET ); -if (g_spi.nint >5 ) { -wilc_spi_read_reg (wilc,0x1a94 , - &irq_flags); - tmp |= (((irq_flags >>0 ) &0x7 ) << (IRG_FLAGS_OFFSET +5 )); - } +if (g_spi.nint >5 ) { +wilc_spi_read_reg (wilc,0x1a94 , + &irq_flags); + tmp |= (((irq_flags >>0 ) &0x7 ) << (IRG_FLAGS_OFFSET +5 )); + } - { -u32 unkmown_mask; +u32 unkmown_mask; - unkmown_mask = ~((1ul << g_spi.nint) -1 ); + unkmown_mask = ~((1ul << g_spi.nint) -1 ); -if ((tmp >>IRG_FLAGS_OFFSET ) & unkmown_mask) { -dev_err (&spi->dev,"Unexpected interrupt (2): j=%d, tmp=%x, mask=%x\n" , j, tmp, unkmown_mask); - happended =1 ; - } +if ((tmp >>IRG_FLAGS_OFFSET ) & unkmown_mask) { +dev_err (&spi->dev,"Unexpected interrupt (2): j=%d, tmp=%x, mask=%x\n" , j, tmp, unkmown_mask); + happended =1 ; } - j++; - }while (happended); - } + j++; + }while (happended); - *int_status = tmp; + *int_status = tmp; } _fail_: --2.9.3
--
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/20170311110652.8384-2-diaconita.tamara%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
PATCH 2/3 staging: wilc1000: Declare variables at top of function
In reply to Tamara DiaconitaMoving declaration of some variables at top of wilc_spi_read_int function to imrpove code readability.
--- drivers/staging/wilc1000/wilc_spi.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/staging/wilc1000/wilc_spi.c +8 -11
@@ -929,6 +929,9 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) {struct spi_device *spi =to_spi_device (wilc->dev);int ret; +int happended, j; +u32 irq_flags; +u32 unkmown_mask;if (g_spi.has_thrpt_enh) { ret = spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE,
@@ -946,12 +949,8 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) } tmp = (byte_cnt >>2 ) &IRQ_DMA_WD_CNT_MASK ; -int happended, j; - j =0 ; do { - u32 irq_flags; - happended = 0; wilc_spi_read_reg(wilc, 0x1a90, &irq_flags);
@@ -963,14 +962,12 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) tmp |= (((irq_flags >>0 ) &0x7 ) << (IRG_FLAGS_OFFSET +5 )); } -u32 unkmown_mask; - - unkmown_mask = ~((1ul << g_spi.nint) -1 ); + unkmown_mask = ~((1ul << g_spi.nint) -1 ); -if ((tmp >>IRG_FLAGS_OFFSET ) & unkmown_mask) { -dev_err (&spi->dev,"Unexpected interrupt (2): j=%d, tmp=%x, mask=%x\n" , j, tmp, unkmown_mask); - happended =1 ; - } +if ((tmp >>IRG_FLAGS_OFFSET ) & unkmown_mask) { +dev_err (&spi->dev,"Unexpected interrupt (2): j=%d, tmp=%x, mask=%x\n" , j, tmp, unkmown_mask); + happended =1 ; + } j++; }while (happended);
Signature · 1 line
2.9.3
PATCH 3/3 staging: wilc1000: Correct name of variables
In reply to Tamara DiaconitaCorrect misspelled variables: unkmown_mask and happended to improve code readability.
Problem found with checkpatch.pl.
--- drivers/staging/wilc1000/wilc_spi.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/staging/wilc1000/wilc_spi.c +8 -8
@@ -929,9 +929,9 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) {struct spi_device *spi =to_spi_device (wilc->dev);int ret; -int happended, j; +int happened, j;u32 irq_flags; -u32 unkmown_mask; +u32 unknown_mask;if (g_spi.has_thrpt_enh) { ret = spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE,
@@ -951,7 +951,7 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) j =0 ; do { - happended = 0; + happened = 0; wilc_spi_read_reg(wilc, 0x1a90, &irq_flags); tmp |= ((irq_flags >> 27) << IRG_FLAGS_OFFSET);
@@ -962,14 +962,14 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) tmp |= (((irq_flags >>0 ) &0x7 ) << (IRG_FLAGS_OFFSET +5 )); } - unkmown_mask = ~((1ul << g_spi.nint) -1 ); + unknown_mask = ~((1ul << g_spi.nint) -1 ); -if ((tmp >>IRG_FLAGS_OFFSET ) & unkmown_mask) { -dev_err (&spi->dev,"Unexpected interrupt (2): j=%d, tmp=%x, mask=%x\n" , j, tmp, unkmown_mask); - happended =1 ; +if ((tmp >>IRG_FLAGS_OFFSET ) & unknown_mask) { +dev_err (&spi->dev,"Unexpected interrupt (2): j=%d, tmp=%x, mask=%x\n" , j, tmp, unknown_mask); + happened =1 ; } j++; - }while (happended); + }while (happened); *int_status = tmp; }
Signature · 1 line
2.9.3