From patchwork Sun Nov 27 12:08:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Simchaev X-Patchwork-Id: 628950 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C20E2C4321E for ; Sun, 27 Nov 2022 12:08:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229657AbiK0MIr (ORCPT ); Sun, 27 Nov 2022 07:08:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229683AbiK0MIm (ORCPT ); Sun, 27 Nov 2022 07:08:42 -0500 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE42F58D; Sun, 27 Nov 2022 04:08:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1669550921; x=1701086921; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=SUE566R94CnqYxmANcyAUdfEbOCvEF2a7+p3jOhVJKs=; b=b0CVcw1KF3O9Ci9n8C04GM9ysIrHGsD9TdHLNQVSS/nU2V6apyrT0g9Z +rcwNqMwQU2JsWNuq0PUPieUkQKkugmQWFnd1SUlMY6AHmqW/zq2AkjL7 o6/dNmoeKh8HZ8aYG5rNXrxxd98dy/6lzW99q0AHQnbl+lC34yvqSjNxi ywZcLyr2Rm7R5RIcafZOGL48ZGxFfHZEt6fIUsLN9kKETsCsboo2AecJy FB1wxUBnLNZC5RMB/c1gGwnK5V9iSc6c/Kywdtr0ZergqR4ilz078Myd9 1h53S4DdmhbN81BbnnsteLHgd5vPkGDXeQGP7WNB1WZUqtrYOsqvQjfnb A==; X-IronPort-AV: E=Sophos;i="5.96,198,1665417600"; d="scan'208";a="215510881" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 Nov 2022 20:08:41 +0800 IronPort-SDR: VzdkvOlbXOC1XsfpcLqtrrdJ6/6qPlZUm/EfHw5LKzWPwpipkgLk92/j4w8DLD8Hub/7tIvYoV YuBvlOP4S7bJ6eE+pAGez2B7GqyAceSWp6GhVlf95iJCl8cNGuk8JDk0sYHheJns7NQmbgAjyP HPtNZi4HTlpA/uEOPrkjyY3BOa/OneQxAQ7aSgdEarmMYmTNY/GdoIHUawEnsKipm1bem9JQ0+ blQ7rZ8IYMLq7jiHEcYYa37tNSc4lsu3U0ADyj+m1zcuIwmWC89wgasDWEvgMsJVFqwVWEVkpq A0k= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Nov 2022 03:27:24 -0800 IronPort-SDR: spoPjWjffvUZwCkJjwwqZVcZC8C9hZNxLmk1Iq4k7uO2smqRC5br/lYolW9kZiqnb2+GLMMQJt dJCqQuZDJx8TbtN1NHLbtzjlDkdZEWyNICjwJViuwUUlYHNjsOS60XnBT8hKs6wYy/W0aRmDJy 88SfXLPrVTPiw3JQ5i9V+wDNYk/u1tqAeWYEfO7+kBmIeMRFatRmQrzWFxAqlgWgX9a58Y+Lf8 Diad3+j9kDuDsI2J3/jllODN9V+IIqPydNNAfcNTmbNpj7kF6xJug0wPSuaZGj/L6qdPfc3a8D Z4s= WDCIronportException: Internal Received: from ilb001078.ad.shared (HELO ilb001078.sdcorp.global.sandisk.com) ([10.45.31.219]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Nov 2022 04:08:39 -0800 From: Arthur Simchaev To: martin.petersen@oracle.com Cc: beanhuo@micron.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Arthur Simchaev Subject: [PATCH v4 2/4] ufs: core: Remove redundant desc_size variable from hba Date: Sun, 27 Nov 2022 14:08:28 +0200 Message-Id: <1669550910-9672-3-git-send-email-Arthur.Simchaev@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1669550910-9672-1-git-send-email-Arthur.Simchaev@wdc.com> References: <1669550910-9672-1-git-send-email-Arthur.Simchaev@wdc.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Always read the descriptor with QUERY_DESC_MAX_SIZE. According to the spec, the device returns the actual size Reviewed-by: Bean Huo Signed-off-by: Arthur Simchaev --- drivers/ufs/core/ufshcd.c | 53 +++++++++++++---------------------------------- include/ufs/ufs.h | 1 - include/ufs/ufshcd.h | 1 - 3 files changed, 14 insertions(+), 41 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 2e47c69..70e96b6 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -3377,28 +3377,11 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba, void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, int *desc_len) { - if (desc_id >= QUERY_DESC_IDN_MAX || desc_id == QUERY_DESC_IDN_RFU_0 || - desc_id == QUERY_DESC_IDN_RFU_1) - *desc_len = 0; - else - *desc_len = hba->desc_size[desc_id]; + /*Always returns QUERY_DESC_MAX_SIZE*/ + *desc_len = QUERY_DESC_MAX_SIZE; } EXPORT_SYMBOL(ufshcd_map_desc_id_to_length); -static void ufshcd_update_desc_length(struct ufs_hba *hba, - 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_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; -} - /** * ufshcd_read_desc_param - read the specified descriptor parameter * @hba: Pointer to adapter instance @@ -3470,7 +3453,6 @@ 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, desc_index, buff_len); if (is_kmalloc) { /* Make sure we don't copy more data than available */ @@ -4909,7 +4891,7 @@ static void ufshcd_setup_links(struct ufs_hba *hba, struct scsi_device *sdev) */ static void ufshcd_lu_init(struct ufs_hba *hba, struct scsi_device *sdev) { - int len = hba->desc_size[QUERY_DESC_IDN_UNIT]; + int len = QUERY_DESC_MAX_SIZE; u8 lun = ufshcd_scsi_to_upiu_lun(sdev->lun); u8 lun_qdepth = hba->nutrs; u8 *desc_buf; @@ -7480,25 +7462,24 @@ 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[QUERY_DESC_IDN_POWER]; u8 *desc_buf; u32 icc_level; - desc_buf = kmalloc(buff_len, GFP_KERNEL); + desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL); if (!desc_buf) return; ret = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_POWER, 0, 0, - desc_buf, buff_len); + desc_buf, QUERY_DESC_MAX_SIZE); if (ret) { dev_err(hba->dev, - "%s: Failed reading power descriptor.len = %d ret = %d", - __func__, buff_len, ret); + "%s: Failed reading power descriptor ret = %d", + __func__, ret); goto out; } icc_level = ufshcd_find_max_sup_active_icc_level(hba, desc_buf, - buff_len); + QUERY_DESC_MAX_SIZE); dev_dbg(hba->dev, "%s: setting icc_level 0x%x", __func__, icc_level); ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR, @@ -7715,14 +7696,14 @@ static int ufs_get_device_desc(struct ufs_hba *hba) u8 *desc_buf; struct ufs_dev_info *dev_info = &hba->dev_info; - desc_buf = kmalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL); + desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL); if (!desc_buf) { err = -ENOMEM; goto out; } err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_DEVICE, 0, 0, desc_buf, - hba->desc_size[QUERY_DESC_IDN_DEVICE]); + QUERY_DESC_MAX_SIZE); if (err) { dev_err(hba->dev, "%s: Failed reading Device Desc. err = %d\n", __func__, err); @@ -7969,18 +7950,16 @@ static void ufshcd_clear_dbg_ufs_stats(struct ufs_hba *hba) 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[QUERY_DESC_IDN_GEOMETRY]; - desc_buf = kmalloc(buff_len, GFP_KERNEL); + desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL); if (!desc_buf) { err = -ENOMEM; goto out; } err = ufshcd_read_desc_param(hba, QUERY_DESC_IDN_GEOMETRY, 0, 0, - desc_buf, buff_len); + desc_buf, QUERY_DESC_MAX_SIZE); if (err) { dev_err(hba->dev, "%s: Failed reading Geometry Desc. err = %d\n", __func__, err); @@ -7992,7 +7971,7 @@ static int ufshcd_device_geo_params_init(struct ufs_hba *hba) else if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN] == 0) hba->dev_info.max_lu_supported = 8; - if (hba->desc_size[QUERY_DESC_IDN_GEOMETRY] >= + if (desc_buf[QUERY_DESC_LENGTH_OFFSET] >= GEOMETRY_DESC_PARAM_HPB_MAX_ACTIVE_REGS) ufshpb_get_geo_info(hba, desc_buf); @@ -8077,11 +8056,7 @@ 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, i; - - /* Init device descriptor sizes */ - for (i = 0; i < QUERY_DESC_IDN_MAX; i++) - hba->desc_size[i] = QUERY_DESC_MAX_SIZE; + int ret; /* Init UFS geometry descriptor related parameters */ ret = ufshcd_device_geo_params_init(hba); diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h index 1bba3fe..2fc7107 100644 --- a/include/ufs/ufs.h +++ b/include/ufs/ufs.h @@ -38,7 +38,6 @@ #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/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index 5cf81df..7df2ce1 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -952,7 +952,6 @@ struct ufs_hba { bool is_urgent_bkops_lvl_checked; struct rw_semaphore clk_scaling_lock; - unsigned char desc_size[QUERY_DESC_IDN_MAX]; atomic_t scsi_block_reqs_cnt; struct device bsg_dev; From patchwork Sun Nov 27 12:08:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Simchaev X-Patchwork-Id: 628949 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1544EC46467 for ; Sun, 27 Nov 2022 12:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbiK0MIz (ORCPT ); Sun, 27 Nov 2022 07:08:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiK0MIt (ORCPT ); Sun, 27 Nov 2022 07:08:49 -0500 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40997F59A; Sun, 27 Nov 2022 04:08:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1669550926; x=1701086926; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=AcrYLNFC69GBpZDau/GkN2EkK6yLdYoD4nEUN+JjbNA=; b=Nm6eriDpRVTvCq8Sb726O8TgZLuWYIUM3Nm/lXif/9RLqAzCBl7u6I8g qOxQKxxRPYtZG3XoeOiVdGowx2RZEs0BNnsKxkek/HGD+Rj8zt5da6Q0g aSFOwr4PgGqKaINKErL0c9fNE3ikfUh3CamH+GZ5Vt1VL60hOvQrAOdJ1 69tFD4+ZI3IHz3FSvMVg8AT3Bvp72FRRCe/G4c+E5iEW4McyyUpSrDDll wWY3CLh3sl8jHH7PhHriOjMZU+wiFoeAOd3vcz8g+nVFkO0Mb9IRy0ddC 1XJEN463J3/RQkbYQNcj3APMnliobhwTvtLPbWRMKBh5ftwagTbsHusEr Q==; X-IronPort-AV: E=Sophos;i="5.96,198,1665417600"; d="scan'208";a="215510895" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 Nov 2022 20:08:46 +0800 IronPort-SDR: yCGUKLzBNJPFHAfRn0uD3UjUUUg0gb+SK0ZX9hyMaB0iBpWP9L33isOP9j8quaXcrhvq0LrQ4f YC7Kvd1oiS7fYu7oDsghZtRLG8X5+6ueDXKZHkCVwz7Ikh4APF9fIHOe6Wi0CyfbMcwIjDaH8S nQwrXJdrGX64gw8JsXkTjAaMOnsBqxTuqwx4Wr+xuvyPtxGmvoPg6QddipCU8OIZzFaNWiLC/M sTJ+Qg1cwOH5kidUUr054BDUoTRHFA+8XQdqki0yGuztsZoBnJDBWVHSiBdFSj2uN29Aq9O9Tb y9s= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Nov 2022 03:27:29 -0800 IronPort-SDR: pRRi84UOocDVSbZEdDbvvWhI+wjFHAm0qbN4fEFSnj0Qd9Gi7hwEkeOMv3HAae01DkQmge1Z+d Gq0xHM1r66Tr+pol+z+2K6j9m/LBuU6XKGqDv+sMikkdi7tR+eK2EtSwIq35zOBkWbWh5LOwAD Ubu62QcDkuOuYKxlo5T4A1inmeCeFLU/PqGnbtDMtrGGw6U9NypDcHClHQ9a6raAOVoKVORPKm hsn4Z3FANqCj/PjG4UYPPg6VE5KUB5y8NEvkVS3tQXUPc+zDg9h01891WD6m0QFVWFCqY9eyc8 5CY= WDCIronportException: Internal Received: from ilb001078.ad.shared (HELO ilb001078.sdcorp.global.sandisk.com) ([10.45.31.219]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Nov 2022 04:08:44 -0800 From: Arthur Simchaev To: martin.petersen@oracle.com Cc: beanhuo@micron.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Arthur Simchaev Subject: [PATCH v4 4/4] ufs: core: Remove ufshcd_map_desc_id_to_length function Date: Sun, 27 Nov 2022 14:08:30 +0200 Message-Id: <1669550910-9672-5-git-send-email-Arthur.Simchaev@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1669550910-9672-1-git-send-email-Arthur.Simchaev@wdc.com> References: <1669550910-9672-1-git-send-email-Arthur.Simchaev@wdc.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org There shouldn't be any restriction of the descriptor size (not the descriptor id for that matter) up to QUERY_DESC_MAX_SIZE. According to the spec, the caller can use any descriptor size, and it is up to the device to return the actual size. Therefore there shouldn't be any sizes hardcoded in the kernel, nor any need to cache it, hence ufshcd_map_desc_id_to_length function is redundant. always read the descriptors with QUERY_DESC_MAX_SIZE size. Reviewed-by: Bean Huo Suggested-by: Bean Huo Signed-off-by: Arthur Simchaev --- drivers/ufs/core/ufs_bsg.c | 7 +------ drivers/ufs/core/ufshcd-priv.h | 3 --- drivers/ufs/core/ufshcd.c | 46 +++++++++++------------------------------- drivers/ufs/core/ufshpb.c | 4 +--- 4 files changed, 14 insertions(+), 46 deletions(-) diff --git a/drivers/ufs/core/ufs_bsg.c b/drivers/ufs/core/ufs_bsg.c index b99e3f3..dc441ac 100644 --- a/drivers/ufs/core/ufs_bsg.c +++ b/drivers/ufs/core/ufs_bsg.c @@ -16,16 +16,11 @@ static int ufs_bsg_get_query_desc_size(struct ufs_hba *hba, int *desc_len, struct utp_upiu_query *qr) { int desc_size = be16_to_cpu(qr->length); - int desc_id = qr->idn; if (desc_size <= 0) return -EINVAL; - 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); + *desc_len = min_t(int, QUERY_DESC_MAX_SIZE, desc_size); return 0; } diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index a9e8e1f..c52e2f3 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -70,9 +70,6 @@ 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); -void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, - int *desc_length); - int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd); int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 617c4e0..7f89626 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -3369,20 +3369,6 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba, } /** - * 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) - */ -void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, - int *desc_len) -{ - /*Always returns QUERY_DESC_MAX_SIZE*/ - *desc_len = QUERY_DESC_MAX_SIZE; -} -EXPORT_SYMBOL(ufshcd_map_desc_id_to_length); - -/** * ufshcd_read_desc_param - read the specified descriptor parameter * @hba: Pointer to adapter instance * @desc_id: descriptor idn value @@ -3402,26 +3388,13 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, { int ret; u8 *desc_buf; - int buff_len; + int buff_len = QUERY_DESC_MAX_SIZE; bool is_kmalloc = true; /* Safety check */ if (desc_id >= QUERY_DESC_IDN_MAX || !param_size) return -EINVAL; - /* 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\n", __func__); - return -EINVAL; - } - - if (param_offset >= buff_len) { - dev_err(hba->dev, "%s: Invalid offset 0x%x in descriptor IDN 0x%x, length 0x%x\n", - __func__, param_offset, desc_id, buff_len); - return -EINVAL; - } - /* Check whether we need temp memory */ if (param_offset != 0 || param_size < buff_len) { desc_buf = kzalloc(buff_len, GFP_KERNEL); @@ -3434,15 +3407,23 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, /* Request for full descriptor */ ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, - desc_id, desc_index, 0, - desc_buf, &buff_len); - + desc_id, desc_index, 0, + desc_buf, &buff_len); if (ret) { dev_err(hba->dev, "%s: Failed reading descriptor. desc_id %d, desc_index %d, param_offset %d, ret %d\n", __func__, desc_id, desc_index, param_offset, ret); goto out; } + /* Update descriptor length */ + buff_len = desc_buf[QUERY_DESC_LENGTH_OFFSET]; + + if (param_offset >= buff_len) { + dev_err(hba->dev, "%s: Invalid offset 0x%x in descriptor IDN 0x%x, length 0x%x\n", + __func__, param_offset, desc_id, buff_len); + return -EINVAL; + } + /* Sanity check */ if (desc_buf[QUERY_DESC_DESC_TYPE_OFFSET] != desc_id) { dev_err(hba->dev, "%s: invalid desc_id %d in descriptor header\n", @@ -3451,9 +3432,6 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, goto out; } - /* Update descriptor length */ - buff_len = desc_buf[QUERY_DESC_LENGTH_OFFSET]; - if (is_kmalloc) { /* Make sure we don't copy more data than available */ if (param_offset >= buff_len) diff --git a/drivers/ufs/core/ufshpb.c b/drivers/ufs/core/ufshpb.c index be3fb24..19c9b5d 100644 --- a/drivers/ufs/core/ufshpb.c +++ b/drivers/ufs/core/ufshpb.c @@ -2382,12 +2382,10 @@ static int ufshpb_get_lu_info(struct ufs_hba *hba, int lun, { u16 max_active_rgns; u8 lu_enable; - int size; + int size = QUERY_DESC_MAX_SIZE; int ret; char desc_buf[QUERY_DESC_MAX_SIZE]; - ufshcd_map_desc_id_to_length(hba, QUERY_DESC_IDN_UNIT, &size); - ufshcd_rpm_get_sync(hba); ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, QUERY_DESC_IDN_UNIT, lun, 0,