Skip to contentSkip to conversation

scsi: ufs: revamp string descriptor reading

PATCH Applied Tomas Winkler 2 participants 2 messages Jul 30, 2019 – Aug 8, 2019 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi: ufs: revamp string descriptor reading

Define new a type: uc_string_id for easier string handling and less casting. Reduce number or string copies in price of a dynamic allocation.

---
V2:
a. Use u8 instead of char as result string is utf8 b. In ufshcd_read_desc_param() keep buffer typed u8*

 drivers/scsi/ufs/ufs-sysfs.c |  18 ++--
 drivers/scsi/ufs/ufs.h       |   2 +-
 drivers/scsi/ufs/ufshcd.c    | 162 +++++++++++++++++++++--------------
 drivers/scsi/ufs/ufshcd.h    |   7 +-
 4 files changed, 112 insertions(+), 77 deletions(-)
drivers/scsi/ufs/ufs-sysfs.c +9 -9
index f478685122ff..969a36b15897 100644
@@ -571,9 +571,10 @@ static ssize_t _name##_show(struct device *dev,				\
 	int ret;							\
 	int desc_len = QUERY_DESC_MAX_SIZE;				\
 	u8 *desc_buf;							\
+									\
 	desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_ATOMIC);		\
-	if (!desc_buf)							\
-		return -ENOMEM;						\
+	if (!desc_buf)                                                  \
+		return -ENOMEM;                                         \
 	ret = ufshcd_query_descriptor_retry(hba,			\
 		UPIU_QUERY_OPCODE_READ_DESC, QUERY_DESC_IDN_DEVICE,	\
 		0, 0, desc_buf, &desc_len);				\
@@ -582,14 +583,13 @@ static ssize_t _name##_show(struct device *dev,				\
 		goto out;						\
 	}								\
 	index = desc_buf[DEVICE_DESC_PARAM##_pname];			\
-	memset(desc_buf, 0, QUERY_DESC_MAX_SIZE);			\
-	if (ufshcd_read_string_desc(hba, index, desc_buf,		\
-		QUERY_DESC_MAX_SIZE, true)) {				\
-		ret = -EINVAL;						\
+	kfree(desc_buf);						\
+	desc_buf = NULL;						\
+	ret = ufshcd_read_string_desc(hba, index, &desc_buf,		\
+				      SD_ASCII_STD);			\
+	if (ret < 0)							\
 		goto out;						\
-	}								\
-	ret = snprintf(buf, PAGE_SIZE, "%s\n",				\
-		desc_buf + QUERY_DESC_HDR_SIZE);			\
+	ret = snprintf(buf, PAGE_SIZE, "%s\n", desc_buf);		\
 out:									\
 	kfree(desc_buf);						\
 	return ret;							\
drivers/scsi/ufs/ufs.h +1 -1
index 99a9c4d16f6b..3327981ef894 100644
@@ -541,7 +541,7 @@ struct ufs_dev_info {
  */
 struct ufs_dev_desc {
 	u16 wmanufacturerid;
-	char model[MAX_MODEL_LEN + 1];
+	u8 *model;
 };
 
 /**
drivers/scsi/ufs/ufshcd.c +97 -65

242 lines not on this page · raw message

drivers/scsi/ufs/ufshcd.h +5 -2
index a43c7135f33d..9f61550abc7f 100644
@@ -913,8 +913,11 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
 		      enum attr_idn idn, u8 index, u8 selector, u32 *attr_val);
 int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
 	enum flag_idn idn, bool *flag_res);
-int ufshcd_read_string_desc(struct ufs_hba *hba, int desc_index,
-			    u8 *buf, u32 size, bool ascii);
+
+#define SD_ASCII_STD true
+#define SD_RAW false
+int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
+			    u8 **buf, bool ascii);
 
 int ufshcd_hold(struct ufs_hba *hba, bool async);
 void ufshcd_release(struct ufs_hba *hba);
Signature · 1 line
2.20.1
#1 lore raw

Tomas,

Quoted 3 lines

Define new a type: uc_string_id for easier string handling and less casting. Reduce number or string copies in price of a dynamic allocation.

Applied to 5.4/scsi-queue. Thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering