scsi: ufs: revamp string descriptor reading
PATCH RESEND 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.
---
Resend: It was reviewed by not merged.
drivers/scsi/ufs/ufs-sysfs.c | 20 ++--- drivers/scsi/ufs/ufs.h | 2 +- drivers/scsi/ufs/ufshcd.c | 164 +++++++++++++++++++++-------------- drivers/scsi/ufs/ufshcd.h | 9 +- 4 files changed, 115 insertions(+), 80 deletions(-)
drivers/scsi/ufs/ufs-sysfs.c +10 -10
@@ -570,10 +570,11 @@ static ssize_t _name##_show(struct device *dev, \struct ufs_hba *hba =dev_get_drvdata (dev); \int ret; \int desc_len =QUERY_DESC_MAX_SIZE ; \ -u8 *desc_buf; \ +char *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
@@ -541,7 +541,7 @@ struct ufs_dev_info {*/ struct ufs_dev_desc {u16 wmanufacturerid; -char model[MAX_MODEL_LEN +1 ]; +char *model; };/**
drivers/scsi/ufs/ufshcd.c +98 -66
250 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +6 -3
@@ -885,14 +885,17 @@ int ufshcd_read_desc_param(struct ufs_hba *hba,enum desc_idn desc_id, int desc_index, u8 param_offset, - u8 *param_read_buf, + void *param_read_buf, u8 param_size);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, +char **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
Hi Tomas,
Quoted 22 lines
Define new a type:
uc_string_idfor easier string handling and less casting. Reduce number or string copies in price of a dynamic allocation.Signed-off-by Tomas Winkler <[email protected]>Tested-by Avri Altman <[email protected]>---
Resend: It was reviewed by not merged.
drivers/scsi/ufs/ufs-sysfs.c | 20 ++--- drivers/scsi/ufs/ufs.h | 2 +- drivers/scsi/ufs/ufshcd.c | 164 +++++++++++++++++++++-------------- drivers/scsi/ufs/ufshcd.h | 9 +- 4 files changed, 115 insertions(+), 80 deletions(-)drivers/scsi/ufs/ufs-sysfs.c +0
-0
drivers/scsi/ufs/ufs-sysfs.c static ssize_t _name##_show(struct device *dev, · line 575
Quoted 7 lines
drivers/scsi/ufs/ufs-sysfs.c +2
-1@@ -570,10 +570,11 @@ static ssize_t _name##_show(struct device *dev, \struct ufs_hba *hba =dev_get_drvdata (dev); \int ret; \int desc_len =QUERY_DESC_MAX_SIZE ; \ -u8 *desc_buf; \ +char *desc_buf; \ + \
Leaving it a u8 * here, will assure it would be utf-8, And save you making param_read_buf opaque,
in ufshcd_read_desc and ufshcd_read_desc_param. A fare tradeoff, don't you think?
drivers/scsi/ufs/ufs.h struct ufs_dev_info { · line 545
Quoted 11 lines
drivers/scsi/ufs/ufs.h +1
-1@@ -541,7 +541,7 @@ struct ufs_dev_info {*/ struct ufs_dev_desc {u16 wmanufacturerid; -char model[MAX_MODEL_LEN +1 ]; +char *model; };
Belongs to a different patch?
Quoted 10 lines
drivers/scsi/ufs/ufs.h +0
-0/** * ufshcd_read_string_desc - read string descriptor * @hba: pointer to adapter instance
* @desc_index: descriptor index
- * @buf: pointer to buffer where descriptor would be read
- * @size: size of buf
+ * @buf: pointer to buffer where descriptor would be read,
+ * the caller should free the memory.
* @ascii: if true convert from unicode to ascii characters
+ * null terminated string.
Since ascii is always true, maybe omit this argument altogether, and group the if (asci) clause in some handler?
drivers/scsi/ufs/ufs.h static int ufs_get_device_desc(struct ufs_hba · line 6484
Quoted 9 lines
/**
drivers/scsi/ufs/ufs.h +3
-0@@ -6452,6 +6478,9 @@ static int ufs_get_device_desc(struct ufs_hba *hba, u8 model_index;u8 *desc_buf; +if (!dev_desc) +return -EINVAL ; +
A different patch?
drivers/scsi/ufs/ufs.h static int ufs_get_device_desc(struct ufs_hba
Quoted 6 lines
drivers/scsi/ufs/ufs.h +5
-0+static void ufs_put_device_desc (struct ufs_dev_desc *dev_desc) +{ +kfree (dev_desc->model); + dev_desc->model =NULL ; +}
A different patch?
While it's true that dev_desc->model conclude its part after ufs_fixup_device_setup, Why are you releasing specifically this part of card?
drivers/scsi/ufs/ufs.h
Quoted 3 lines
drivers/scsi/ufs/ufs.h +1
-0ufs_fixup_device_setup (hba, &card); +ufs_put_device_desc (&card);
A different patch?
Quoted 16 lines
drivers/scsi/ufs/ufs.h +1
-0+ufshcd_tune_unipro_params (hba);/* UFS device is also active now */ drivers/scsi/ufs/ufshcd.h +1
-1@@ -885,14 +885,17 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, enum desc_idn desc_id, int desc_index, u8 param_offset, - u8 *param_read_buf, + void *param_read_buf, u8 param_size);
drivers/scsi/ufs/ufshcd.h int ufshcd_read_desc_param(struct ufs_hba · line 898
Quoted 10 lines
drivers/scsi/ufs/ufshcd.h +3
-2int 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
Not really needed?
Thanks,
Avri