Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: mcq: Fix memory allocation checks for SQE and CQE
@ 2025-09-06 20:36 ` Alok Tiwari
  2025-09-07 10:00   ` Alim Akhtar
  0 siblings, 1 reply; 2+ messages in thread
From: Alok Tiwari @ 2025-09-06 20:36 UTC (permalink / raw)
  To: mani, quic_cang, quic_asutoshd, peter.wang, martin.petersen,
	alim.akhtar, avri.altman, bvanassche, James.Bottomley, linux-scsi
  Cc: alok.a.tiwari, linux-kernel

The previous checks incorrectly tested the DMA addresses returned
by dmam_alloc_coherent instead of the returned virtual addresses.
This could cause allocation failures to go unnoticed.

dmam_alloc_coherent returns the CPU address, not the DMA address.
Using DMA pointer for NULL check is incorrect.

Change checks to verify sqe_base_addr and cqe_base_addr instead of
sqe_dma_addr and cqe_dma_addr

Fixes: 4682abfae2eb ("scsi: ufs: core: mcq: Allocate memory for MCQ mode")
Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
---
 drivers/ufs/core/ufs-mcq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c
index 1e50675772fe..cc88aaa106da 100644
--- a/drivers/ufs/core/ufs-mcq.c
+++ b/drivers/ufs/core/ufs-mcq.c
@@ -243,7 +243,7 @@ int ufshcd_mcq_memory_alloc(struct ufs_hba *hba)
 		hwq->sqe_base_addr = dmam_alloc_coherent(hba->dev, utrdl_size,
 							 &hwq->sqe_dma_addr,
 							 GFP_KERNEL);
-		if (!hwq->sqe_dma_addr) {
+		if (!hwq->sqe_base_addr) {
 			dev_err(hba->dev, "SQE allocation failed\n");
 			return -ENOMEM;
 		}
@@ -252,7 +252,7 @@ int ufshcd_mcq_memory_alloc(struct ufs_hba *hba)
 		hwq->cqe_base_addr = dmam_alloc_coherent(hba->dev, cqe_size,
 							 &hwq->cqe_dma_addr,
 							 GFP_KERNEL);
-		if (!hwq->cqe_dma_addr) {
+		if (!hwq->cqe_base_addr) {
 			dev_err(hba->dev, "CQE allocation failed\n");
 			return -ENOMEM;
 		}
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH] scsi: ufs: mcq: Fix memory allocation checks for SQE and CQE
  2025-09-06 20:36 ` [PATCH] scsi: ufs: mcq: Fix memory allocation checks for SQE and CQE Alok Tiwari
@ 2025-09-07 10:00   ` Alim Akhtar
  0 siblings, 0 replies; 2+ messages in thread
From: Alim Akhtar @ 2025-09-07 10:00 UTC (permalink / raw)
  To: 'Alok Tiwari', mani, quic_cang, quic_asutoshd, peter.wang,
	martin.petersen, avri.altman, bvanassche, James.Bottomley,
	linux-scsi
  Cc: linux-kernel

Hi Alok

> -----Original Message-----
> From: Alok Tiwari <alok.a.tiwari@oracle.com>
> Sent: Sunday, September 7, 2025 2:06 AM
> To: mani@kernel.org; quic_cang@quicinc.com; quic_asutoshd@quicinc.com;
> peter.wang@mediatek.com; martin.petersen@oracle.com;
> alim.akhtar@samsung.com; avri.altman@wdc.com; bvanassche@acm.org;
> James.Bottomley@HansenPartnership.com; linux-scsi@vger.kernel.org
> Cc: alok.a.tiwari@oracle.com; linux-kernel@vger.kernel.org
> Subject: [PATCH] scsi: ufs: mcq: Fix memory allocation checks for SQE and
> CQE
> 
> The previous checks incorrectly tested the DMA addresses returned by
> dmam_alloc_coherent instead of the returned virtual addresses.
> This could cause allocation failures to go unnoticed.
> 
> dmam_alloc_coherent returns the CPU address, not the DMA address.
> Using DMA pointer for NULL check is incorrect.
> 
Right, Zero/NULL can be a valid DMA address and  NULL retuned by
dmam_alloc_coherent()
Is allocation failure. 
May be rephrase your commit message to be more clearer and this patch is
good to go.

> Change checks to verify sqe_base_addr and cqe_base_addr instead of
> sqe_dma_addr and cqe_dma_addr
> 
> Fixes: 4682abfae2eb ("scsi: ufs: core: mcq: Allocate memory for MCQ mode")
> Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
> ---
For v2 patch, feel free to add
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>

>  drivers/ufs/core/ufs-mcq.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c index
> 1e50675772fe..cc88aaa106da 100644
> --- a/drivers/ufs/core/ufs-mcq.c
> +++ b/drivers/ufs/core/ufs-mcq.c
> @@ -243,7 +243,7 @@ int ufshcd_mcq_memory_alloc(struct ufs_hba *hba)
>  		hwq->sqe_base_addr = dmam_alloc_coherent(hba->dev,
> utrdl_size,
>  							 &hwq-
> >sqe_dma_addr,
>  							 GFP_KERNEL);
> -		if (!hwq->sqe_dma_addr) {
> +		if (!hwq->sqe_base_addr) {
>  			dev_err(hba->dev, "SQE allocation failed\n");
>  			return -ENOMEM;
>  		}
> @@ -252,7 +252,7 @@ int ufshcd_mcq_memory_alloc(struct ufs_hba *hba)
>  		hwq->cqe_base_addr = dmam_alloc_coherent(hba->dev,
> cqe_size,
>  							 &hwq-
> >cqe_dma_addr,
>  							 GFP_KERNEL);
> -		if (!hwq->cqe_dma_addr) {
> +		if (!hwq->cqe_base_addr) {
>  			dev_err(hba->dev, "CQE allocation failed\n");
>  			return -ENOMEM;
>  		}
> --
> 2.50.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-07 10:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20250906203658epcas5p335a6395bad2fa2f9f2d629d80a3dcb38@epcas5p3.samsung.com>
2025-09-06 20:36 ` [PATCH] scsi: ufs: mcq: Fix memory allocation checks for SQE and CQE Alok Tiwari
2025-09-07 10:00   ` Alim Akhtar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox