Re: [PATCH 1/2] scsi: ufs: Add Multi-Circular Queue support

Dan Carpenter
2022-07-25T09:16:51Z

Hi Can,

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Can-Guo/UFS-Multi-Circular-Queue-MCQ/20220719-150436
base: https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
config: arc-randconfig-m041-20220718 (https://download.01.org/0day-ci/archive/20220723/202207231904.OkiLJTiT-lkp@intel.com/config)
compiler: arceb-elf-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
drivers/ufs/core/ufshcd.c:2887 ufshcd_queuecommand() error: uninitialized symbol 'hwq'.
drivers/ufs/core/ufs-mcq.c:315 ufshcd_mcq_config_resource() warn: passing zero to 'PTR_ERR'
drivers/ufs/core/ufs-mcq.c:334 ufshcd_mcq_config_resource() error: potentially dereferencing uninitialized 'res_mem'.
drivers/ufs/core/ufs-mcq.c:330 ufshcd_mcq_config_resource() warn: missing error code 'ret'

Old smatch warnings:
drivers/ufs/core/ufshcd.c:5360 ufshcd_uic_cmd_compl() error: we previously assumed 'hba->active_uic_cmd' could be null (see line 5348)

vim +/hwq +2887 drivers/ufs/core/ufshcd.c

7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2792 static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2793 {
4728ab4a8e6490 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-07-21 2794 struct ufs_hba *hba = shost_priv(host);
3f2c1002e0fcb6 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-08-09 2795 int tag = scsi_cmd_to_rq(cmd)->tag;
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2796 struct ufshcd_lrb *lrbp;
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2797 int err = 0;
2b7356bcd24efd drivers/ufs/core/ufshcd.c Asutosh Das 2022-07-19 2798 struct ufs_hw_queue *hwq;
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2799
eaab9b57305496 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-12-03 2800 WARN_ONCE(tag < 0 || tag >= hba->nutrs, "Invalid tag %d\n", tag);
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2801
5675c381ea5136 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-12-03 2802 /*
5675c381ea5136 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-12-03 2803 * Allows the UFS error handler to wait for prior ufshcd_queuecommand()
5675c381ea5136 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-12-03 2804 * calls.
5675c381ea5136 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-12-03 2805 */
5675c381ea5136 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-12-03 2806 rcu_read_lock();
5675c381ea5136 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-12-03 2807
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2808 switch (hba->ufshcd_state) {
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2809 case UFSHCD_STATE_OPERATIONAL:
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2810 break;
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2811 case UFSHCD_STATE_EH_SCHEDULED_NON_FATAL:
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2812 /*
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2813 * SCSI error handler can call ->queuecommand() while UFS error
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2814 * handler is in progress. Error interrupts could change the
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2815 * state from UFSHCD_STATE_RESET to
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2816 * UFSHCD_STATE_EH_SCHEDULED_NON_FATAL. Prevent requests
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2817 * being issued in that case.
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2818 */
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2819 if (ufshcd_eh_in_progress(hba)) {
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2820 err = SCSI_MLQUEUE_HOST_BUSY;
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2821 goto out;
d489f18ad1fc33 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-10-08 2822 }
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2823 break;
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2824 case UFSHCD_STATE_EH_SCHEDULED_FATAL:
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2825 /*
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2826 * pm_runtime_get_sync() is used at error handling preparation
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2827 * stage. If a scsi cmd, e.g. the SSU cmd, is sent from hba's
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2828 * PM ops, it can never be finished if we let SCSI layer keep
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2829 * retrying it, which gets err handler stuck forever. Neither
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2830 * can we let the scsi cmd pass through, because UFS is in bad
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2831 * state, the scsi cmd may eventually time out, which will get
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2832 * err handler blocked for too long. So, just fail the scsi cmd
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2833 * sent from PM ops, err handler can recover PM error anyways.
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2834 */
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2835 if (hba->pm_op_in_progress) {
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2836 hba->force_reset = true;
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2837 set_host_byte(cmd, DID_BAD_TARGET);
35c3730a965722 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-10-07 2838 scsi_done(cmd);
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2839 goto out;
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2840 }
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2841 fallthrough;
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2842 case UFSHCD_STATE_RESET:
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2843 err = SCSI_MLQUEUE_HOST_BUSY;
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2844 goto out;
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2845 case UFSHCD_STATE_ERROR:
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2846 set_host_byte(cmd, DID_ERROR);
35c3730a965722 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-10-07 2847 scsi_done(cmd);
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2848 goto out;
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2849 }
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2850
7fabb77b3aa016 drivers/scsi/ufs/ufshcd.c Gilad Broner 2017-02-03 2851 hba->req_abort_count = 0;
7fabb77b3aa016 drivers/scsi/ufs/ufshcd.c Gilad Broner 2017-02-03 2852
1ab27c9cf8b63d drivers/scsi/ufs/ufshcd.c Sahitya Tummala 2014-09-25 2853 err = ufshcd_hold(hba, true);
1ab27c9cf8b63d drivers/scsi/ufs/ufshcd.c Sahitya Tummala 2014-09-25 2854 if (err) {
1ab27c9cf8b63d drivers/scsi/ufs/ufshcd.c Sahitya Tummala 2014-09-25 2855 err = SCSI_MLQUEUE_HOST_BUSY;
1ab27c9cf8b63d drivers/scsi/ufs/ufshcd.c Sahitya Tummala 2014-09-25 2856 goto out;
1ab27c9cf8b63d drivers/scsi/ufs/ufshcd.c Sahitya Tummala 2014-09-25 2857 }
2dec9475a4028b drivers/scsi/ufs/ufshcd.c Can Guo 2020-08-09 2858 WARN_ON(ufshcd_is_clkgating_allowed(hba) &&
2dec9475a4028b drivers/scsi/ufs/ufshcd.c Can Guo 2020-08-09 2859 (hba->clk_gating.state != CLKS_ON));
1ab27c9cf8b63d drivers/scsi/ufs/ufshcd.c Sahitya Tummala 2014-09-25 2860
2b7356bcd24efd drivers/ufs/core/ufshcd.c Asutosh Das 2022-07-19 2861 if (is_mcq_enabled(hba))
2b7356bcd24efd drivers/ufs/core/ufshcd.c Asutosh Das 2022-07-19 2862 lrbp = ufshcd_mcq_find_lrb(hba, scsi_cmd_to_rq(cmd), &hwq);
2b7356bcd24efd drivers/ufs/core/ufshcd.c Asutosh Das 2022-07-19 2863 else
a45f937110fa6b drivers/scsi/ufs/ufshcd.c Can Guo 2021-05-24 2864 lrbp = &hba->lrb[tag];

hwq not initialized on else path

2b7356bcd24efd drivers/ufs/core/ufshcd.c Asutosh Das 2022-07-19 2865
5a0b0cb9bee767 drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30 2866 WARN_ON(lrbp->cmd);
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2867 lrbp->cmd = cmd;
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2868 lrbp->task_tag = tag;
0ce147d48a3e33 drivers/scsi/ufs/ufshcd.c Subhash Jadavani 2014-09-25 2869 lrbp->lun = ufshcd_scsi_to_upiu_lun(cmd->device->lun);
51d1628fc45727 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2022-04-19 2870 lrbp->intr_cmd = !ufshcd_is_intr_aggr_allowed(hba);
df043c745ea149 drivers/scsi/ufs/ufshcd.c Satya Tangirala 2020-07-06 2871
3f2c1002e0fcb6 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-08-09 2872 ufshcd_prepare_lrbp_crypto(scsi_cmd_to_rq(cmd), lrbp);
df043c745ea149 drivers/scsi/ufs/ufshcd.c Satya Tangirala 2020-07-06 2873
e0b299e36004f5 drivers/scsi/ufs/ufshcd.c Gilad Broner 2017-02-03 2874 lrbp->req_abort_skip = false;
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2875
09d9e4d0418766 drivers/scsi/ufs/ufshcd.c Avri Altman 2021-10-30 2876 ufshpb_prep(hba, lrbp);
2fff76f87542fa drivers/scsi/ufs/ufshcd.c Daejun Park 2021-07-12 2877
300bb13f5c7b1d drivers/scsi/ufs/ufshcd.c Joao Pinto 2016-05-11 2878 ufshcd_comp_scsi_upiu(hba, lrbp);
300bb13f5c7b1d drivers/scsi/ufs/ufshcd.c Joao Pinto 2016-05-11 2879
75b1cc4ad63afa drivers/scsi/ufs/ufshcd.c Kiwoong Kim 2016-11-22 2880 err = ufshcd_map_sg(hba, lrbp);
5a0b0cb9bee767 drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30 2881 if (err) {
5a0b0cb9bee767 drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30 2882 lrbp->cmd = NULL;
17c7d35f141ef6 drivers/scsi/ufs/ufshcd.c Can Guo 2019-12-05 2883 ufshcd_release(hba);
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2884 goto out;
5a0b0cb9bee767 drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma 2013-07-30 2885 }
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2886
2b7356bcd24efd drivers/ufs/core/ufshcd.c Asutosh Das 2022-07-19 @2887 ufshcd_send_command(hba, lrbp, hwq);
^^^
Sent

7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2888 out:
5675c381ea5136 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-12-03 2889 rcu_read_unlock();
5675c381ea5136 drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-12-03 2890
88b099006d83b0 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-09-17 2891 if (ufs_trigger_eh()) {
88b099006d83b0 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-09-17 2892 unsigned long flags;
88b099006d83b0 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-09-17 2893
88b099006d83b0 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-09-17 2894 spin_lock_irqsave(hba->host->host_lock, flags);
88b099006d83b0 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-09-17 2895 ufshcd_schedule_eh_work(hba);
88b099006d83b0 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-09-17 2896 spin_unlock_irqrestore(hba->host->host_lock, flags);
88b099006d83b0 drivers/scsi/ufs/ufshcd.c Adrian Hunter 2021-09-17 2897 }
c11a1ae9b8f65e drivers/scsi/ufs/ufshcd.c Bart Van Assche 2021-07-21 2898
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2899 return err;
7a3e97b0dc4bba drivers/scsi/ufs/ufshcd.c Santosh Yaraganavi 2012-02-29 2900 }

--
0-DAY CI Kernel Test Service