From 0122615a5e5956446458246dbc29abea3577460d Mon Sep 17 00:00:00 2001 From: Bean Huo Date: Wed, 2 Dec 2020 10:36:49 +0100 Subject: [PATCH 1/5] ufs-utils: fix configuration file size overflow issue After changeing the binary configuration image file, possibly, the size of configuration file will be one byte bigger than original size by using seek(). in this case, we choose QUERY_DESC_CONFIGURAION_MAX_SIZE as its length. Signed-off-by: Bean Huo --- ufs_cmds.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ufs_cmds.c b/ufs_cmds.c index 2e1a8a8..b1e35a2 100644 --- a/ufs_cmds.c +++ b/ufs_cmds.c @@ -806,6 +806,9 @@ static int do_conf_desc(int fd, __u8 opt, __u8 index, char *data_file) } lseek(data_fd, 0, SEEK_SET); + if (file_size > QUERY_DESC_CONFIGURAION_MAX_SIZE) + file_size = QUERY_DESC_CONFIGURAION_MAX_SIZE; + rc = read(data_fd, conf_desc_buf, file_size); if (rc <= 0) { print_error("Cannot config file"); From 90e786095e0177dbe124a4e5370757c71c2d18b0 Mon Sep 17 00:00:00 2001 From: Bean Huo Date: Wed, 2 Dec 2020 16:13:05 +0100 Subject: [PATCH 2/5] ufs-utils: fix unknow IDE issue while reading attribute descriptor IDE 01h in Atrributes is Reserved. Signed-off-by: Bean Huo --- ufs_cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ufs_cmds.c b/ufs_cmds.c index b1e35a2..fb03693 100644 --- a/ufs_cmds.c +++ b/ufs_cmds.c @@ -244,7 +244,7 @@ struct query_err_res { struct attr_fields ufs_attrs[] = { {"bBootLunEn", BYTE, (URD|UWRT), (READ_ONLY|WRITE_PRSIST), DEV}, - {"bMAX_DATA_SIZE_FOR_HPB_SINGLE_CMD", BYTE, URD, READ_ONLY, DEV}, + {ATTR_RSRV()}, {"bCurrentPowerMode", BYTE, URD, READ_ONLY, DEV}, {"bActiveICCLevel", BYTE, (URD|UWRT), (READ_NRML|WRITE_PRSIST), DEV}, {"bOutOfOrderDataEn", BYTE, (URD|UWRT), (READ_NRML|WRITE_ONCE), DEV}, From a0546c6151c345ec8986f300120761db2a099efa Mon Sep 17 00:00:00 2001 From: Bean Huo Date: Fri, 4 Dec 2020 11:55:22 +0100 Subject: [PATCH 3/5] ufs-utils: Fix invalid flag idn error Flags length has been changed, but we didn't update it in the verify_and_set_idn() Signed-off-by: Bean Huo --- options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options.c b/options.c index 79218cc..25e1a92 100644 --- a/options.c +++ b/options.c @@ -266,7 +266,7 @@ static int verify_and_set_idn(struct tool_options *options) } break; case FLAG_TYPE: - if (idn > QUERY_FLAG_IDN_PERMANENTLYDISABLEFW) { + if (idn > QUERY_FLAG_IDN_MAX) { print_error("Invalid flag idn %d", idn); goto out; } From 8eb983a4709594282b8a927a86b7127a5979dfb5 Mon Sep 17 00:00:00 2001 From: Bean Huo Date: Fri, 4 Dec 2020 12:46:37 +0100 Subject: [PATCH 4/5] ufs-utils: Fix Invalid Index error for Flags access WriteBooster related flags are an array of flags, add its index distinguish. Signed-off-by: Bean Huo --- ufs_cmds.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ufs_cmds.c b/ufs_cmds.c index fb03693..1d21f34 100644 --- a/ufs_cmds.c +++ b/ufs_cmds.c @@ -308,10 +308,10 @@ struct flag_fields ufs_flags[] = { {"fPermanentlyDisableFw", (URD|UWRT), (READ_NRML|WRITE_ONCE), DEV}, {"Reserved", ACC_INVALID, MODE_INVALID, LEVEL_INVALID}, /*D*/ {"Reserved", ACC_INVALID, MODE_INVALID, LEVEL_INVALID}, -/*E*/ {"fWriteBoosterEn", (URD|UWRT), (READ_NRML|WRITE_VLT), DEV}, -/*F*/ {"fWBFlushEn", (URD|UWRT), (READ_NRML|WRITE_VLT), DEV}, +/*E*/ {"fWriteBoosterEn", (URD|UWRT), (READ_NRML|WRITE_VLT), DEV | ARRAY}, +/*F*/ {"fWBFlushEn", (URD|UWRT), (READ_NRML|WRITE_VLT), DEV | ARRAY}, /*10h*/ {"fWBFlushDuringHibernate", (URD|UWRT), - (READ_NRML|WRITE_VLT), DEV}, + (READ_NRML|WRITE_VLT), DEV | ARRAY}, /*11h*/ {"fHPBReset", (URD|UWRT), (READ_NRML|SET_ONLY), DEV} }; @@ -1207,7 +1207,9 @@ int do_flags(struct tool_options *opt) rc = do_query_rq(fd, &bsg_req, &bsg_rsp, UPIU_QUERY_FUNC_STANDARD_READ_REQUEST, UPIU_QUERY_OPCODE_READ_FLAG, flag_idn, - opt->index, opt->selector, 0, 0, 0); + (tmp->device_level & ARRAY) ? + opt->index : 0, + opt->selector, 0, 0, 0); if (rc == OK) { printf("%-26s := 0x%01x\n", tmp->name, be32toh(bsg_rsp.upiu_rsp.qr.value) & From 9293f364fbe6aa87a7617af640e8c413b87d4e5f Mon Sep 17 00:00:00 2001 From: Bean Huo Date: Fri, 4 Dec 2020 13:06:59 +0100 Subject: [PATCH 5/5] ufs-utils: Fix Invalid Index error for Attributes access WriteBooster related attributes are an array of attributes, add its index distinguish. Signed-off-by: Bean Huo --- ufs_cmds.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ufs_cmds.c b/ufs_cmds.c index 1d21f34..f839e38 100644 --- a/ufs_cmds.c +++ b/ufs_cmds.c @@ -252,7 +252,7 @@ struct attr_fields ufs_attrs[] = { {"bPurgeStatus", BYTE, URD, READ_ONLY, DEV}, {"bMaxDataInSize", BYTE, (URD|UWRT), (READ_NRML|WRITE_PRSIST), DEV}, {"bMaxDataOutSize", BYTE, (URD|UWRT), (READ_NRML|WRITE_PRSIST), DEV}, - {"dDynCapNeeded", WORD, URD, READ_ONLY, DEV}, + {"dDynCapNeeded", WORD, URD, READ_ONLY, ARRAY}, {"bRefClkFreq", BYTE, (URD|UWRT), (READ_NRML|WRITE_PRSIST), DEV}, {"bConfigDescrLock", BYTE, (URD|UWRT), (READ_NRML|WRITE_ONCE), DEV}, {"bMaxNumOfRTT", BYTE, (URD|UWRT), (READ_NRML|WRITE_PRSIST), DEV}, @@ -271,10 +271,10 @@ struct attr_fields ufs_attrs[] = { {"bDeviceTooHighTempBoundary", BYTE, URD, READ_ONLY, DEV}, /*1A*/ {"bDeviceTooLowTempBoundary", BYTE, URD, READ_ONLY, DEV}, /*1B*/ {"bThrottlingStatus", BYTE, URD, READ_ONLY, DEV}, -/*1C*/ {"bWBBufFlushStatus", BYTE, URD, READ_ONLY, DEV}, -/*1D*/ {"bAvailableWBBufSize", BYTE, URD, READ_ONLY, DEV}, -/*1E*/ {"bWBBufLifeTimeEst", BYTE, URD, READ_ONLY, DEV}, -/*1F*/ {"bCurrentWBBufSize", DWORD, URD, READ_ONLY, DEV}, +/*1C*/ {"bWBBufFlushStatus", BYTE, URD, READ_ONLY, DEV | ARRAY}, +/*1D*/ {"bAvailableWBBufSize", BYTE, URD, READ_ONLY, DEV | ARRAY}, +/*1E*/ {"bWBBufLifeTimeEst", BYTE, URD, READ_ONLY, DEV | ARRAY}, +/*1F*/ {"bCurrentWBBufSize", DWORD, URD, READ_ONLY, DEV | ARRAY}, {ATTR_RSRV()}, {ATTR_RSRV()}, {ATTR_RSRV()}, @@ -1099,7 +1099,9 @@ int do_attributes(struct tool_options *opt) rc = do_query_rq(fd, &bsg_req, &bsg_rsp, UPIU_QUERY_FUNC_STANDARD_READ_REQUEST, UPIU_QUERY_OPCODE_READ_ATTR, att_idn, - opt->index, opt->selector, 0, 0, 0); + tmp->device_level & ARRAY ? + opt->index : 0, + opt->selector, 0, 0, 0); if (rc == OK) { attr_value = be32toh(bsg_rsp.upiu_rsp.qr.value); print_attribute(tmp, (__u8 *)&attr_value);