Re: [PATCH] staging: rtl8723bs: refactor switch-case
From: Dan Carpenter
Date: Mon Mar 30 2026 - 05:35:45 EST
On Sat, Mar 28, 2026 at 07:33:58PM +0300, Bera Yüzlü wrote:
> Refactored huge switch-case to lookup table. Used if-else for dynamic
> values.
>
> Signed-off-by: Bera Yüzlü <b9788213@xxxxxxxxx>
> ---
> .../staging/rtl8723bs/hal/HalBtc8723b1Ant.c | 269 +++++-------------
> 1 file changed, 69 insertions(+), 200 deletions(-)
>
> diff --git a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
> index b3e34f97cfc6..c02df8e3c398 100644
> --- a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
> +++ b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
> @@ -989,6 +989,51 @@ static void halbtc8723b1ant_SetFwPstdma(
> pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
> }
>
> +static const u32 FwPstdma_table[41][5] = {
> + {0, 0, 0, 0, 0}, // 0
> + {0, 0, 0, 0, 0},
> + {0, 0, 0, 0, 0},
> + {0x51, 0x1d, 0x1d, 0x0, 0x10},
> + {0x93, 0x15, 0x3, 0x14, 0x0},
> + {0x61, 0x15, 0x3, 0x11, 0x10}, // 5
> + {0x61, 0x20, 0x3, 0x11, 0x11},
> + {0x13, 0xc, 0x5, 0x0, 0x0},
> + {0x93, 0x25, 0x3, 0x10, 0x0},
> + {0, 0, 0, 0, 0},
> + {0x13, 0xa, 0xa, 0x0, 0x40}, // 10
> + {0, 0, 0, 0, 0},
> + {0x51, 0x0a, 0x0a, 0x0, 0x50},
> + {0x51, 0x12, 0x12, 0x0, 0x10},
> + {0, 0, 0, 0, 0},
> + {0x13, 0xa, 0x3, 0x8, 0x0}, // 15
> + {0x93, 0x15, 0x3, 0x10, 0x0},
> + {0, 0, 0, 0, 0},
This patch is sort of a pain in the butt to review... I'm not
sure that it improves readability. I had to read until I got
to 17 before I found a mistake.
> + {0x93, 0x25, 0x3, 0x10, 0x0},
> + {0, 0, 0, 0, 0},
> + {0x61, 0x3f, 0x03, 0x11, 0x10}, // 20
[ snip ]
> + else if (type == 0 || type == 17 || type == 19 || type == 37 || type == 38 || type == 39)
> + halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51,
> + 0x1a, 0x1a,
> + 0x0, psTdmaByte4Val);
In the original code there was no entry for 17 but in the new patch it's
treated like a 0. What's the deal with that?
$ grep 17 drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c
regards,
dan carpenter
> + else if (type < 41)
> + halbtc8723b1ant_SetFwPstdma(pBtCoexist, FwPstdma_table[type][0],
> + FwPstdma_table[type][1], FwPstdma_table[type][2],
> + FwPstdma_table[type][3], FwPstdma_table[type][4]);