> #define SD_ASCII_STD true > #define SD_RAW false > diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c > index b928ed8..e32396e 100644 > --- a/drivers/ufs/core/ufshcd.c > +++ b/drivers/ufs/core/ufshcd.c > @@ -3686,6 +3686,12 @@ static int ufshcd_memory_alloc(struct ufs_hba > *hba) > } > > /* > + * Not freed if MCQ is configured see ufshcd_release_sdb_queue() and > + * ufshcd_config_mcq() > + */ > + if (hba->utmrdl_base_addr) > + goto skip_utmrdl; > + /* > * Allocate memory for UTP Task Management descriptors > * UFSHCI requires 1024 byte alignment of UTMRD > */ > @@ -3701,6 +3707,7 @@ static int ufshcd_memory_alloc(struct ufs_hba > *hba) > goto out; > } > > +skip_utmrdl: > /* Allocate memory for local reference block */ > hba->lrb = devm_kcalloc(hba->dev, > hba->nutrs, sizeof(struct ufshcd_lrb), > @@ -8176,6 +8183,22 @@ static int ufshcd_add_lus(struct ufs_hba *hba) > return ret; > } > > +/* SDB - Single Doorbell */ > +static void ufshcd_release_sdb_queue(struct ufs_hba *hba, int nutrs) > +{ > + size_t ucdl_size, utrdl_size; > + > + ucdl_size = sizeof(struct utp_transfer_cmd_desc) * nutrs; > + dmam_free_coherent(hba->dev, ucdl_size, hba->ucdl_base_addr, > + hba->ucdl_dma_addr); > + > + utrdl_size = sizeof(struct utp_transfer_req_desc) * nutrs; > + dmam_free_coherent(hba->dev, utrdl_size, hba->utrdl_base_addr, > + hba->utrdl_dma_addr); > + > + devm_kfree(hba->dev, hba->lrb); Is it possible not to release the lrb here? and then you won't be needing to call ufshcd_memory_alloc again? Thanks, Avri > +} > + > static int ufshcd_alloc_mcq(struct ufs_hba *hba) > { > int ret; > @@ -8183,12 +8206,25 @@ static int ufshcd_alloc_mcq(struct ufs_hba > *hba) > > hba->nutrs = ufshcd_mcq_decide_queue_depth(hba); > ret = ufshcd_mcq_init(hba); > - if (ret) { > - hba->nutrs = old_nutrs; > - return ret; > + if (ret) > + goto err; > + > + if (hba->nutrs != old_nutrs) { > + ufshcd_release_sdb_queue(hba, old_nutrs); > + ret = ufshcd_memory_alloc(hba); > + if (ret) > + goto err; > + ufshcd_host_memory_configure(hba); > } > > + ret = ufshcd_mcq_memory_alloc(hba); > + if (ret) > + goto err; > + > return 0; > +err: > + hba->nutrs = old_nutrs; > + return ret; > }