Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: ufs: core: Start the RTC update work later

The RTC update work involves runtime resuming the UFS controller. Hence,
only start the RTC update work after runtime power management in the UFS
driver has been fully initialized. This patch fixes the following kernel
crash:

Internal error: Oops: 0000000096000006 [#1] PREEMPT SMP
Workqueue: events ufshcd_rtc_work
Call trace:
_raw_spin_lock_irqsave+0x34/0x8c (P)
pm_runtime_get_if_active+0x24/0x9c (L)
pm_runtime_get_if_active+0x24/0x9c
ufshcd_rtc_work+0x138/0x1b4
process_one_work+0x148/0x288
worker_thread+0x2cc/0x3d4
kthread+0x110/0x114
ret_from_fork+0x10/0x20

Reported-by: Neil Armstrong <neil.armstrong@linaro.org>
Closes: https://lore.kernel.org/linux-scsi/0c0bc528-fdc2-4106-bc99-f23ae377f6f5@linaro.org/
Fixes: 6bf999e0eb41 ("scsi: ufs: core: Add UFS RTC support")
Cc: Bean Huo <beanhuo@micron.com>
Cc: stable@vger.kernel.org
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20241031212632.2799127-1-bvanassche@acm.org
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8650-HDK
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
54c814c8 7ce3e610

+8 -2
+8 -2
drivers/ufs/core/ufshcd.c
··· 8636 8636 ufshcd_init_clk_scaling_sysfs(hba); 8637 8637 } 8638 8638 8639 + /* 8640 + * The RTC update code accesses the hba->ufs_device_wlun->sdev_gendev 8641 + * pointer and hence must only be started after the WLUN pointer has 8642 + * been initialized by ufshcd_scsi_add_wlus(). 8643 + */ 8644 + schedule_delayed_work(&hba->ufs_rtc_update_work, 8645 + msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS)); 8646 + 8639 8647 ufs_bsg_probe(hba); 8640 8648 scsi_scan_host(hba->host); 8641 8649 ··· 8803 8795 ufshcd_force_reset_auto_bkops(hba); 8804 8796 8805 8797 ufshcd_set_timestamp_attr(hba); 8806 - schedule_delayed_work(&hba->ufs_rtc_update_work, 8807 - msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS)); 8808 8798 8809 8799 /* Gear up to HS gear if supported */ 8810 8800 if (hba->max_pwr_info.is_valid) {