From 0956319b580726029ddc4e00cde6c5a348b99052 Mon Sep 17 00:00:00 2001 From: anans Date: Tue, 15 Mar 2022 13:37:37 +0530 Subject: [PATCH] fix(ufs): move nutrs assignment to ufs_init nutrs is set in ufs_enum (used by get_empty_slot), this will not be assigned if UFS_FLAGS_SKIPINIT is set in flags during init and might end up crashing read/write commands Change-Id: I1517b69c56741fd5bf4ef0ebc1fc8738746233d7 Signed-off-by: anans --- drivers/ufs/ufs.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/ufs/ufs.c b/drivers/ufs/ufs.c index b040a9518..3c27afff2 100644 --- a/drivers/ufs/ufs.c +++ b/drivers/ufs/ufs.c @@ -739,11 +739,6 @@ static void ufs_enum(void) unsigned int blk_num, blk_size; int i; - /* 0 means 1 slot */ - nutrs = (mmio_read_32(ufs_params.reg_base + CAP) & CAP_NUTRS_MASK) + 1; - if (nutrs > (ufs_params.desc_size / UFS_DESC_SIZE)) - nutrs = ufs_params.desc_size / UFS_DESC_SIZE; - ufs_verify_init(); ufs_verify_ready(); @@ -788,6 +783,13 @@ int ufs_init(const ufs_ops_t *ops, ufs_params_t *params) memcpy(&ufs_params, params, sizeof(ufs_params_t)); + /* 0 means 1 slot */ + nutrs = (mmio_read_32(ufs_params.reg_base + CAP) & CAP_NUTRS_MASK) + 1; + if (nutrs > (ufs_params.desc_size / UFS_DESC_SIZE)) { + nutrs = ufs_params.desc_size / UFS_DESC_SIZE; + } + + if (ufs_params.flags & UFS_FLAGS_SKIPINIT) { result = ufshc_dme_get(0x1571, 0, &data); assert(result == 0);