media: sti: bdisp: fix a possible sleep-in-atomic-context bug in bdisp_device_run()
PATCH v2 1/1 media: sti: bdisp: fix a possible sleep-in-atomic-context bug in bdisp_device_run()
The driver may sleep while holding a spinlock.
The function call path (from bottom to top) in Linux 4.19 is:
drivers/media/platform/sti/bdisp/bdisp-hw.c, 385:
msleep in bdisp_hw_resetdrivers/media/platform/sti/bdisp/bdisp-v4l2.c, 341:
bdisp_hw_reset in bdisp_device_rundrivers/media/platform/sti/bdisp/bdisp-v4l2.c, 317:
_raw_spin_lock_irqsave in bdisp_device_run
To fix this bug, msleep() is replaced with udelay().
This bug is found by a static analysis tool STCheck written by myself.
---
v2:
* Use udelay() instead of mdelay().
Thank Fabien for good advice.
--- drivers/media/platform/sti/bdisp/bdisp-hw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/sti/bdisp/bdisp-hw.c +3 -3
@@ -14,8 +14,8 @@#define MAX_SRC_WIDTH 2048/* Reset & boot poll config */ -#define POLL_RST_MAX 50 -#define POLL_RST_DELAY_MS 20 +#define POLL_RST_MAX 500 +#define POLL_RST_DELAY_MS 2enum bdisp_target_plan {BDISP_RGB ,
@@ -382,7 +382,7 @@ int bdisp_hw_reset(struct bdisp_dev *bdisp)for (i =0 ; i <POLL_RST_MAX ; i++) {if (readl (bdisp->regs +BLT_STA1 ) &BLT_STA1_IDLE )break ; -msleep (POLL_RST_DELAY_MS ); +udelay (POLL_RST_DELAY_MS *1000 ); }if (i ==POLL_RST_MAX )dev_err (bdisp->dev,"Reset timeout\n" );
Signature · 1 line
2.17.1
Thank you!
Quoted 10 lines · Jia-Ju Bai
The driver may sleep while holding a spinlock.
The function call path (from bottom to top) in Linux 4.19 is:
drivers/media/platform/sti/bdisp/bdisp-hw.c, 385:
msleep inbdisp_hw_resetdrivers/media/platform/sti/bdisp/bdisp-v4l2.c, 341:
bdisp_hw_resetinbdisp_device_rundrivers/media/platform/sti/bdisp/bdisp-v4l2.c, 317:
_raw_spin_lock_irqsaveinbdisp_device_run
Quoted 5 lines
To fix this bug,
msleep()is replaced withudelay().This bug is found by a static analysis tool STCheck written by myself.
Signed-off-by Jia-Ju Bai <[email protected]>
Quoted 33 lines
---
v2:
* Useudelay()instead ofmdelay().
Thank Fabien for good advice.--- drivers/media/platform/sti/bdisp/bdisp-hw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/media/platform/sti/bdisp/bdisp-hw.c +3
-3@@ -14,8 +14,8 @@#define MAX_SRC_WIDTH 2048/* Reset & boot poll config */ -#define POLL_RST_MAX 50 -#define POLL_RST_DELAY_MS 20 +#define POLL_RST_MAX 500 +#define POLL_RST_DELAY_MS 2enum bdisp_target_plan {BDISP_RGB ,@@ -382,7 +382,7 @@ int bdisp_hw_reset(struct bdisp_dev *bdisp)for (i =0 ; i <POLL_RST_MAX ; i++) {if (readl (bdisp->regs +BLT_STA1 ) &BLT_STA1_IDLE )break ; -msleep (POLL_RST_DELAY_MS ); +udelay (POLL_RST_DELAY_MS *1000 ); }if (i ==POLL_RST_MAX )dev_err (bdisp->dev,"Reset timeout\n" );