From patchwork Wed Jun 3 09:19:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11585389 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 38CF4739 for ; Wed, 3 Jun 2020 09:20:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 220622074B for ; Wed, 3 Jun 2020 09:20:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Cg4iNhJR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726827AbgFCJUV (ORCPT ); Wed, 3 Jun 2020 05:20:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725881AbgFCJUR (ORCPT ); Wed, 3 Jun 2020 05:20:17 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 265C0C05BD43; Wed, 3 Jun 2020 02:20:17 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id x93so1115238ede.9; Wed, 03 Jun 2020 02:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cB2Kq623XQ22+n48/sVsupZYgeDKXkx1f2JvNrAS7Eg=; b=Cg4iNhJRn5TfwR+U6is/i/hkAI1C9vOZvH39O2kJGvC1+kcpOFWBoj02RZ/8YCizw4 TN4Du8QJBJI6OUxnRcqzguDlxAiP2/KLM+BEfrGuH9lodFpEJfOgGuFoDNXS79AFBz3x BSsx6G3o7UvIqUq6xWxHdBiWiemDcWfl6cIGF9cbZ+GTKMi12BzXwKqcEi6HcBKxQ0zv pxy2EWZTHcX0B82yUMVYkGAtDjECsP16RgEYII6rnhKDRvCVIk+Gf8BMCLbVKMdWjqQe TfSe3HOGF7SZHSRFfLJPR8Uk3oUhqjIqbBm7Lp4TXfH2nDfijmXfByJaWPWg0Tf5Dxhl Ksqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cB2Kq623XQ22+n48/sVsupZYgeDKXkx1f2JvNrAS7Eg=; b=XsJliFSpgFNdkXhVOMaDoJvqsZi4OA665ECiLJ635kfRJ2/LyzgIHBq08cvMnVfOL5 7mqI+TmhAXXO6/sl5WBqnrJvhzveskuWmaMKjIiuCcx1jDm1sxhlds0wb/IhReWv+V4J W1E4Ig3wJCa/HBTUuuRz6IdC5HwAYH4UrkydP+1IW/OUgGwb2FzuWcap73/CAivjq+ck ldog925ncIn2RQb/wKku9yCW6171KCMGnOOCG7XOVoaWh2sg2KX5lJ5dDrnH29GrKRI+ FHkV2D3ZCKhVGhGd3EFmu0pRNkz3DSaqy6O5hPJPMnF59Z/lJ/4vvfspalGfwpXtqQX0 Xhdg== X-Gm-Message-State: AOAM530rHIpVSg+wpfTiJ+bJG06E42cwAlCiy+VxIT3z13X7qO1J8//I 2dzuqaq3at8Xemd5gWQlZOk= X-Google-Smtp-Source: ABdhPJy+qf+2utE3eFGUuUKDP3e9ahV4uH/A0a7cQZ4CwL43z9QvLnR4ACkNxsjTDJ9eKZfjk4AtuA== X-Received: by 2002:a50:ac84:: with SMTP id x4mr31446589edc.124.1591176015916; Wed, 03 Jun 2020 02:20:15 -0700 (PDT) Received: from localhost.localdomain ([2a01:598:d00c:464c:92b:aecc:3637:dc7c]) by smtp.gmail.com with ESMTPSA id 64sm865636eda.85.2020.06.03.02.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2020 02:20:15 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, beanhuo@outlook.com Subject: [RESENT PATCH v5 1/5] scsi: ufs: remove max_t in ufs_get_device_desc Date: Wed, 3 Jun 2020 11:19:55 +0200 Message-Id: <20200603091959.27618-2-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200603091959.27618-1-huobean@gmail.com> References: <20200603091959.27618-1-huobean@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo For the UFS device, the maximum descriptor size is 255, max_t called in ufs_get_device_desc() is useless. Signed-off-by: Bart van Assche Signed-off-by: Bean Huo Acked-by: Avri Altman Reviewed-by: Stanley Chu --- drivers/scsi/ufs/ufshcd.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index ad4fc829cbb2..2cf077ab9dfd 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6903,14 +6903,11 @@ static void ufs_fixup_device_setup(struct ufs_hba *hba) static int ufs_get_device_desc(struct ufs_hba *hba) { int err; - size_t buff_len; u8 model_index; u8 *desc_buf; struct ufs_dev_info *dev_info = &hba->dev_info; - buff_len = max_t(size_t, hba->desc_size.dev_desc, - QUERY_DESC_MAX_SIZE + 1); - desc_buf = kmalloc(buff_len, GFP_KERNEL); + desc_buf = kmalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL); if (!desc_buf) { err = -ENOMEM; goto out; From patchwork Wed Jun 3 09:19:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11585393 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCFBC739 for ; Wed, 3 Jun 2020 09:20:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C36A820674 for ; Wed, 3 Jun 2020 09:20:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L3Rzqkip" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726598AbgFCJUU (ORCPT ); Wed, 3 Jun 2020 05:20:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725954AbgFCJUT (ORCPT ); Wed, 3 Jun 2020 05:20:19 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E7B7C05BD1E; Wed, 3 Jun 2020 02:20:19 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id q13so1143071edi.3; Wed, 03 Jun 2020 02:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xU7pX4nkK7ZQg7clUMzQ4yPEEjGSdbLLAvPKUl0GCPM=; b=L3RzqkippX2qj1i6eCQ5wpBKTfjAzeOGUJeZHSyz1uM5TAj9tfrJw7HGi6Nt8tPeIE J+Y+Q4PbcOq9uP1M9n0kW79eS+E4RC072dnehJlQfZ53T5Z2pGVdL9s3ewLRIAHGVCb8 kvTybfqwvz5cwZfhsLLDljSa4VPfj/q+6ZYnUXqhbYScms91UK6MsBaklPeu2ANigvxu 0H98xL64nCPH2SmWwPT3iO7NaHaV+YrGtcoWhDQGQWEi0at9lDye5cGIKaSsUsp0fSCJ CwV2EWzn9bICFXGHLXNgh7zgYcQhkJXAEH3Y2wQ4nrO3o5IYsXRRVodoOACobTgc54Ev lnEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xU7pX4nkK7ZQg7clUMzQ4yPEEjGSdbLLAvPKUl0GCPM=; b=oTFPR155lYQNS1PUyUEcrwaVl7N8cvElTx35JR3zuL8FkpgPXqRiOC2SKxjgizQRhn qp5KrJ8Ti0AU5+72zOgkr50YX97APH7sRS7cLZOZp8g8PnSTRmQo112nb3+wq1xNQci0 IAyrmUHLTWrlpWQIvfCueh/fSLiCvTR4rXjbbHi/PELt71vpL8lpP4zof7SEqgpbrYoC 40oTFn9wtkyO17ClDnh4kbOuwskLb5rF74jECwx5a5qT1l4ndI6PJTPYDyXPBhvea204 Ja8q559cUq0VYnotoBdmQvet8WgJQIxuGHSfzPLLHdfDWFg/P4Vr2kDpEwM9rdLt4aSc ZSRQ== X-Gm-Message-State: AOAM533g9zyTxIJNpgPE+p5dmM4BgFNSSo678Eybfolf5adO7sg+XBUs vWkY7KIRtk8069sMn5RO+08= X-Google-Smtp-Source: ABdhPJz65a3RCO/nFWS+lEzKjLuelstixw+3z5Wxj/AMi5H3E8W8EY5y9nAdTSz/0uTQdNP9ZDhMqQ== X-Received: by 2002:a50:b2e1:: with SMTP id p88mr30552214edd.198.1591176017991; Wed, 03 Jun 2020 02:20:17 -0700 (PDT) Received: from localhost.localdomain ([2a01:598:d00c:464c:92b:aecc:3637:dc7c]) by smtp.gmail.com with ESMTPSA id 64sm865636eda.85.2020.06.03.02.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2020 02:20:17 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, beanhuo@outlook.com Subject: [RESENT PATCH v5 2/5] scsi: ufs: delete ufshcd_read_desc() Date: Wed, 3 Jun 2020 11:19:56 +0200 Message-Id: <20200603091959.27618-3-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200603091959.27618-1-huobean@gmail.com> References: <20200603091959.27618-1-huobean@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo Delete ufshcd_read_desc(). Instead, let caller directly call ufshcd_read_desc_param(). Signed-off-by: Bean Huo Reviewed-by: Avri Altman Reviewed-by: Bart van Assche Reviewed-by: Stanley Chu --- drivers/scsi/ufs/ufshcd.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 2cf077ab9dfd..c18c2aadbe14 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3221,16 +3221,6 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, return ret; } -static inline int ufshcd_read_desc(struct ufs_hba *hba, - enum desc_idn desc_id, - int desc_index, - void *buf, - u32 size) -{ - return ufshcd_read_desc_param(hba, desc_id, desc_index, 0, buf, size); -} - - /** * struct uc_string_id - unicode string * @@ -3278,9 +3268,8 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, if (!uc_str) return -ENOMEM; - ret = ufshcd_read_desc(hba, QUERY_DESC_IDN_STRING, - desc_index, uc_str, - QUERY_DESC_MAX_SIZE); + ret = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_STRING, desc_index, 0, + (u8 *)uc_str, QUERY_DESC_MAX_SIZE); if (ret < 0) { dev_err(hba->dev, "Reading String Desc failed after %d retries. err = %d\n", QUERY_REQ_RETRIES, ret); @@ -6711,8 +6700,8 @@ static void ufshcd_set_active_icc_lvl(struct ufs_hba *hba) if (!desc_buf) return; - ret = ufshcd_read_desc(hba, QUERY_DESC_IDN_POWER, 0, - desc_buf, buff_len); + ret = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_POWER, 0, 0, + desc_buf, buff_len); if (ret) { dev_err(hba->dev, "%s: Failed reading power descriptor.len = %d ret = %d", @@ -6913,8 +6902,8 @@ static int ufs_get_device_desc(struct ufs_hba *hba) goto out; } - err = ufshcd_read_desc(hba, QUERY_DESC_IDN_DEVICE, 0, desc_buf, - hba->desc_size.dev_desc); + err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_DEVICE, 0, 0, desc_buf, + hba->desc_size.dev_desc); if (err) { dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n", __func__, err); @@ -7196,8 +7185,8 @@ static int ufshcd_device_geo_params_init(struct ufs_hba *hba) goto out; } - err = ufshcd_read_desc(hba, QUERY_DESC_IDN_GEOMETRY, 0, - desc_buf, buff_len); + err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_GEOMETRY, 0, 0, + desc_buf, buff_len); if (err) { dev_err(hba->dev, "%s: Failed reading Geometry Desc. err = %d\n", __func__, err); From patchwork Wed Jun 3 09:19:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11585391 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4010C1392 for ; Wed, 3 Jun 2020 09:20:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 279E52074B for ; Wed, 3 Jun 2020 09:20:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IoM4ng/2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726905AbgFCJUh (ORCPT ); Wed, 3 Jun 2020 05:20:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726844AbgFCJUV (ORCPT ); Wed, 3 Jun 2020 05:20:21 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08A9BC05BD43; Wed, 3 Jun 2020 02:20:21 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id p18so1129577eds.7; Wed, 03 Jun 2020 02:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ogVBeLIbUp0NMkbqjh+n5vv4JgRPcqvKmVHALzkoaQM=; b=IoM4ng/2v4WolN9uZtbOyJkSTfaNDpUzdLNwJPJ7EEKEQ92PdmqGo+13pEWhiU7p3X Cvj/WbgwtrXXsCWCkA77HlsqEsXxKWmzIo0B63myw02OK1Z6ekb9L/LnKiiPrwAKEOno D5fmihdWZm1yzhm9xYK/bHOXmTKZ5QEgv/e2DNzqhadtEA0E7q7Tpl4OP0T4gtiChPmw 3ifSz7QAjPXiYDsxcH7dgYbuJl93t6OEsuoa8TVJ3s5fmZEy8E7sn98SvMqUii3Lu+zL vlLv0e7+luboBunXbQa6NVJSGvJ0KE+0cdhvWXl2Jt3vXJC3uWb8yHvutFH2T0nFIUza nh3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ogVBeLIbUp0NMkbqjh+n5vv4JgRPcqvKmVHALzkoaQM=; b=fD6s2LNVL4dFfHkNZ6ZdJzRfXNXzTmMUdX76PWiTWDfDJI+/jJZJpFd3abNSEECIM/ ohsssE8Gv5eW2n51yMSRX1Zw0C9IHSjp0ZM7Lu3S62LHId/Lcgv0SHfz8JcvWgvgw9EC HQJRTWQsHLCc+1Gl0dFWApMEzN8iOAopUjtPuTQkRRNsc1x9xDWkYnzHZ05UcoNxPW3K DmtRfb83VlLSeEQ9WrOp2dbnrIdfJAouquyYLE14I2rIcX1rfa/UX3OOhsEob/uLcTsy G1e/5AFkHe34tvBYWBiYIfIwzoLMDWeb/hSNhNOCvgDZKtmvCLJ8/8OY5gA8bMbooIN4 Ybag== X-Gm-Message-State: AOAM533Ll/fbSi/NRz8jDmFZyzYbkBpAoLUbz6byrYH95d8CN0j9yMCy mPgdGcju88faGkxMNvGcCPQ= X-Google-Smtp-Source: ABdhPJzXDCE/8Q8sDevWCrnJ5C9NHj2GgnTLW1qURMiMirBoCgNM5FUphb55fmon7SVn5LwHowXCmA== X-Received: by 2002:aa7:d79a:: with SMTP id s26mr28799189edq.202.1591176019739; Wed, 03 Jun 2020 02:20:19 -0700 (PDT) Received: from localhost.localdomain ([2a01:598:d00c:464c:92b:aecc:3637:dc7c]) by smtp.gmail.com with ESMTPSA id 64sm865636eda.85.2020.06.03.02.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2020 02:20:19 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, beanhuo@outlook.com Subject: [RESENT PATCH v5 3/5] scsi: ufs: fix potential access NULL pointer while memcpy Date: Wed, 3 Jun 2020 11:19:57 +0200 Message-Id: <20200603091959.27618-4-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200603091959.27618-1-huobean@gmail.com> References: <20200603091959.27618-1-huobean@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo If param_offset is not 0, the memcpy length shouldn't be the true descriptor length. Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufshcd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index c18c2aadbe14..7163b268ed0b 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3210,8 +3210,8 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, } /* Check wherher we will not copy more data, than available */ - if (is_kmalloc && param_size > buff_len) - param_size = buff_len; + if (is_kmalloc && (param_offset + param_size) > buff_len) + param_size = buff_len - param_offset; if (is_kmalloc) memcpy(param_read_buf, &desc_buf[param_offset], param_size); From patchwork Wed Jun 3 09:19:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11585385 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41E48739 for ; Wed, 3 Jun 2020 09:20:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00BAC207DA for ; Wed, 3 Jun 2020 09:20:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SeNdPsHw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726871AbgFCJU1 (ORCPT ); Wed, 3 Jun 2020 05:20:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725881AbgFCJUY (ORCPT ); Wed, 3 Jun 2020 05:20:24 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 185B2C05BD43; Wed, 3 Jun 2020 02:20:23 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id o15so1363911ejm.12; Wed, 03 Jun 2020 02:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Aoi3xuxMLMW4MC5IHy+PLceD1Is3GSCaMCdwd+7OIME=; b=SeNdPsHw6XwsXsv77rt/xMzy8O+EBxYxaL9hwlt1a2RT/XNbSLSyUscJFx9yY4Qyi2 UP423qI8PvG25VsCTkMxRpJ28qqca1ufrVbqr/8J3XEQSwi4y8Tg2cbpxJLV8DVHsyjS V8GpFCqry643qWy9YgzdFjlA9AVzaePHx4hjHsW4REl1E7wojxBCYHkqFLSIERC/GfaG La9BSiaTlqolous+KbQWncTQe/nIZe4H9qav4gUZG/MOov4QMovk2GwNHpYALEWLmwLt V8dhzo0OCPNJLvDKnT8cDrPOGIIo5/0vzXY4dYcNXjEa6doiV7AeiQK+CPY5vnb7XW1I LypQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Aoi3xuxMLMW4MC5IHy+PLceD1Is3GSCaMCdwd+7OIME=; b=ap9wv8n5Nut9c3pbpySkz9DFSC+D501zHg89d1ghXF5URGn7q8psA4tVM8KcBEkxnU bJKpVLs3iqo1bQonT4mxxJdNPfdUYBpxIrsSn2LUd1EOIkb7JZ/d/NRpPkcIEXmdFtjG uq5lKvME10gofgECTQ2GrH8noSsWWtwvMhVYXmDs/9dYu/KU4hY4V5rYdA3cXn37cjpf 0xBj2upPDi+vmzrkeCuTIxLaqLZT4H1trcHleAHbrXMAOLIm/yY/oNq4xqysMaWigc3/ Zet6ougNUgVdEGeZxmzgaPDsHLIw8cONx7HnU/ABrbDi2c/kA46ww21YwjUmT1Ve6bU6 dRzA== X-Gm-Message-State: AOAM532uBrtV8rnzxpJGENPQMHGFeGGdc3ucyP7DeL+bOVPHIGwps9bx 1aSQ56x9Mh9GLag9JxFpqM4= X-Google-Smtp-Source: ABdhPJxZCnLl2BNH2XhAaNDHIO/GMzS7uMOvWkThmpoCdAf38vP8Tg1EEdQKP6sSrc3OaPwtcBxfOA== X-Received: by 2002:a17:906:31d2:: with SMTP id f18mr16498098ejf.110.1591176021774; Wed, 03 Jun 2020 02:20:21 -0700 (PDT) Received: from localhost.localdomain ([2a01:598:d00c:464c:92b:aecc:3637:dc7c]) by smtp.gmail.com with ESMTPSA id 64sm865636eda.85.2020.06.03.02.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2020 02:20:21 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, beanhuo@outlook.com Subject: [RESENT PATCH v5 4/5] scsi: ufs: cleanup ufs initialization path Date: Wed, 3 Jun 2020 11:19:58 +0200 Message-Id: <20200603091959.27618-5-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200603091959.27618-1-huobean@gmail.com> References: <20200603091959.27618-1-huobean@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo At UFS initialization stage, to get the length of the descriptor, ufshcd_read_desc_length() being called 6 times. Instead, we will capture the descriptor size the first time we'll read it. Delete unnecessary redundant code, remove ufshcd_read_desc_length(), ufshcd_init_desc_sizes(), and boost UFS initialization. Signed-off-by: Bean Huo Reviewed-by: Bart van Assche Reviewed-by: Stanley Chu --- drivers/scsi/ufs/ufs.h | 10 --- drivers/scsi/ufs/ufs_bsg.c | 5 +- drivers/scsi/ufs/ufshcd.c | 168 ++++++++----------------------------- drivers/scsi/ufs/ufshcd.h | 16 +--- 4 files changed, 38 insertions(+), 161 deletions(-) diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index c70845d41449..8770255b5dc0 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -200,16 +200,6 @@ enum desc_header_offset { QUERY_DESC_DESC_TYPE_OFFSET = 0x01, }; -enum ufs_desc_def_size { - QUERY_DESC_DEVICE_DEF_SIZE = 0x59, - QUERY_DESC_CONFIGURATION_DEF_SIZE = 0x90, - QUERY_DESC_UNIT_DEF_SIZE = 0x2D, - QUERY_DESC_INTERCONNECT_DEF_SIZE = 0x06, - QUERY_DESC_GEOMETRY_DEF_SIZE = 0x48, - QUERY_DESC_POWER_DEF_SIZE = 0x62, - QUERY_DESC_HEALTH_DEF_SIZE = 0x25, -}; - /* Unit descriptor parameters offsets in bytes*/ enum unit_desc_param { UNIT_DESC_PARAM_LEN = 0x0, diff --git a/drivers/scsi/ufs/ufs_bsg.c b/drivers/scsi/ufs/ufs_bsg.c index 53dd87628cbe..27f54615ee84 100644 --- a/drivers/scsi/ufs/ufs_bsg.c +++ b/drivers/scsi/ufs/ufs_bsg.c @@ -11,13 +11,12 @@ static int ufs_bsg_get_query_desc_size(struct ufs_hba *hba, int *desc_len, { int desc_size = be16_to_cpu(qr->length); int desc_id = qr->idn; - int ret; if (desc_size <= 0) return -EINVAL; - ret = ufshcd_map_desc_id_to_length(hba, desc_id, desc_len); - if (ret || !*desc_len) + ufshcd_map_desc_id_to_length(hba, desc_id, desc_len); + if (!*desc_len) return -EINVAL; *desc_len = min_t(int, *desc_len, desc_size); diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 7163b268ed0b..5ad0eebccc98 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3052,95 +3052,32 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba, return err; } -/** - * ufshcd_read_desc_length - read the specified descriptor length from header - * @hba: Pointer to adapter instance - * @desc_id: descriptor idn value - * @desc_index: descriptor index - * @desc_length: pointer to variable to read the length of descriptor - * - * Return 0 in case of success, non-zero otherwise - */ -static int ufshcd_read_desc_length(struct ufs_hba *hba, - enum desc_idn desc_id, - int desc_index, - int *desc_length) -{ - int ret; - u8 header[QUERY_DESC_HDR_SIZE]; - int header_len = QUERY_DESC_HDR_SIZE; - - if (desc_id >= QUERY_DESC_IDN_MAX) - return -EINVAL; - - ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, - desc_id, desc_index, 0, header, - &header_len); - - if (ret) { - dev_err(hba->dev, "%s: Failed to get descriptor header id %d", - __func__, desc_id); - return ret; - } else if (desc_id != header[QUERY_DESC_DESC_TYPE_OFFSET]) { - dev_warn(hba->dev, "%s: descriptor header id %d and desc_id %d mismatch", - __func__, header[QUERY_DESC_DESC_TYPE_OFFSET], - desc_id); - ret = -EINVAL; - } - - *desc_length = header[QUERY_DESC_LENGTH_OFFSET]; - return ret; - -} - /** * ufshcd_map_desc_id_to_length - map descriptor IDN to its length * @hba: Pointer to adapter instance * @desc_id: descriptor idn value * @desc_len: mapped desc length (out) - * - * Return 0 in case of success, non-zero otherwise */ -int ufshcd_map_desc_id_to_length(struct ufs_hba *hba, - enum desc_idn desc_id, int *desc_len) +void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, + int *desc_len) { - switch (desc_id) { - case QUERY_DESC_IDN_DEVICE: - *desc_len = hba->desc_size.dev_desc; - break; - case QUERY_DESC_IDN_POWER: - *desc_len = hba->desc_size.pwr_desc; - break; - case QUERY_DESC_IDN_GEOMETRY: - *desc_len = hba->desc_size.geom_desc; - break; - case QUERY_DESC_IDN_CONFIGURATION: - *desc_len = hba->desc_size.conf_desc; - break; - case QUERY_DESC_IDN_UNIT: - *desc_len = hba->desc_size.unit_desc; - break; - case QUERY_DESC_IDN_INTERCONNECT: - *desc_len = hba->desc_size.interc_desc; - break; - case QUERY_DESC_IDN_STRING: - *desc_len = QUERY_DESC_MAX_SIZE; - break; - case QUERY_DESC_IDN_HEALTH: - *desc_len = hba->desc_size.hlth_desc; - break; - case QUERY_DESC_IDN_RFU_0: - case QUERY_DESC_IDN_RFU_1: - *desc_len = 0; - break; - default: + if (desc_id >= QUERY_DESC_IDN_MAX || desc_id == QUERY_DESC_IDN_RFU_0 || + desc_id == QUERY_DESC_IDN_RFU_1) *desc_len = 0; - return -EINVAL; - } - return 0; + else + *desc_len = hba->desc_size[desc_id]; } EXPORT_SYMBOL(ufshcd_map_desc_id_to_length); +static void ufshcd_update_desc_length(struct ufs_hba *hba, + enum desc_idn desc_id, + unsigned char desc_len) +{ + if (hba->desc_size[desc_id] == QUERY_DESC_MAX_SIZE && + desc_id != QUERY_DESC_IDN_STRING) + hba->desc_size[desc_id] = desc_len; +} + /** * ufshcd_read_desc_param - read the specified descriptor parameter * @hba: Pointer to adapter instance @@ -3168,16 +3105,11 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, if (desc_id >= QUERY_DESC_IDN_MAX || !param_size) return -EINVAL; - /* Get the max length of descriptor from structure filled up at probe - * time. - */ - ret = ufshcd_map_desc_id_to_length(hba, desc_id, &buff_len); - - /* Sanity checks */ - if (ret || !buff_len) { - dev_err(hba->dev, "%s: Failed to get full descriptor length", - __func__); - return ret; + /* Get the length of descriptor */ + ufshcd_map_desc_id_to_length(hba, desc_id, &buff_len); + if (!buff_len) { + dev_err(hba->dev, "%s: Failed to get desc length", __func__); + return -EINVAL; } /* Check whether we need temp memory */ @@ -3209,6 +3141,10 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, goto out; } + /* Update descriptor length */ + buff_len = desc_buf[QUERY_DESC_LENGTH_OFFSET]; + ufshcd_update_desc_length(hba, desc_id, buff_len); + /* Check wherher we will not copy more data, than available */ if (is_kmalloc && (param_offset + param_size) > buff_len) param_size = buff_len - param_offset; @@ -6692,7 +6628,7 @@ static u32 ufshcd_find_max_sup_active_icc_level(struct ufs_hba *hba, static void ufshcd_set_active_icc_lvl(struct ufs_hba *hba) { int ret; - int buff_len = hba->desc_size.pwr_desc; + int buff_len = hba->desc_size[QUERY_DESC_IDN_POWER]; u8 *desc_buf; u32 icc_level; @@ -6810,7 +6746,8 @@ static void ufshcd_wb_probe(struct ufs_hba *hba, u8 *desc_buf) if (!ufshcd_is_wb_allowed(hba)) return; - if (hba->desc_size.dev_desc < DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP + 4) + if (hba->desc_size[QUERY_DESC_IDN_DEVICE] < + DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP + 4) goto wb_disabled; hba->dev_info.d_ext_ufs_feature_sup = @@ -6903,7 +6840,7 @@ static int ufs_get_device_desc(struct ufs_hba *hba) } err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_DEVICE, 0, 0, desc_buf, - hba->desc_size.dev_desc); + hba->desc_size[QUERY_DESC_IDN_DEVICE]); if (err) { dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n", __func__, err); @@ -7132,53 +7069,13 @@ static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) hba->req_abort_count = 0; } -static void ufshcd_init_desc_sizes(struct ufs_hba *hba) -{ - int err; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_DEVICE, 0, - &hba->desc_size.dev_desc); - if (err) - hba->desc_size.dev_desc = QUERY_DESC_DEVICE_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_POWER, 0, - &hba->desc_size.pwr_desc); - if (err) - hba->desc_size.pwr_desc = QUERY_DESC_POWER_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_INTERCONNECT, 0, - &hba->desc_size.interc_desc); - if (err) - hba->desc_size.interc_desc = QUERY_DESC_INTERCONNECT_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_CONFIGURATION, 0, - &hba->desc_size.conf_desc); - if (err) - hba->desc_size.conf_desc = QUERY_DESC_CONFIGURATION_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_UNIT, 0, - &hba->desc_size.unit_desc); - if (err) - hba->desc_size.unit_desc = QUERY_DESC_UNIT_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_GEOMETRY, 0, - &hba->desc_size.geom_desc); - if (err) - hba->desc_size.geom_desc = QUERY_DESC_GEOMETRY_DEF_SIZE; - - err = ufshcd_read_desc_length(hba, QUERY_DESC_IDN_HEALTH, 0, - &hba->desc_size.hlth_desc); - if (err) - hba->desc_size.hlth_desc = QUERY_DESC_HEALTH_DEF_SIZE; -} - static int ufshcd_device_geo_params_init(struct ufs_hba *hba) { int err; size_t buff_len; u8 *desc_buf; - buff_len = hba->desc_size.geom_desc; + buff_len = hba->desc_size[QUERY_DESC_IDN_GEOMETRY]; desc_buf = kmalloc(buff_len, GFP_KERNEL); if (!desc_buf) { err = -ENOMEM; @@ -7274,10 +7171,11 @@ static int ufshcd_set_dev_ref_clk(struct ufs_hba *hba) static int ufshcd_device_params_init(struct ufs_hba *hba) { bool flag; - int ret; + int ret, i; - /* Init check for device descriptor sizes */ - ufshcd_init_desc_sizes(hba); + /* Init device descriptor sizes */ + for (i = 0; i < QUERY_DESC_IDN_MAX; i++) + hba->desc_size[i] = QUERY_DESC_MAX_SIZE; /* Init UFS geometry descriptor related parameters */ ret = ufshcd_device_geo_params_init(hba); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index bf97d616e597..2b62869fa459 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -236,16 +236,6 @@ struct ufs_dev_cmd { struct ufs_query query; }; -struct ufs_desc_size { - int dev_desc; - int pwr_desc; - int geom_desc; - int interc_desc; - int unit_desc; - int conf_desc; - int hlth_desc; -}; - /** * struct ufs_clk_info - UFS clock related info * @list: list headed by hba->clk_list_head @@ -738,7 +728,7 @@ struct ufs_hba { bool is_urgent_bkops_lvl_checked; struct rw_semaphore clk_scaling_lock; - struct ufs_desc_size desc_size; + unsigned char desc_size[QUERY_DESC_IDN_MAX]; atomic_t scsi_block_reqs_cnt; struct device bsg_dev; @@ -976,8 +966,8 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, int ufshcd_hold(struct ufs_hba *hba, bool async); void ufshcd_release(struct ufs_hba *hba); -int ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, - int *desc_length); +void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, + int *desc_length); u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba); From patchwork Wed Jun 3 09:19:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11585387 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C38C1392 for ; Wed, 3 Jun 2020 09:20:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21D2520674 for ; Wed, 3 Jun 2020 09:20:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a1dRKcsX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726888AbgFCJUc (ORCPT ); Wed, 3 Jun 2020 05:20:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbgFCJU1 (ORCPT ); Wed, 3 Jun 2020 05:20:27 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D84EC05BD43; Wed, 3 Jun 2020 02:20:25 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id f7so1391157ejq.6; Wed, 03 Jun 2020 02:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q95qHoKQVgshqw0ghfJQeL4NL6m9CpdNwWifAaKLFtc=; b=a1dRKcsXzPT7/8nWrC4VZaeR7YDw02C/6aHacGu5vuOLbvbvwCyiF2dyNYk5DyJ3Kl MAwO8gypA1msXDmORABgyDYQODgRevPwvvOddPfYkxvocIpBNYhRdICe+0PVaGcnPpbw AASLFSQRL/MkeLNui2tEMXLMXDY868Bj8AMb5yJ9/7fRAK/vQ+ma+/khX+KiaoWRiJ3o vBk45uVjCPubkPcywcAPWRY28S03tEVe2vUFozKS0ancrlRbQ5aXG4EujqnMZQ938+G5 qlWcov5+CydFFhht1xEpEw2UxUWMXDGc1JpYTFHYZOzs/tDVuKaBMerpUB2lBzRr51/S PQog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q95qHoKQVgshqw0ghfJQeL4NL6m9CpdNwWifAaKLFtc=; b=L030gZ94B8xz1+ef2vzBbhcxglP4h/IWtsha7MlLZ4l65Y8grrqyfyWSIyDV7YBrpo 6Za0HLD9zR5/4ne8RR/h7ZelETEa4ngmGJTHbQ3gYQpfvjLc7q6XKMvKLiGhi0Elx/0X /Dm5Su+4NuSZAIGLAelTxaqLY17hX9aSvOd3x2W3lZnKzGMkau6e8zXG3L8jaztZOIv6 OP4FBZLST+tBvd7EG/3S/5Sdaos8obeRggGYxP2IoA2NC3gT0ksmDzXrzhL2xMeyDq/j tQuIK+zoM2DiUWtc9u0Z7LCOM32simx+14dE0OQduq+V62CKw9zYpBoaFkB49zf4QgGn 69VA== X-Gm-Message-State: AOAM530bBG8KfknegoRkzvFher/pUfuxRd2UtdahDFluDmfyeHB2VDb5 vnGxn80wPZEfsOaCmtqOUWE= X-Google-Smtp-Source: ABdhPJz2YuxsHU8XJEnnqJiRuVIc8v0w9TR6f+5y6O8Uy9eveeYV2eS4etq0B0vYPFhh908E2u0qtQ== X-Received: by 2002:a17:906:6156:: with SMTP id p22mr25758769ejl.329.1591176023678; Wed, 03 Jun 2020 02:20:23 -0700 (PDT) Received: from localhost.localdomain ([2a01:598:d00c:464c:92b:aecc:3637:dc7c]) by smtp.gmail.com with ESMTPSA id 64sm865636eda.85.2020.06.03.02.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2020 02:20:23 -0700 (PDT) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, beanhuo@outlook.com Subject: [RESENT PATCH v5 5/5] scsi: ufs: add compatibility with 3.1 UFS unit descriptor length Date: Wed, 3 Jun 2020 11:19:59 +0200 Message-Id: <20200603091959.27618-6-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200603091959.27618-1-huobean@gmail.com> References: <20200603091959.27618-1-huobean@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo For UFS 3.1, the normal unit descriptor is 10 bytes larger than the RPMB unit, however, both descriptors share the same desc_idn, to cover both unit descriptors with one length, we choose the normal unit descriptor length by desc_index. Signed-off-by: Bean Huo Reviewed-by: Avri Altman --- drivers/scsi/ufs/ufs.h | 1 + drivers/scsi/ufs/ufshcd.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index 8770255b5dc0..250e1a905a14 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -63,6 +63,7 @@ #define UFS_UPIU_MAX_UNIT_NUM_ID 0x7F #define UFS_MAX_LUNS (SCSI_W_LUN_BASE + UFS_UPIU_MAX_UNIT_NUM_ID) #define UFS_UPIU_WLUN_ID (1 << 7) +#define UFS_RPMB_UNIT 0xC4 /* WriteBooster buffer is available only for the logical unit from 0 to 7 */ #define UFS_UPIU_MAX_WB_LUN_ID 8 diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 5ad0eebccc98..f283b9eb97ac 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3070,11 +3070,16 @@ void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, EXPORT_SYMBOL(ufshcd_map_desc_id_to_length); static void ufshcd_update_desc_length(struct ufs_hba *hba, - enum desc_idn desc_id, + enum desc_idn desc_id, int desc_index, unsigned char desc_len) { if (hba->desc_size[desc_id] == QUERY_DESC_MAX_SIZE && - desc_id != QUERY_DESC_IDN_STRING) + desc_id != QUERY_DESC_IDN_STRING && desc_index != UFS_RPMB_UNIT) + /* For UFS 3.1, the normal unit descriptor is 10 bytes larger + * than the RPMB unit, however, both descriptors share the same + * desc_idn, to cover both unit descriptors with one length, we + * choose the normal unit descriptor length by desc_index. + */ hba->desc_size[desc_id] = desc_len; } @@ -3143,7 +3148,7 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, /* Update descriptor length */ buff_len = desc_buf[QUERY_DESC_LENGTH_OFFSET]; - ufshcd_update_desc_length(hba, desc_id, buff_len); + ufshcd_update_desc_length(hba, desc_id, desc_index, buff_len); /* Check wherher we will not copy more data, than available */ if (is_kmalloc && (param_offset + param_size) > buff_len)