Skip to contentSkip to conversation

scsi: ufs: mediatek: avoid sched_clock() misuse

PATCH Applied Arnd Bergmann 4 participants 4 messages Oct 18, 2021 – Oct 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: ufs: mediatek: avoid sched_clock() misuse

From: Arnd Bergmann <[email protected]>

sched_clock() is not meant to be used in portable driver code, and assuming a particular clock frequency is not how this is meant to be used. It also causes a build failure because of a missing header inclusion:

drivers/scsi/ufs/ufs-mediatek.c:321:12: error: implicit declaration of function 'sched_clock' [-Werror,-Wimplicit-function-declaration]

        timeout = sched_clock() + retry_ms * 1000000UL;

A better interface to use here ktime_get_mono_fast_ns(), which works mostly like ktime_get() but is safe to use inside of a suspend callback.

Fixes 9561f58442e4 ("scsi: ufs: mediatek: Support vops pre suspend to disable auto-hibern8")
---
 drivers/scsi/ufs/ufs-mediatek.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/ufs/ufs-mediatek.c +3 -3
index d1696db70ce8..a47241ed0a57 100644
@@ -318,15 +318,15 @@ static void ufs_mtk_wait_idle_state(struct ufs_hba *hba,
 	u32 val, sm;
 	bool wait_idle;
 
-	timeout = sched_clock() + retry_ms * 1000000UL;
-
+	/* cannot use plain ktime_get() in suspend */
+	timeout = ktime_get_mono_fast_ns() + retry_ms * 1000000UL;
 
 	/* wait a specific time after check base */
 	udelay(10);
 	wait_idle = false;
 
 	do {
-		time_checked = sched_clock();
+		time_checked = ktime_get_mono_fast_ns();
 		ufs_mtk_dbg_sel(hba);
 		val = ufshcd_readl(hba, REG_UFS_PROBE);
 
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw

Hi Arnd,

Quoted 28 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

sched_clock() is not meant to be used in portable driver code, and assuming a particular clock frequency is not how this is meant to be used. It also causes a build failure because of a missing header inclusion:

drivers/scsi/ufs/ufs-mediatek.c:321:12: error: implicit declaration of function 'sched_clock' [-Werror,-Wimplicit-function-declaration]

        timeout = sched_clock() + retry_ms * 1000000UL;

A better interface to use here ktime_get_mono_fast_ns(), which works mostly like ktime_get() but is safe to use inside of a suspend callback.

Fixes 9561f58442e4 ("scsi: ufs: mediatek: Support vops pre suspend

to disable auto-hibern8")

---
 drivers/scsi/ufs/ufs-mediatek.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/ufs/ufs- renamed from drivers/scsi/ufs/ufs-mediatek.c +0 -0

mediatek.c
index d1696db70ce8..a47241ed0a57 100644

drivers/scsi/ufs/ufs-mediatek.c static void ufs_mtk_wait_idle_state(struct · line 323

Quoted 8 lines
drivers/scsi/ufs/ufs-mediatek.c +2 -2
@@ -318,15 +318,15 @@ static void ufs_mtk_wait_idle_state(struct
 ufs_hba *hba,
 	u32 val, sm;
 	bool wait_idle;
 
-	timeout = sched_clock() + retry_ms * 1000000UL;
-
+	/* cannot use plain ktime_get() in suspend */
+	timeout = ktime_get_mono_fast_ns() + retry_ms * 1000000UL;

Thanks for this fix.

Quoted 11 lines
drivers/scsi/ufs/ufs-mediatek.c +1 -1
 	/* wait a specific time after check base */
 	udelay(10);
 	wait_idle = false;
 
 	do {
-		time_checked = sched_clock();
+		time_checked = ktime_get_mono_fast_ns();
 		ufs_mtk_dbg_sel(hba);
 		val = ufshcd_readl(hba, REG_UFS_PROBE);
 
#2 lore raw
In reply to Arnd Bergmann
Quoted 28 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

sched_clock() is not meant to be used in portable driver code, and assuming a particular clock frequency is not how this is meant to be used. It also causes a build failure because of a missing header inclusion:

drivers/scsi/ufs/ufs-mediatek.c:321:12: error: implicit declaration of function 'sched_clock' [-Werror,-Wimplicit-function-declaration]

        timeout = sched_clock() + retry_ms * 1000000UL;

A better interface to use here ktime_get_mono_fast_ns(), which works mostly like ktime_get() but is safe to use inside of a suspend callback.

Fixes 9561f58442e4 ("scsi: ufs: mediatek: Support vops pre suspend

to disable auto-hibern8")

---
 drivers/scsi/ufs/ufs-mediatek.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/ufs/ufs- renamed from drivers/scsi/ufs/ufs-mediatek.c +0 -0

mediatek.c
index d1696db70ce8..a47241ed0a57 100644

drivers/scsi/ufs/ufs-mediatek.c static void ufs_mtk_wait_idle_state(struct · line 323

Quoted 8 lines
drivers/scsi/ufs/ufs-mediatek.c +2 -2
@@ -318,15 +318,15 @@ static void ufs_mtk_wait_idle_state(struct
 ufs_hba *hba,
 	u32 val, sm;
 	bool wait_idle;
 
-	timeout = sched_clock() + retry_ms * 1000000UL;
-
+	/* cannot use plain ktime_get() in suspend */
+	timeout = ktime_get_mono_fast_ns() + retry_ms * 1000000UL;

Thanks for this patch.

Quoted 11 lines
drivers/scsi/ufs/ufs-mediatek.c +1 -1
 	/* wait a specific time after check base */
 	udelay(10);
 	wait_idle = false;
 
 	do {
-		time_checked = sched_clock();
+		time_checked = ktime_get_mono_fast_ns();
 		ufs_mtk_dbg_sel(hba);
 		val = ufshcd_readl(hba, REG_UFS_PROBE);
 
#3 lore raw
In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

sched_clock() is not meant to be used in portable driver code, and assuming a particular clock frequency is not how this is meant to be used. It also causes a build failure because of a missing header inclusion:

[...]

Applied to 5.16/scsi-queue, thanks!

[1/1] scsi: ufs: mediatek: avoid sched_clock() misuse

      https://git.kernel.org/mkp/scsi/c/bb4a8dcb4e94
Signature · 6 lines
Martin K. Petersen	Oracle Linux Engineering

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek