Skip to content

Commit bde44bb

Browse files
subhashj@codeaurora.orgmartinkpetersen
authored andcommitted
scsi: ufs: fix failure to read the string descriptor
While reading variable size descriptors (like string descriptor), some UFS devices may report the "LENGTH" (field in "Transaction Specific fields" of Query Response UPIU) same as what was requested in Query Request UPIU instead of reporting the actual size of the variable size descriptor. Although it's safe to ignore the "LENGTH" field for variable size descriptors as we can always derive the length of the descriptor from the descriptor header fields. Hence this change impose the length match check only for fixed size descriptors (for which we always request the correct size as part of Query Request UPIU). Reviewed-by: Venkat Gopalakrishnan <[email protected]> Signed-off-by: Subhash Jadavani <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 24d6243 commit bde44bb

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

drivers/scsi/ufs/ufshcd.c

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,16 +2108,38 @@ static int ufshcd_read_desc_param(struct ufs_hba *hba,
21082108
desc_id, desc_index, 0, desc_buf,
21092109
&buff_len);
21102110

2111-
if (ret || (buff_len < ufs_query_desc_max_size[desc_id]) ||
2112-
(desc_buf[QUERY_DESC_LENGTH_OFFSET] !=
2113-
ufs_query_desc_max_size[desc_id])
2114-
|| (desc_buf[QUERY_DESC_DESC_TYPE_OFFSET] != desc_id)) {
2115-
dev_err(hba->dev, "%s: Failed reading descriptor. desc_id %d, param_offset %d, buff_len %d ,index %d, ret %d",
2116-
__func__, desc_id, param_offset, buff_len,
2117-
desc_index, ret);
2118-
if (!ret)
2119-
ret = -EINVAL;
2111+
if (ret) {
2112+
dev_err(hba->dev, "%s: Failed reading descriptor. desc_id %d, desc_index %d, param_offset %d, ret %d",
2113+
__func__, desc_id, desc_index, param_offset, ret);
2114+
2115+
goto out;
2116+
}
2117+
2118+
/* Sanity check */
2119+
if (desc_buf[QUERY_DESC_DESC_TYPE_OFFSET] != desc_id) {
2120+
dev_err(hba->dev, "%s: invalid desc_id %d in descriptor header",
2121+
__func__, desc_buf[QUERY_DESC_DESC_TYPE_OFFSET]);
2122+
ret = -EINVAL;
2123+
goto out;
2124+
}
21202125

2126+
/*
2127+
* While reading variable size descriptors (like string descriptor),
2128+
* some UFS devices may report the "LENGTH" (field in "Transaction
2129+
* Specific fields" of Query Response UPIU) same as what was requested
2130+
* in Query Request UPIU instead of reporting the actual size of the
2131+
* variable size descriptor.
2132+
* Although it's safe to ignore the "LENGTH" field for variable size
2133+
* descriptors as we can always derive the length of the descriptor from
2134+
* the descriptor header fields. Hence this change impose the length
2135+
* match check only for fixed size descriptors (for which we always
2136+
* request the correct size as part of Query Request UPIU).
2137+
*/
2138+
if ((desc_id != QUERY_DESC_IDN_STRING) &&
2139+
(buff_len != desc_buf[QUERY_DESC_LENGTH_OFFSET])) {
2140+
dev_err(hba->dev, "%s: desc_buf length mismatch: buff_len %d, buff_len(desc_header) %d",
2141+
__func__, buff_len, desc_buf[QUERY_DESC_LENGTH_OFFSET]);
2142+
ret = -EINVAL;
21212143
goto out;
21222144
}
21232145

0 commit comments

Comments
 (0)