diff mbox series

[10/21] ufs: Remove ufshcd_valid_tag()

Message ID 20210701211224.17070-11-bvanassche@acm.org
State Superseded
Headers show
Series UFS patches for kernel v5.15 | expand

Commit Message

Bart Van Assche July 1, 2021, 9:12 p.m. UTC
scsi_add_host() allocates shost->can_queue tags. ufshcd_init() sets
shost->can_queue to hba->nutrs. In other words, we know that tag values
will be in the range [0, hba->nutrs). Hence remove the checks that
verify that blk_get_request() returns a tag in this range. This check
was introduced by commit 14497328b6a6 ("scsi: ufs: verify command tag
validity").

Cc: Alim Akhtar <alim.akhtar@samsung.com>
Cc: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/ufs/ufshcd.c | 40 ++++++---------------------------------
 1 file changed, 6 insertions(+), 34 deletions(-)

Comments

Avri Altman July 5, 2021, 6:46 a.m. UTC | #1
> 

> scsi_add_host() allocates shost->can_queue tags. ufshcd_init() sets

> shost->can_queue to hba->nutrs. In other words, we know that tag values

> will be in the range [0, hba->nutrs). Hence remove the checks that

> verify that blk_get_request() returns a tag in this range. This check

> was introduced by commit 14497328b6a6 ("scsi: ufs: verify command tag

> validity").

> 

> Cc: Alim Akhtar <alim.akhtar@samsung.com>

> Cc: Avri Altman <avri.altman@wdc.com>

> Signed-off-by: Bart Van Assche <bvanassche@acm.org>


>  static int ufshcd_abort(struct scsi_cmnd *cmd)

>  {

> -       struct Scsi_Host *host;

> -       struct ufs_hba *hba;

> +       struct Scsi_Host *host = cmd->device->host;

> +       struct ufs_hba *hba = shost_priv(host);

> +       unsigned int tag = cmd->request->tag;

> +       struct ufshcd_lrb *lrbp = &hba->lrb[tag];

>         unsigned long flags;

> -       unsigned int tag;

>         int err = 0;

> -       struct ufshcd_lrb *lrbp;

>         u32 reg;

> 

> -       host = cmd->device->host;

> -       hba = shost_priv(host);

> -       tag = cmd->request->tag;

> -       lrbp = &hba->lrb[tag];

lrbp is used below ?
if (lrbp->lun == UFS_UPIU_UFS_DEVICE_WLUN) ...

Thanks,
Avri

> -       if (!ufshcd_valid_tag(hba, tag)) {

> -               dev_err(hba->dev,

> -                       "%s: invalid command tag %d: cmd=0x%p, cmd-

> >request=0x%p",

> -                       __func__, tag, cmd, cmd->request);

> -               BUG();

> -       }

> -

>         ufshcd_hold(hba, false);

>         reg = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);

>         /* If command is already aborted/completed, return SUCCESS */
Bart Van Assche July 5, 2021, 6:08 p.m. UTC | #2
On 7/4/21 11:46 PM, Avri Altman wrote:
>> scsi_add_host() allocates shost->can_queue tags. ufshcd_init() sets

>> shost->can_queue to hba->nutrs. In other words, we know that tag values

>> will be in the range [0, hba->nutrs). Hence remove the checks that

>> verify that blk_get_request() returns a tag in this range. This check

>> was introduced by commit 14497328b6a6 ("scsi: ufs: verify command tag

>> validity").

>>

>> Cc: Alim Akhtar <alim.akhtar@samsung.com>

>> Cc: Avri Altman <avri.altman@wdc.com>

>> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

> 

>>  static int ufshcd_abort(struct scsi_cmnd *cmd)

>>  {

>> -       struct Scsi_Host *host;

>> -       struct ufs_hba *hba;

>> +       struct Scsi_Host *host = cmd->device->host;

>> +       struct ufs_hba *hba = shost_priv(host);

>> +       unsigned int tag = cmd->request->tag;

>> +       struct ufshcd_lrb *lrbp = &hba->lrb[tag];

>>         unsigned long flags;

>> -       unsigned int tag;

>>         int err = 0;

>> -       struct ufshcd_lrb *lrbp;

>>         u32 reg;

>>

>> -       host = cmd->device->host;

>> -       hba = shost_priv(host);

>> -       tag = cmd->request->tag;

>> -       lrbp = &hba->lrb[tag];

> lrbp is used below ?

> if (lrbp->lun == UFS_UPIU_UFS_DEVICE_WLUN) ...


Hi Avri,

The lrbp assignment is preserved but it has been moved up to the
declaration block.

Bart.
Avri Altman July 5, 2021, 7:01 p.m. UTC | #3
> 

> On 7/4/21 11:46 PM, Avri Altman wrote:

> >> scsi_add_host() allocates shost->can_queue tags. ufshcd_init() sets

> >> shost->can_queue to hba->nutrs. In other words, we know that tag values

> >> will be in the range [0, hba->nutrs). Hence remove the checks that

> >> verify that blk_get_request() returns a tag in this range. This check

> >> was introduced by commit 14497328b6a6 ("scsi: ufs: verify command tag

> >> validity").

> >>

> >> Cc: Alim Akhtar <alim.akhtar@samsung.com>

> >> Cc: Avri Altman <avri.altman@wdc.com>

> >> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

> >

> >>  static int ufshcd_abort(struct scsi_cmnd *cmd)

> >>  {

> >> -       struct Scsi_Host *host;

> >> -       struct ufs_hba *hba;

> >> +       struct Scsi_Host *host = cmd->device->host;

> >> +       struct ufs_hba *hba = shost_priv(host);

> >> +       unsigned int tag = cmd->request->tag;

> >> +       struct ufshcd_lrb *lrbp = &hba->lrb[tag];

> >>         unsigned long flags;

> >> -       unsigned int tag;

> >>         int err = 0;

> >> -       struct ufshcd_lrb *lrbp;

> >>         u32 reg;

> >>

> >> -       host = cmd->device->host;

> >> -       hba = shost_priv(host);

> >> -       tag = cmd->request->tag;

> >> -       lrbp = &hba->lrb[tag];

> > lrbp is used below ?

> > if (lrbp->lun == UFS_UPIU_UFS_DEVICE_WLUN) ...

> 

> Hi Avri,

> 

> The lrbp assignment is preserved but it has been moved up to the

> declaration block.

Missed that - sorry.

Avri

> Bart.
Avri Altman July 5, 2021, 7:02 p.m. UTC | #4
> scsi_add_host() allocates shost->can_queue tags. ufshcd_init() sets

> shost->can_queue to hba->nutrs. In other words, we know that tag values

> will be in the range [0, hba->nutrs). Hence remove the checks that

> verify that blk_get_request() returns a tag in this range. This check

> was introduced by commit 14497328b6a6 ("scsi: ufs: verify command tag

> validity").

> 

> Cc: Alim Akhtar <alim.akhtar@samsung.com>

> Cc: Avri Altman <avri.altman@wdc.com>

> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Reviewed-by: Avri Altman <avri.altman@wdc.com>
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 2148e123e9db..2e6aa614e3f5 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -253,11 +253,6 @@  static inline void ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable);
 static void ufshcd_hba_vreg_set_lpm(struct ufs_hba *hba);
 static void ufshcd_hba_vreg_set_hpm(struct ufs_hba *hba);
 
-static inline bool ufshcd_valid_tag(struct ufs_hba *hba, int tag)
-{
-	return tag >= 0 && tag < hba->nutrs;
-}
-
 static inline void ufshcd_enable_irq(struct ufs_hba *hba)
 {
 	if (!hba->is_irq_enabled) {
@@ -2701,21 +2696,11 @@  static void ufshcd_init_lrb(struct ufs_hba *hba, struct ufshcd_lrb *lrb, int i)
  */
 static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
 {
+	struct ufs_hba *hba = shost_priv(host);
+	int tag = cmd->request->tag;
 	struct ufshcd_lrb *lrbp;
-	struct ufs_hba *hba;
-	int tag;
 	int err = 0;
 
-	hba = shost_priv(host);
-
-	tag = cmd->request->tag;
-	if (!ufshcd_valid_tag(hba, tag)) {
-		dev_err(hba->dev,
-			"%s: invalid command tag %d: cmd=0x%p, cmd->request=0x%p",
-			__func__, tag, cmd, cmd->request);
-		BUG();
-	}
-
 	if (!down_read_trylock(&hba->clk_scaling_lock))
 		return SCSI_MLQUEUE_HOST_BUSY;
 
@@ -2968,7 +2953,6 @@  static int ufshcd_exec_dev_cmd(struct ufs_hba *hba,
 		goto out_unlock;
 	}
 	tag = req->tag;
-	WARN_ON_ONCE(!ufshcd_valid_tag(hba, tag));
 
 	if (unlikely(test_bit(tag, &hba->outstanding_reqs))) {
 		err = -EBUSY;
@@ -6673,7 +6657,6 @@  static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba,
 		goto out_unlock;
 	}
 	tag = req->tag;
-	WARN_ON_ONCE(!ufshcd_valid_tag(hba, tag));
 
 	if (unlikely(test_bit(tag, &hba->outstanding_reqs))) {
 		err = -EBUSY;
@@ -6975,25 +6958,14 @@  static int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)
  */
 static int ufshcd_abort(struct scsi_cmnd *cmd)
 {
-	struct Scsi_Host *host;
-	struct ufs_hba *hba;
+	struct Scsi_Host *host = cmd->device->host;
+	struct ufs_hba *hba = shost_priv(host);
+	unsigned int tag = cmd->request->tag;
+	struct ufshcd_lrb *lrbp = &hba->lrb[tag];
 	unsigned long flags;
-	unsigned int tag;
 	int err = 0;
-	struct ufshcd_lrb *lrbp;
 	u32 reg;
 
-	host = cmd->device->host;
-	hba = shost_priv(host);
-	tag = cmd->request->tag;
-	lrbp = &hba->lrb[tag];
-	if (!ufshcd_valid_tag(hba, tag)) {
-		dev_err(hba->dev,
-			"%s: invalid command tag %d: cmd=0x%p, cmd->request=0x%p",
-			__func__, tag, cmd, cmd->request);
-		BUG();
-	}
-
 	ufshcd_hold(hba, false);
 	reg = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
 	/* If command is already aborted/completed, return SUCCESS */