MIPS: rtlx: Fix two error paths in rtlx_open()
cover MIPS: rtlx: Fix two error paths in rtlx_open()
Two error paths in rtlx_open() leave state behind: a failed rtlx_init() skips the in_open decrement, so the channel stays busy for good, and a signal while waiting for the SP program leaves the stack wait entry on the queue.
Found with a static analysis tool and checked by hand. Compile tested on mips (maltaaprp_defconfig, W=1); I don't have the hardware.
---
Suyuan Wang (2):
MIPS: rtlx: Drop in_open count when rtlx_init() fails
MIPS: rtlx: Call finish_wait() when rtlx_open() is interrupted
arch/mips/kernel/rtlx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
PATCH 1/2 MIPS: rtlx: Drop in_open count when rtlx_init() fails
From: Suyuan Wang <[email protected]>
rtlx_open() raises channel_wqs[index].in_open at the start and drops it again at out_fail, on both the success and the error paths. When rtlx_init() fails, for example because the SP program has no valid RTLX id, the code jumps to out_ret instead and skips the decrement.
After that, every later open of the channel sees in_open > 1 and fails with -EBUSY, even after a correct SP program is loaded.
Jump to out_fail so the count is dropped, and remove the now unused out_ret label.
Found with a static analysis tool and checked by hand.
--- arch/mips/kernel/rtlx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/mips/kernel/rtlx.c +1 -2
@@ -159,7 +159,7 @@ int rtlx_open(int index, int can_sleep) ret =rtlx_init (*p);if (ret <0 ) - goto out_ret; + goto out_fail; } chan = &rtlx->channel[index];
@@ -175,7 +175,6 @@ int rtlx_open(int index, int can_sleep)atomic_dec (&channel_wqs[index].in_open);smp_mb (); -out_ret:return ret; }
Signature · 1 line
2.34.1
PATCH 2/2 MIPS: rtlx: Call finish_wait() when rtlx_open() is interrupted
In reply to Suyuan WangFrom: Suyuan Wang <[email protected]>
While rtlx_open() waits for the SP program, it calls prepare_to_wait() with a wait entry on its own stack. If a signal is pending, it leaves the loop with:
ret = -ERESTARTSYS; goto out_fail;
and skips finish_wait(). The stack wait entry stays on channel_wqs[index].lx_queue after rtlx_open() returns, and the task is still in TASK_INTERRUPTIBLE state. A later wake up of that queue then walks a stale stack entry.
Call finish_wait() before leaving the loop on a signal.
Found with a static analysis tool and checked by hand.
--- arch/mips/kernel/rtlx.c | 2 ++ 1 file changed, 2 insertions(+)
arch/mips/kernel/rtlx.c +2 -0
@@ -138,6 +138,8 @@ int rtlx_open(int index, int can_sleep)schedule ();continue ; } +finish_wait (&channel_wqs[index].lx_queue, + &wait); ret = -ERESTARTSYS ; goto out_fail; }
Signature · 1 line
2.34.1