scsi: ufs: revamp string descriptor reading
PATCH 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.
--- 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
@@ -543,7 +543,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
@@ -880,14 +880,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.19.2
Hello Tomas,
Quoted 6 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]>
Just one nit - doesn't really matters.
Cheers,
Avri
drivers/scsi/ufs/ufshcd.c static int ufshcd_probe_hba(struct ufs_hba *hba) · line 6850
Quoted 11 lines
--- 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/ufshcd.c +1
-0ufs_fixup_device_setup (hba, &card); +ufs_put_device_desc (&card);
ufs_get_device_desc() and ufs_put_device_desc() actually serves the quirks setup. Make sense to call it from within so the logic is clear and in one place. Might also save ufs_put_device_desc().
Quoted 39 lines
-----Original Message-----
From: Avri Altman [mailto:[email protected]]
Sent: Tuesday, December 11, 2018 18:18
To: Winkler, Tomas <[email protected]>; James E . J . Bottomley <[email protected]>; Martin K . Petersen <[email protected]>; Vinayak Holikatti <[email protected]>; Hunter, Adrian <[email protected]>
Cc: Christoph Hellwig <[email protected]>; Vivek Gautam <[email protected]>; Subhash Jadavani <[email protected]>; Alex Lemberg <[email protected]>; linux- [email protected]; [email protected]
Subject: RE: [PATCH] scsi: ufs: revamp string descriptor readingHello Tomas,
Quoted 6 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]>Just one nit - doesn't really matters.
Cheers,
AvriQuoted 9 lines
--- 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(-)
Quoted 6 lines
drivers/scsi/ufs/ufshcd.c static int ufshcd_probe_hba(struct ufs_hba *hba) · line 6850
Quoted 2 lines
drivers/scsi/ufs/ufshcd.c +1
-0ufs_fixup_device_setup (hba, &card); +ufs_put_device_desc (&card);
ufs_get_device_desc()andufs_put_device_desc()actually serves the quirks setup.
Make sense to call it from within so the logic is clear and in one place. Might also saveufs_put_device_desc().
You are right from the current perspective , just I'd need it also for the RPMB patches that should follow, then it will have bit larger span than the quirks.
Thanks
Tomas
Quoted 31 lines
Quoted 24 lines
Hello Tomas,
Quoted 6 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]>Just one nit - doesn't really matters.
Cheers,
AvriQuoted 9 lines
--- 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(-)Quoted 6 lines
drivers/scsi/ufs/ufshcd.c static int ufshcd_probe_hba(struct ufs_hba *hba) · line 6850
Quoted 2 lines
drivers/scsi/ufs/ufshcd.c +1
-0ufs_fixup_device_setup (hba, &card); +ufs_put_device_desc (&card);
ufs_get_device_desc()andufs_put_device_desc()actually serves the quirks setup.
Make sense to call it from within so the logic is clear and in one place. Might also saveufs_put_device_desc().
Quoted 3 lines
You are right from the current perspective , just I'd need it also for the RPMB patches that should follow, then it will have bit larger span than the quirks.
Is this okay, can we merge?
Thanks
Tomas
Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
Hello Tomas,
Quoted 6 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]>Just one nit - doesn't really matters.
Cheers,
Avridrivers/scsi/ufs/ufshcd.c static int ufshcd_probe_hba(struct ufs_hba *hba) · line 6850
Quoted 11 lines
--- 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/ufshcd.c +1
-0ufs_fixup_device_setup (hba, &card); +ufs_put_device_desc (&card);
ufs_get_device_desc()andufs_put_device_desc()actually serves the quirks setup.
Make sense to call it from within so the logic is clear and in one place. Might also saveufs_put_device_desc().
Quoted 6 lines
Quoted 1 line
You are right from the current perspective , just I'd need it also for the
RPMB
Quoted 2 lines
patches that should follow, then it will have bit larger span than the quirks.
Is this okay, can we merge?
Looks good to me.
Thanks,
Avri
Quoted 2 lines
Thanks
Tomas