All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: Fix a possible use before initialization case
@ 2021-06-09  3:36 Can Guo
  2021-06-09  6:29 ` Stanley Chu
  2021-06-09  8:16   ` kernel test robot
  0 siblings, 2 replies; 5+ messages in thread
From: Can Guo @ 2021-06-09  3:36 UTC (permalink / raw)
  To: asutoshd, nguyenb, hongwus, ziqichen, linux-scsi, kernel-team, cang
  Cc: Can Guo, Alim Akhtar, Avri Altman, James E.J. Bottomley,
	Martin K. Petersen, Stanley Chu, Bean Huo, Jaegeuk Kim,
	open list

In ufshcd_exec_dev_cmd(), if error happens before lrpb is initialized,
then we should bail out instead of letting trace record the error.

Fixes: a45f937110fa6 ("scsi: ufs: Optimize host lock on transfer requests send/compl paths")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Can Guo <cang@qti.qualcomm.com>

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index fe1b5f4..0d54ab7 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -2972,7 +2972,7 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,
 
 	if (unlikely(test_bit(tag, &hba->outstanding_reqs))) {
 		err = -EBUSY;
-		goto out;
+		goto out_put_tag;
 	}
 
 	init_completion(&wait);
-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: Fix a possible use before initialization case
  2021-06-09  3:36 [PATCH] scsi: ufs: Fix a possible use before initialization case Can Guo
@ 2021-06-09  6:29 ` Stanley Chu
  2021-06-09  8:16   ` kernel test robot
  1 sibling, 0 replies; 5+ messages in thread
From: Stanley Chu @ 2021-06-09  6:29 UTC (permalink / raw)
  To: Can Guo
  Cc: asutoshd, nguyenb, hongwus, ziqichen, linux-scsi, kernel-team,
	cang, Alim Akhtar, Avri Altman, James E.J. Bottomley,
	Martin K. Petersen, Bean Huo, Jaegeuk Kim, open list

On Tue, 2021-06-08 at 20:36 -0700, Can Guo wrote:
> In ufshcd_exec_dev_cmd(), if error happens before lrpb is initialized,
> then we should bail out instead of letting trace record the error.
> 
> Fixes: a45f937110fa6 ("scsi: ufs: Optimize host lock on transfer requests send/compl paths")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Can Guo <cang@qti.qualcomm.com>
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index fe1b5f4..0d54ab7 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -2972,7 +2972,7 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,
>  
>  	if (unlikely(test_bit(tag, &hba->outstanding_reqs))) {
>  		err = -EBUSY;
> -		goto out;
> +		goto out_put_tag;
>  	}
>  
>  	init_completion(&wait);

Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: Fix a possible use before initialization case
  2021-06-09  3:36 [PATCH] scsi: ufs: Fix a possible use before initialization case Can Guo
@ 2021-06-09  8:16   ` kernel test robot
  2021-06-09  8:16   ` kernel test robot
  1 sibling, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-06-09  8:16 UTC (permalink / raw)
  To: Can Guo, asutoshd, nguyenb, hongwus, ziqichen, linux-scsi,
	kernel-team, cang
  Cc: kbuild-all, clang-built-linux, Can Guo, Alim Akhtar, Avri Altman

[-- Attachment #1: Type: text/plain, Size: 7067 bytes --]

Hi Can,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on scsi/for-next v5.13-rc5 next-20210608]
[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]

url:    https://github.com/0day-ci/linux/commits/Can-Guo/scsi-ufs-Fix-a-possible-use-before-initialization-case/20210609-113857
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: x86_64-randconfig-a012-20210608 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project d2012d965d60c3258b3a69d024491698f8aec386)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/d566879446f64c07b54dfc7ade9d8ef80bf4687a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Can-Guo/scsi-ufs-Fix-a-possible-use-before-initialization-case/20210609-113857
        git checkout d566879446f64c07b54dfc7ade9d8ef80bf4687a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/scsi/ufs/ufshcd.c:2993:1: warning: unused label 'out' [-Wunused-label]
   out:
   ^~~~
   1 warning generated.


vim +/out +2993 drivers/scsi/ufs/ufshcd.c

5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2938  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2939  /**
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2940   * ufshcd_exec_dev_cmd - API for sending device management requests
8aa29f192ca675 Bart Van Assche    2018-03-01  2941   * @hba: UFS hba
8aa29f192ca675 Bart Van Assche    2018-03-01  2942   * @cmd_type: specifies the type (NOP, Query...)
8aa29f192ca675 Bart Van Assche    2018-03-01  2943   * @timeout: time in seconds
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2944   *
68078d5cc1a59b Dolev Raviv        2013-07-30  2945   * NOTE: Since there is only one available tag for device management commands,
68078d5cc1a59b Dolev Raviv        2013-07-30  2946   * it is expected you hold the hba->dev_cmd.lock mutex.
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2947   */
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2948  static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2949  		enum dev_cmd_type cmd_type, int timeout)
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2950  {
7252a3603015f1 Bart Van Assche    2019-12-09  2951  	struct request_queue *q = hba->cmd_queue;
7252a3603015f1 Bart Van Assche    2019-12-09  2952  	struct request *req;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2953  	struct ufshcd_lrb *lrbp;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2954  	int err;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2955  	int tag;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2956  	struct completion wait;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2957  
a3cd5ec55f6c72 Subhash Jadavani   2017-02-03  2958  	down_read(&hba->clk_scaling_lock);
a3cd5ec55f6c72 Subhash Jadavani   2017-02-03  2959  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2960  	/*
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2961  	 * Get free slot, sleep if slots are unavailable.
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2962  	 * Even though we use wait_event() which sleeps indefinitely,
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2963  	 * the maximum wait time is bounded by SCSI request timeout.
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2964  	 */
7252a3603015f1 Bart Van Assche    2019-12-09  2965  	req = blk_get_request(q, REQ_OP_DRV_OUT, 0);
bb14dd1564c90d Dan Carpenter      2019-12-13  2966  	if (IS_ERR(req)) {
bb14dd1564c90d Dan Carpenter      2019-12-13  2967  		err = PTR_ERR(req);
bb14dd1564c90d Dan Carpenter      2019-12-13  2968  		goto out_unlock;
bb14dd1564c90d Dan Carpenter      2019-12-13  2969  	}
7252a3603015f1 Bart Van Assche    2019-12-09  2970  	tag = req->tag;
7252a3603015f1 Bart Van Assche    2019-12-09  2971  	WARN_ON_ONCE(!ufshcd_valid_tag(hba, tag));
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2972  
a45f937110fa6b Can Guo            2021-05-24  2973  	if (unlikely(test_bit(tag, &hba->outstanding_reqs))) {
7a7e66c65d4148 Can Guo            2020-12-02  2974  		err = -EBUSY;
d566879446f64c Can Guo            2021-06-08  2975  		goto out_put_tag;
7a7e66c65d4148 Can Guo            2020-12-02  2976  	}
7a7e66c65d4148 Can Guo            2020-12-02  2977  
a45f937110fa6b Can Guo            2021-05-24  2978  	init_completion(&wait);
a45f937110fa6b Can Guo            2021-05-24  2979  	lrbp = &hba->lrb[tag];
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2980  	WARN_ON(lrbp->cmd);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2981  	err = ufshcd_compose_dev_cmd(hba, lrbp, cmd_type, tag);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2982  	if (unlikely(err))
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2983  		goto out_put_tag;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2984  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2985  	hba->dev_cmd.complete = &wait;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2986  
fb475b74d6630e Avri Altman        2021-01-10  2987  	ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr);
e3dfdc532d5c68 Yaniv Gardi        2016-02-01  2988  	/* Make sure descriptors are ready before ringing the doorbell */
e3dfdc532d5c68 Yaniv Gardi        2016-02-01  2989  	wmb();
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2990  
a45f937110fa6b Can Guo            2021-05-24  2991  	ufshcd_send_command(hba, tag);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2992  	err = ufshcd_wait_for_dev_cmd(hba, lrbp, timeout);
7a7e66c65d4148 Can Guo            2020-12-02 @2993  out:
fb475b74d6630e Avri Altman        2021-01-10  2994  	ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP,
fb475b74d6630e Avri Altman        2021-01-10  2995  				    (struct utp_upiu_req *)lrbp->ucd_rsp_ptr);
6667e6d91c88a7 Ohad Sharabi       2018-03-28  2996  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2997  out_put_tag:
7252a3603015f1 Bart Van Assche    2019-12-09  2998  	blk_put_request(req);
bb14dd1564c90d Dan Carpenter      2019-12-13  2999  out_unlock:
a3cd5ec55f6c72 Subhash Jadavani   2017-02-03  3000  	up_read(&hba->clk_scaling_lock);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  3001  	return err;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  3002  }
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  3003  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 44723 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: Fix a possible use before initialization case
@ 2021-06-09  8:16   ` kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-06-09  8:16 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 7178 bytes --]

Hi Can,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on scsi/for-next v5.13-rc5 next-20210608]
[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]

url:    https://github.com/0day-ci/linux/commits/Can-Guo/scsi-ufs-Fix-a-possible-use-before-initialization-case/20210609-113857
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: x86_64-randconfig-a012-20210608 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project d2012d965d60c3258b3a69d024491698f8aec386)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/d566879446f64c07b54dfc7ade9d8ef80bf4687a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Can-Guo/scsi-ufs-Fix-a-possible-use-before-initialization-case/20210609-113857
        git checkout d566879446f64c07b54dfc7ade9d8ef80bf4687a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/scsi/ufs/ufshcd.c:2993:1: warning: unused label 'out' [-Wunused-label]
   out:
   ^~~~
   1 warning generated.


vim +/out +2993 drivers/scsi/ufs/ufshcd.c

5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2938  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2939  /**
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2940   * ufshcd_exec_dev_cmd - API for sending device management requests
8aa29f192ca675 Bart Van Assche    2018-03-01  2941   * @hba: UFS hba
8aa29f192ca675 Bart Van Assche    2018-03-01  2942   * @cmd_type: specifies the type (NOP, Query...)
8aa29f192ca675 Bart Van Assche    2018-03-01  2943   * @timeout: time in seconds
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2944   *
68078d5cc1a59b Dolev Raviv        2013-07-30  2945   * NOTE: Since there is only one available tag for device management commands,
68078d5cc1a59b Dolev Raviv        2013-07-30  2946   * it is expected you hold the hba->dev_cmd.lock mutex.
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2947   */
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2948  static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2949  		enum dev_cmd_type cmd_type, int timeout)
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2950  {
7252a3603015f1 Bart Van Assche    2019-12-09  2951  	struct request_queue *q = hba->cmd_queue;
7252a3603015f1 Bart Van Assche    2019-12-09  2952  	struct request *req;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2953  	struct ufshcd_lrb *lrbp;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2954  	int err;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2955  	int tag;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2956  	struct completion wait;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2957  
a3cd5ec55f6c72 Subhash Jadavani   2017-02-03  2958  	down_read(&hba->clk_scaling_lock);
a3cd5ec55f6c72 Subhash Jadavani   2017-02-03  2959  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2960  	/*
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2961  	 * Get free slot, sleep if slots are unavailable.
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2962  	 * Even though we use wait_event() which sleeps indefinitely,
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2963  	 * the maximum wait time is bounded by SCSI request timeout.
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2964  	 */
7252a3603015f1 Bart Van Assche    2019-12-09  2965  	req = blk_get_request(q, REQ_OP_DRV_OUT, 0);
bb14dd1564c90d Dan Carpenter      2019-12-13  2966  	if (IS_ERR(req)) {
bb14dd1564c90d Dan Carpenter      2019-12-13  2967  		err = PTR_ERR(req);
bb14dd1564c90d Dan Carpenter      2019-12-13  2968  		goto out_unlock;
bb14dd1564c90d Dan Carpenter      2019-12-13  2969  	}
7252a3603015f1 Bart Van Assche    2019-12-09  2970  	tag = req->tag;
7252a3603015f1 Bart Van Assche    2019-12-09  2971  	WARN_ON_ONCE(!ufshcd_valid_tag(hba, tag));
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2972  
a45f937110fa6b Can Guo            2021-05-24  2973  	if (unlikely(test_bit(tag, &hba->outstanding_reqs))) {
7a7e66c65d4148 Can Guo            2020-12-02  2974  		err = -EBUSY;
d566879446f64c Can Guo            2021-06-08  2975  		goto out_put_tag;
7a7e66c65d4148 Can Guo            2020-12-02  2976  	}
7a7e66c65d4148 Can Guo            2020-12-02  2977  
a45f937110fa6b Can Guo            2021-05-24  2978  	init_completion(&wait);
a45f937110fa6b Can Guo            2021-05-24  2979  	lrbp = &hba->lrb[tag];
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2980  	WARN_ON(lrbp->cmd);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2981  	err = ufshcd_compose_dev_cmd(hba, lrbp, cmd_type, tag);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2982  	if (unlikely(err))
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2983  		goto out_put_tag;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2984  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2985  	hba->dev_cmd.complete = &wait;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2986  
fb475b74d6630e Avri Altman        2021-01-10  2987  	ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr);
e3dfdc532d5c68 Yaniv Gardi        2016-02-01  2988  	/* Make sure descriptors are ready before ringing the doorbell */
e3dfdc532d5c68 Yaniv Gardi        2016-02-01  2989  	wmb();
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2990  
a45f937110fa6b Can Guo            2021-05-24  2991  	ufshcd_send_command(hba, tag);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2992  	err = ufshcd_wait_for_dev_cmd(hba, lrbp, timeout);
7a7e66c65d4148 Can Guo            2020-12-02 @2993  out:
fb475b74d6630e Avri Altman        2021-01-10  2994  	ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP,
fb475b74d6630e Avri Altman        2021-01-10  2995  				    (struct utp_upiu_req *)lrbp->ucd_rsp_ptr);
6667e6d91c88a7 Ohad Sharabi       2018-03-28  2996  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2997  out_put_tag:
7252a3603015f1 Bart Van Assche    2019-12-09  2998  	blk_put_request(req);
bb14dd1564c90d Dan Carpenter      2019-12-13  2999  out_unlock:
a3cd5ec55f6c72 Subhash Jadavani   2017-02-03  3000  	up_read(&hba->clk_scaling_lock);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  3001  	return err;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  3002  }
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  3003  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 44723 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: Fix a possible use before initialization case
@ 2021-06-09  7:19 kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-06-09  7:19 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 7473 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <1623209820-37840-1-git-send-email-cang@qti.qualcomm.com>
References: <1623209820-37840-1-git-send-email-cang@qti.qualcomm.com>
TO: Can Guo <cang@qti.qualcomm.com>
TO: asutoshd(a)codeaurora.org
TO: nguyenb(a)codeaurora.org
TO: hongwus(a)codeaurora.org
TO: ziqichen(a)codeaurora.org
TO: linux-scsi(a)vger.kernel.org
TO: kernel-team(a)android.com
TO: cang(a)codeaurora.org
CC: Can Guo <cang@qti.qualcomm.com>
CC: Alim Akhtar <alim.akhtar@samsung.com>
CC: Avri Altman <avri.altman@wdc.com>

Hi Can,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on scsi/for-next v5.13-rc5 next-20210608]
[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]

url:    https://github.com/0day-ci/linux/commits/Can-Guo/scsi-ufs-Fix-a-possible-use-before-initialization-case/20210609-113857
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
:::::: branch date: 4 hours ago
:::::: commit date: 4 hours ago
config: i386-randconfig-s001-20210608 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/d566879446f64c07b54dfc7ade9d8ef80bf4687a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Can-Guo/scsi-ufs-Fix-a-possible-use-before-initialization-case/20210609-113857
        git checkout d566879446f64c07b54dfc7ade9d8ef80bf4687a
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
>> drivers/scsi/ufs/ufshcd.c:2993:1: sparse: sparse: unused label 'out'

vim +/out +2993 drivers/scsi/ufs/ufshcd.c

5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2938  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2939  /**
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2940   * ufshcd_exec_dev_cmd - API for sending device management requests
8aa29f192ca675 Bart Van Assche    2018-03-01  2941   * @hba: UFS hba
8aa29f192ca675 Bart Van Assche    2018-03-01  2942   * @cmd_type: specifies the type (NOP, Query...)
8aa29f192ca675 Bart Van Assche    2018-03-01  2943   * @timeout: time in seconds
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2944   *
68078d5cc1a59b Dolev Raviv        2013-07-30  2945   * NOTE: Since there is only one available tag for device management commands,
68078d5cc1a59b Dolev Raviv        2013-07-30  2946   * it is expected you hold the hba->dev_cmd.lock mutex.
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2947   */
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2948  static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2949  		enum dev_cmd_type cmd_type, int timeout)
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2950  {
7252a3603015f1 Bart Van Assche    2019-12-09  2951  	struct request_queue *q = hba->cmd_queue;
7252a3603015f1 Bart Van Assche    2019-12-09  2952  	struct request *req;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2953  	struct ufshcd_lrb *lrbp;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2954  	int err;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2955  	int tag;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2956  	struct completion wait;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2957  
a3cd5ec55f6c72 Subhash Jadavani   2017-02-03  2958  	down_read(&hba->clk_scaling_lock);
a3cd5ec55f6c72 Subhash Jadavani   2017-02-03  2959  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2960  	/*
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2961  	 * Get free slot, sleep if slots are unavailable.
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2962  	 * Even though we use wait_event() which sleeps indefinitely,
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2963  	 * the maximum wait time is bounded by SCSI request timeout.
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2964  	 */
7252a3603015f1 Bart Van Assche    2019-12-09  2965  	req = blk_get_request(q, REQ_OP_DRV_OUT, 0);
bb14dd1564c90d Dan Carpenter      2019-12-13  2966  	if (IS_ERR(req)) {
bb14dd1564c90d Dan Carpenter      2019-12-13  2967  		err = PTR_ERR(req);
bb14dd1564c90d Dan Carpenter      2019-12-13  2968  		goto out_unlock;
bb14dd1564c90d Dan Carpenter      2019-12-13  2969  	}
7252a3603015f1 Bart Van Assche    2019-12-09  2970  	tag = req->tag;
7252a3603015f1 Bart Van Assche    2019-12-09  2971  	WARN_ON_ONCE(!ufshcd_valid_tag(hba, tag));
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2972  
a45f937110fa6b Can Guo            2021-05-24  2973  	if (unlikely(test_bit(tag, &hba->outstanding_reqs))) {
7a7e66c65d4148 Can Guo            2020-12-02  2974  		err = -EBUSY;
d566879446f64c Can Guo            2021-06-08  2975  		goto out_put_tag;
7a7e66c65d4148 Can Guo            2020-12-02  2976  	}
7a7e66c65d4148 Can Guo            2020-12-02  2977  
a45f937110fa6b Can Guo            2021-05-24  2978  	init_completion(&wait);
a45f937110fa6b Can Guo            2021-05-24  2979  	lrbp = &hba->lrb[tag];
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2980  	WARN_ON(lrbp->cmd);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2981  	err = ufshcd_compose_dev_cmd(hba, lrbp, cmd_type, tag);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2982  	if (unlikely(err))
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2983  		goto out_put_tag;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2984  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2985  	hba->dev_cmd.complete = &wait;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2986  
fb475b74d6630e Avri Altman        2021-01-10  2987  	ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr);
e3dfdc532d5c68 Yaniv Gardi        2016-02-01  2988  	/* Make sure descriptors are ready before ringing the doorbell */
e3dfdc532d5c68 Yaniv Gardi        2016-02-01  2989  	wmb();
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2990  
a45f937110fa6b Can Guo            2021-05-24  2991  	ufshcd_send_command(hba, tag);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2992  	err = ufshcd_wait_for_dev_cmd(hba, lrbp, timeout);
7a7e66c65d4148 Can Guo            2020-12-02 @2993  out:
fb475b74d6630e Avri Altman        2021-01-10  2994  	ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP,
fb475b74d6630e Avri Altman        2021-01-10  2995  				    (struct utp_upiu_req *)lrbp->ucd_rsp_ptr);
6667e6d91c88a7 Ohad Sharabi       2018-03-28  2996  
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  2997  out_put_tag:
7252a3603015f1 Bart Van Assche    2019-12-09  2998  	blk_put_request(req);
bb14dd1564c90d Dan Carpenter      2019-12-13  2999  out_unlock:
a3cd5ec55f6c72 Subhash Jadavani   2017-02-03  3000  	up_read(&hba->clk_scaling_lock);
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  3001  	return err;
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  3002  }
5a0b0cb9bee767 Sujit Reddy Thumma 2013-07-30  3003  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 37620 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-09  8:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09  3:36 [PATCH] scsi: ufs: Fix a possible use before initialization case Can Guo
2021-06-09  6:29 ` Stanley Chu
2021-06-09  8:16 ` kernel test robot
2021-06-09  8:16   ` kernel test robot
2021-06-09  7:19 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.