diff mbox series

[5/9] ufs: core: Move the ufshcd_device_init() call

Message ID 20240819225102.2437307-6-bvanassche@acm.org
State Superseded
Headers show
Series Simplify the UFS driver initialization code | expand

Commit Message

Bart Van Assche Aug. 19, 2024, 10:50 p.m. UTC
Move the ufshcd_device_init() call to the ufshcd_probe_hba() callers and
remove the 'init_dev_params' argument of ufshcd_probe_hba().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/ufs/core/ufshcd.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

Comments

kernel test robot Aug. 22, 2024, 4:07 p.m. UTC | #1
Hi Bart,

kernel test robot noticed the following build warnings:

[auto build test WARNING on mkp-scsi/for-next]
[cannot apply to jejb-scsi/for-next linus/master v6.11-rc4 next-20240822]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Bart-Van-Assche/ufs-core-Introduce-ufshcd_add_scsi_host/20240820-065414
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
patch link:    https://lore.kernel.org/r/20240819225102.2437307-6-bvanassche%40acm.org
patch subject: [PATCH 5/9] ufs: core: Move the ufshcd_device_init() call
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20240822/202408222305.wOhpxPXn-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240822/202408222305.wOhpxPXn-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408222305.wOhpxPXn-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/ufs/core/ufshcd.c:8871:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    8871 |         if (!hba->pm_op_in_progress &&
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~
    8872 |             (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
         |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/ufs/core/ufshcd.c:8911:6: note: uninitialized use occurs here
    8911 |         if (ret)
         |             ^~~
   drivers/ufs/core/ufshcd.c:8871:2: note: remove the 'if' if its condition is always true
    8871 |         if (!hba->pm_op_in_progress &&
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    8872 |             (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
         |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/ufs/core/ufshcd.c:8871:6: warning: variable 'ret' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized]
    8871 |         if (!hba->pm_op_in_progress &&
         |             ^~~~~~~~~~~~~~~~~~~~~~~
   drivers/ufs/core/ufshcd.c:8911:6: note: uninitialized use occurs here
    8911 |         if (ret)
         |             ^~~
   drivers/ufs/core/ufshcd.c:8871:6: note: remove the '&&' if its condition is always true
    8871 |         if (!hba->pm_op_in_progress &&
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/ufs/core/ufshcd.c:8869:9: note: initialize the variable 'ret' to silence this warning
    8869 |         int ret;
         |                ^
         |                 = 0
   2 warnings generated.


vim +8871 drivers/ufs/core/ufshcd.c

96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8856  
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8857  /**
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8858   * ufshcd_probe_hba - probe hba to detect device and initialize it
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8859   * @hba: per-adapter instance
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8860   *
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8861   * Execute link-startup and verify device initialization
fd4bffb54dc0f6 drivers/ufs/core/ufshcd.c Bart Van Assche       2023-07-27  8862   *
fd4bffb54dc0f6 drivers/ufs/core/ufshcd.c Bart Van Assche       2023-07-27  8863   * Return: 0 upon success; < 0 upon failure.
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8864   */
56161bc6c24d06 drivers/ufs/core/ufshcd.c Bart Van Assche       2024-08-19  8865  static int ufshcd_probe_hba(struct ufs_hba *hba)
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8866  {
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8867  	ktime_t start = ktime_get();
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8868  	unsigned long flags;
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8869  	int ret;
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8870  
fc88ca19ad0989 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2023-09-08 @8871  	if (!hba->pm_op_in_progress &&
fc88ca19ad0989 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2023-09-08  8872  	    (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8873  		/* Reset the device and controller before doing reinit */
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8874  		ufshcd_device_reset(hba);
135c6eb27a85c8 drivers/ufs/core/ufshcd.c Joel Slebodnick       2024-06-13  8875  		ufs_put_device_desc(hba);
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8876  		ufshcd_hba_stop(hba);
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8877  		ufshcd_vops_reinit_notify(hba);
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8878  		ret = ufshcd_hba_enable(hba);
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8879  		if (ret) {
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8880  			dev_err(hba->dev, "Host controller enable failed\n");
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8881  			ufshcd_print_evt_hist(hba);
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8882  			ufshcd_print_host_state(hba);
8643ae66ce749f drivers/scsi/ufs/ufshcd.c Dov Levenglick        2016-10-17  8883  			goto out;
8643ae66ce749f drivers/scsi/ufs/ufshcd.c Dov Levenglick        2016-10-17  8884  		}
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8885  
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8886  		/* Reinit the device */
56161bc6c24d06 drivers/ufs/core/ufshcd.c Bart Van Assche       2024-08-19  8887  		ret = ufshcd_device_init(hba, /*init_dev_params=*/false);
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8888  		if (ret)
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8889  			goto out;
7eb584db73bebb drivers/scsi/ufs/ufshcd.c Dolev Raviv           2014-09-25  8890  	}
57d104c153d3d6 drivers/scsi/ufs/ufshcd.c Subhash Jadavani      2014-09-25  8891  
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8892  	ufshcd_print_pwr_info(hba);
96a7141da33207 drivers/ufs/core/ufshcd.c Manivannan Sadhasivam 2022-12-22  8893  
e89860f196fca3 drivers/scsi/ufs/ufshcd.c Can Guo               2020-03-26  8894  	/*
e89860f196fca3 drivers/scsi/ufs/ufshcd.c Can Guo               2020-03-26  8895  	 * bActiveICCLevel is volatile for UFS device (as per latest v2.1 spec)
e89860f196fca3 drivers/scsi/ufs/ufshcd.c Can Guo               2020-03-26  8896  	 * and for removable UFS card as well, hence always set the parameter.
e89860f196fca3 drivers/scsi/ufs/ufshcd.c Can Guo               2020-03-26  8897  	 * Note: Error handler may issue the device reset hence resetting
e89860f196fca3 drivers/scsi/ufs/ufshcd.c Can Guo               2020-03-26  8898  	 * bActiveICCLevel as well so it is always safe to set this here.
e89860f196fca3 drivers/scsi/ufs/ufshcd.c Can Guo               2020-03-26  8899  	 */
e89860f196fca3 drivers/scsi/ufs/ufshcd.c Can Guo               2020-03-26  8900  	ufshcd_set_active_icc_lvl(hba);
e89860f196fca3 drivers/scsi/ufs/ufshcd.c Can Guo               2020-03-26  8901  
4450a1653a935d drivers/ufs/core/ufshcd.c Jinyoung Choi         2022-08-04  8902  	/* Enable UFS Write Booster if supported */
4450a1653a935d drivers/ufs/core/ufshcd.c Jinyoung Choi         2022-08-04  8903  	ufshcd_configure_wb(hba);
4450a1653a935d drivers/ufs/core/ufshcd.c Jinyoung Choi         2022-08-04  8904  
cd4694756188dc drivers/scsi/ufs/ufshcd.c Adrian Hunter         2021-02-09  8905  	if (hba->ee_usr_mask)
cd4694756188dc drivers/scsi/ufs/ufshcd.c Adrian Hunter         2021-02-09  8906  		ufshcd_write_ee_control(hba);
bdf5c0bb4dd9e7 drivers/ufs/core/ufshcd.c Bart Van Assche       2023-12-14  8907  	ufshcd_configure_auto_hibern8(hba);
71d848b8d97ec0 drivers/scsi/ufs/ufshcd.c Can Guo               2019-11-14  8908  
5a0b0cb9bee767 drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma    2013-07-30  8909  out:
4db7a23605973a drivers/scsi/ufs/ufshcd.c Can Guo               2020-08-09  8910  	spin_lock_irqsave(hba->host->host_lock, flags);
4db7a23605973a drivers/scsi/ufs/ufshcd.c Can Guo               2020-08-09  8911  	if (ret)
4db7a23605973a drivers/scsi/ufs/ufshcd.c Can Guo               2020-08-09  8912  		hba->ufshcd_state = UFSHCD_STATE_ERROR;
4db7a23605973a drivers/scsi/ufs/ufshcd.c Can Guo               2020-08-09  8913  	else if (hba->ufshcd_state == UFSHCD_STATE_RESET)
4db7a23605973a drivers/scsi/ufs/ufshcd.c Can Guo               2020-08-09  8914  		hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL;
4db7a23605973a drivers/scsi/ufs/ufshcd.c Can Guo               2020-08-09  8915  	spin_unlock_irqrestore(hba->host->host_lock, flags);
1d337ec2f35e69 drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma    2014-09-25  8916  
7ff5ab47363334 drivers/scsi/ufs/ufshcd.c Subhash Jadavani      2016-12-22  8917  	trace_ufshcd_init(dev_name(hba->dev), ret,
7ff5ab47363334 drivers/scsi/ufs/ufshcd.c Subhash Jadavani      2016-12-22  8918  		ktime_to_us(ktime_sub(ktime_get(), start)),
73eba2be9203c0 drivers/scsi/ufs/ufshcd.c Subhash Jadavani      2017-01-10  8919  		hba->curr_dev_pwr_mode, hba->uic_link_state);
1d337ec2f35e69 drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma    2014-09-25  8920  	return ret;
1d337ec2f35e69 drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma    2014-09-25  8921  }
1d337ec2f35e69 drivers/scsi/ufs/ufshcd.c Sujit Reddy Thumma    2014-09-25  8922
Bart Van Assche Aug. 22, 2024, 5:46 p.m. UTC | #2
On 8/22/24 9:07 AM, kernel test robot wrote:
>>> drivers/ufs/core/ufshcd.c:8871:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

I plan to fix this compiler warning by combining the following change
into patch 5/9:

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 9af293b39672..313b62509162 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -8832,7 +8832,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)
  {
         ktime_t start = ktime_get();
         unsigned long flags;
-       int ret;
+       int ret = 0;

         if (!hba->pm_op_in_progress &&
             (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {

Bart.
diff mbox series

Patch

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 502d0f5a95c0..86deea546b44 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -298,7 +298,8 @@  static int ufshcd_reset_and_restore(struct ufs_hba *hba);
 static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd);
 static int ufshcd_clear_tm_cmd(struct ufs_hba *hba, int tag);
 static void ufshcd_hba_exit(struct ufs_hba *hba);
-static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params);
+static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params);
+static int ufshcd_probe_hba(struct ufs_hba *hba);
 static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on);
 static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba);
 static int ufshcd_host_reset_and_restore(struct ufs_hba *hba);
@@ -7717,8 +7718,11 @@  static int ufshcd_host_reset_and_restore(struct ufs_hba *hba)
 	err = ufshcd_hba_enable(hba);
 
 	/* Establish the link again and restore the device */
-	if (!err)
-		err = ufshcd_probe_hba(hba, false);
+	if (!err) {
+		err = ufshcd_device_init(hba, /*init_dev_params=*/false);
+		if (!err)
+			err = ufshcd_probe_hba(hba);
+	}
 
 	if (err)
 		dev_err(hba->dev, "%s: Host init failed %d\n", __func__, err);
@@ -8853,22 +8857,17 @@  static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)
 /**
  * ufshcd_probe_hba - probe hba to detect device and initialize it
  * @hba: per-adapter instance
- * @init_dev_params: whether or not to call ufshcd_device_params_init().
  *
  * Execute link-startup and verify device initialization
  *
  * Return: 0 upon success; < 0 upon failure.
  */
-static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
+static int ufshcd_probe_hba(struct ufs_hba *hba)
 {
 	ktime_t start = ktime_get();
 	unsigned long flags;
 	int ret;
 
-	ret = ufshcd_device_init(hba, init_dev_params);
-	if (ret)
-		goto out;
-
 	if (!hba->pm_op_in_progress &&
 	    (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) {
 		/* Reset the device and controller before doing reinit */
@@ -8885,7 +8884,7 @@  static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params)
 		}
 
 		/* Reinit the device */
-		ret = ufshcd_device_init(hba, init_dev_params);
+		ret = ufshcd_device_init(hba, /*init_dev_params=*/false);
 		if (ret)
 			goto out;
 	}
@@ -8933,7 +8932,9 @@  static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 
 	down(&hba->host_sem);
 	/* Initialize hba, detect and initialize UFS device */
-	ret = ufshcd_probe_hba(hba, true);
+	ret = ufshcd_device_init(hba, /*init_dev_params=*/true);
+	if (ret == 0)
+		ret = ufshcd_probe_hba(hba);
 	up(&hba->host_sem);
 	if (ret)
 		goto out;