Re: [PATCH v2] scsi: ufs: sysfs: Print string descriptors as raw data

From: Bart Van Assche
Date: Tue Mar 16 2021 - 23:32:10 EST


On 2/15/21 9:40 AM, Arthur Simchaev wrote:
> -#define UFS_STRING_DESCRIPTOR(_name, _pname) \
> +#define UFS_STRING_DESCRIPTOR(_name, _pname, _is_ascii) \
> static ssize_t _name##_show(struct device *dev, \
> struct device_attribute *attr, char *buf) \
> { \
> @@ -690,10 +690,18 @@ static ssize_t _name##_show(struct device *dev, \
> kfree(desc_buf); \
> desc_buf = NULL; \
> ret = ufshcd_read_string_desc(hba, index, &desc_buf, \
> - SD_ASCII_STD); \
> + _is_ascii); \
> if (ret < 0) \
> goto out; \
> - ret = sysfs_emit(buf, "%s\n", desc_buf); \
> + if (_is_ascii) { \
> + ret = sysfs_emit(buf, "%s\n", desc_buf); \
> + } else { \
> + int i; \
> + \
> + for (i = 0; i < desc_buf[0]; i++) \
> + hex_byte_pack(buf + i * 2, desc_buf[i]); \
> + ret = sysfs_emit(buf, "%s\n", buf); \
> + } \
> out: \
> pm_runtime_put_sync(hba->dev); \
> kfree(desc_buf); \

Hex data needs to be parsed before it can be used by any software. Has
it been considered to make the "raw" attributes binary attributes
instead of hex-encoded binary? See also sysfs_create_bin_file().

Thanks,

Bart.