Skip to content

Commit 0d9a708

Browse files
beanhuomartinkpetersen
authored andcommitted
scsi: ufs: core: Convert string descriptor format macros to enum
Convert SD_ASCII_STD and SD_RAW from boolean macros to enum values for improved code readability. This makes ufshcd_read_string_desc() calls self-documenting by using explicit enum values instead of true/false. Move the ufshcd_read_string_desc() declaration from include/ufs/ufshcd.h to drivers/ufs/core/ufshcd-priv.h since this function is not exported. Co-developed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Bart Van Assche <bvanassche@acm.org> Suggested-by: Avri Altman <Avri.Altman@sandisk.com> Signed-off-by: Bean Huo <beanhuo@micron.com> Link: https://patch.msgid.link/20251107230518.4060231-2-beanhuo@iokpp.de Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 211ddde commit 0d9a708

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

drivers/ufs/core/ufshcd-priv.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag);
7878
void ufshcd_release_scsi_cmd(struct ufs_hba *hba,
7979
struct ufshcd_lrb *lrbp);
8080

81-
#define SD_ASCII_STD true
82-
#define SD_RAW false
83-
int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
84-
u8 **buf, bool ascii);
81+
/**
82+
* enum ufs_descr_fmt - UFS string descriptor format
83+
* @SD_RAW: Raw UTF-16 format
84+
* @SD_ASCII_STD: Convert to null-terminated ASCII string
85+
*/
86+
enum ufs_descr_fmt {
87+
SD_RAW = 0,
88+
SD_ASCII_STD = 1,
89+
};
8590

91+
int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, enum ufs_descr_fmt fmt);
8692
int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd);
8793
int ufshcd_send_bsg_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd);
8894

drivers/ufs/core/ufshcd.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3773,16 +3773,14 @@ static inline char ufshcd_remove_non_printable(u8 ch)
37733773
* @desc_index: descriptor index
37743774
* @buf: pointer to buffer where descriptor would be read,
37753775
* the caller should free the memory.
3776-
* @ascii: if true convert from unicode to ascii characters
3777-
* null terminated string.
3776+
* @fmt: if %SD_ASCII_STD, convert from UTF-16 to ASCII
37783777
*
37793778
* Return:
37803779
* * string size on success.
37813780
* * -ENOMEM: on allocation failure
37823781
* * -EINVAL: on a wrong parameter
37833782
*/
3784-
int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
3785-
u8 **buf, bool ascii)
3783+
int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, enum ufs_descr_fmt fmt)
37863784
{
37873785
struct uc_string_id *uc_str;
37883786
u8 *str;
@@ -3811,7 +3809,7 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
38113809
goto out;
38123810
}
38133811

3814-
if (ascii) {
3812+
if (fmt == SD_ASCII_STD) {
38153813
ssize_t ascii_len;
38163814
int i;
38173815
/* remove header and divide by 2 to move from UTF16 to UTF8 */

include/ufs/ufshcd.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,10 +1431,6 @@ static inline int ufshcd_disable_host_tx_lcc(struct ufs_hba *hba)
14311431
void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);
14321432
void ufshcd_fixup_dev_quirks(struct ufs_hba *hba,
14331433
const struct ufs_dev_quirk *fixups);
1434-
#define SD_ASCII_STD true
1435-
#define SD_RAW false
1436-
int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
1437-
u8 **buf, bool ascii);
14381434

14391435
void ufshcd_hold(struct ufs_hba *hba);
14401436
void ufshcd_release(struct ufs_hba *hba);

0 commit comments

Comments
 (0)