[PATCH 3/3] drivers/card_reader/rtsx_usb: Fix clock switching logic
From: Sean Rhodes
Date: Tue Nov 19 2024 - 07:22:49 EST
Fix the `rtsx_usb_switch_clock` function to ensure the `card_clock`
parameter is not inadvertently modified during the function's
execution. This change:
- Introduces a `hardware_clock` variable to store the original clock
value, preserving the integrity of the `card_clock` parameter.
- Updates the assignment of `ucr->cur_clk` to use `original_card_clock`.
This adjustment aligns the behavior with the intended logic and
prevents unintended side effects from modifying input parameters.
Cc: Arnd Bergmann <arnd@xxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
---
drivers/misc/cardreader/rtsx_usb.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/cardreader/rtsx_usb.c b/drivers/misc/cardreader/rtsx_usb.c
index 285a748748d7..f5936c021777 100644
--- a/drivers/misc/cardreader/rtsx_usb.c
+++ b/drivers/misc/cardreader/rtsx_usb.c
@@ -406,6 +406,7 @@ int rtsx_usb_switch_clock(struct rtsx_ucr *ucr, unsigned int card_clock,
{
int ret;
u8 n, clk_divider, mcu_cnt, div;
+ unsigned int original_card_clock = card_clock;
if (!card_clock) {
ucr->cur_clk = 0;
@@ -494,7 +495,7 @@ int rtsx_usb_switch_clock(struct rtsx_ucr *ucr, unsigned int card_clock,
if (ret < 0)
return ret;
- ucr->cur_clk = card_clock;
+ ucr->cur_clk = original_card_clock;
return 0;
}
--
2.43.0