Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9003118pxu; Mon, 28 Dec 2020 04:06:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXdJ2jtWTcg28HCd3kFMhjxM9jbUAR7b9b4z/e2Sepp1h4tk+0LevVKYK4wvxV49lgjPhM X-Received: by 2002:a17:906:5e0d:: with SMTP id n13mr40730485eju.500.1609157216244; Mon, 28 Dec 2020 04:06:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609157216; cv=none; d=google.com; s=arc-20160816; b=w8X/Djfevyc3X2lZdFJFuJJ3BDK2L1ttfFkRSkShRLzMFKsoykXDoPMIDpige2h/OR V4FnK6Z/iy8oWBkoDcwLf7zAwGKJjK47XBH+jLrzpxFr5SXXjjSNS3PAAVas8XHbKgBq KvOfMdDgvGMgodDocC6Q+5D09jT4DxQPVSZqaIPm2iAEv6q/NeEe6V0cWcK5mVi4/xjQ uqPWlWMT/ZzoApiUpHjquzQmIl1DDv6p98LFzADKRiluMbdkHEPQGY/+7T/sUnEj8shx wp4HfyMPgQfBB/X7iy5GdE1U83rsbeh8336pHh+YJBBCRLIT32+g1J5jf0Dgw5o64ePL BqLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:ironport-sdr; bh=ORO9ONGx5qQAidCjLusy65rw6U5lvqxiuH9sqefzHBQ=; b=wybVxCJA3nc3LQHUqTcEch79lwv+F9NGwZOIO/sY3eWhDhr8siTj2TLVaUqeNbBq1A v+LSJUKt/FcvxnRVQCQDlQfJOoARXmaQ9Q8SmOuz4+pfiIN05/jmUJK+sXKwUGlZ7qQS Z3+FNKVnWq2MexHVKM4xPaGyF553iXfVI4NYrfx25kBjGpw2DyrYcXMPV4A7GMfkyO48 vJ5sVBg3/ZrZ2qwDPWHTHB27arGtPxUGuuFJxATv43lSYPY2s8EE0J0VzzKX5lhf+xHI Wa//j/Cir65iBq47xIglWpsAUI+YQ/KodUf3Wy/hKP6/QwTC3ELi9OFO6KG++lg/HTlz uh+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q16si19453535ejd.199.2020.12.28.04.06.33; Mon, 28 Dec 2020 04:06:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727686AbgL1MF0 (ORCPT + 99 others); Mon, 28 Dec 2020 07:05:26 -0500 Received: from labrats.qualcomm.com ([199.106.110.90]:12867 "EHLO labrats.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727482AbgL1MFY (ORCPT ); Mon, 28 Dec 2020 07:05:24 -0500 IronPort-SDR: 0k5lsHhbcHw79ZwaIYH96GoUtAwxRqbuVSlzHzYawAZE+1cuIk0sYM0FblPPBctdFdv9SwJX0a I1kYsgWEzZ0y340UEemolZ+FgGbT8Dt7JSZPfWFHSha1gNlONeIepUf6YGdDWzT9aSPWed+qfC LPuqTlddjYiWf05w0QK6xTOd64dpXKas+WOD4SsGTqPHKRWY8WGlZGAldqdNjIOYJ5cbp1oggV hCzcPUBkb5EtcQ2aLRfs602fCMTd/NKAexzbKDpfrm5qeiPA797PPnSxB+sVb68/vz9btuSkC5 /ps= X-IronPort-AV: E=Sophos;i="5.78,455,1599548400"; d="scan'208";a="29452600" Received: from unknown (HELO ironmsg05-sd.qualcomm.com) ([10.53.140.145]) by labrats.qualcomm.com with ESMTP; 28 Dec 2020 04:04:44 -0800 X-QCInternal: smtphost Received: from stor-presley.qualcomm.com ([192.168.140.85]) by ironmsg05-sd.qualcomm.com with ESMTP; 28 Dec 2020 04:04:43 -0800 Received: by stor-presley.qualcomm.com (Postfix, from userid 359480) id EC2AC2188E; Mon, 28 Dec 2020 04:04:43 -0800 (PST) From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, ziqichen@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Bart Van Assche , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] scsi: ufs: Correct the lun used in eh_device_reset_handler() callback Date: Mon, 28 Dec 2020 04:04:36 -0800 Message-Id: <1609157080-26283-1-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Users can initiate resets to specific SCSI device/target/host through IOCTL. When this happens, the SCSI cmd passed to eh_device/target/host _reset_handler() callbacks is initialized with a request whose tag is -1. So, in this case, it is not right for eh_device_reset_handler() callback to count on the lun get from hba->lrb[-1]. Fix it by getting lun from the SCSI device associated with the SCSI cmd. Signed-off-by: Can Guo diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 98093a5..d577cda 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6604,19 +6604,16 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) { struct Scsi_Host *host; struct ufs_hba *hba; - unsigned int tag; u32 pos; int err; - u8 resp = 0xF; - struct ufshcd_lrb *lrbp; + u8 resp = 0xF, lun; unsigned long flags; host = cmd->device->host; hba = shost_priv(host); - tag = cmd->request->tag; - lrbp = &hba->lrb[tag]; - err = ufshcd_issue_tm_cmd(hba, lrbp->lun, 0, UFS_LOGICAL_RESET, &resp); + lun = ufshcd_scsi_to_upiu_lun(cmd->device->lun); + err = ufshcd_issue_tm_cmd(hba, lun, 0, UFS_LOGICAL_RESET, &resp); if (err || resp != UPIU_TASK_MANAGEMENT_FUNC_COMPL) { if (!err) err = resp; @@ -6625,7 +6622,7 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) /* clear the commands that were pending for corresponding LUN */ for_each_set_bit(pos, &hba->outstanding_reqs, hba->nutrs) { - if (hba->lrb[pos].lun == lrbp->lun) { + if (hba->lrb[pos].lun == lun) { err = ufshcd_clear_cmd(hba, pos); if (err) break; -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.