Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Fourier" <fourier.thomas@gmail.com>
Cc: "open list:AACRAID SCSI RAID DRIVER" <linux-scsi@vger.kernel.org>
Subject: Re: [PATCH] scsi: aacraid: fix dma_free_coherent() size
Date: Fri, 16 Oct 2026 15:06:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-174530@kernel.org> (raw)
In-Reply-To: <20261016145420.50870-2-fourier.thomas@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] scsi: aacraid: DMA unmap size mismatch due to shrunken can_queue
--

commit 1e9d5fb7ed09ff94558efbd312a1809b83cd68c2
Author: Thomas Fourier <fourier.thomas@gmail.com>

scsi: aacraid: fix dma_free_coherent() size

This commit updates the DMA unmap size calculation in aac_fib_map_free()
to use dev->max_cmd_size instead of dev->max_fib_size. This is intended to
match the initial allocation size in fib_map_alloc() and prevent leaving
parts of the memory mapped.

> diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
> index 0dba4406494a5..16cc4593a5c97 100644
> --- a/drivers/scsi/aacraid/commsup.c
> +++ b/drivers/scsi/aacraid/commsup.c
> @@ -81,7 +81,7 @@ void aac_fib_map_free(struct aac_dev *dev)
>  		return;
>  
>  	num_fibs = dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB;
> -	fib_size = dev->max_fib_size + sizeof(struct aac_fib_xporthdr);
> +	fib_size = dev->max_cmd_size + sizeof(struct aac_fib_xporthdr);
>  	alloc_size = fib_size * num_fibs + ALIGN32 - 1;

[Severity: High]
Does this recalculation still result in a DMA unmap size mismatch?

While this update corrects the fib_size multiplier, the num_fibs multiplier
is based on dev->scsi_host_ptr->can_queue, which can be modified after the
initial allocation.

For example, fib_map_alloc() allocates memory based on the initial value of
can_queue:

drivers/scsi/aacraid/commsup.c:fib_map_alloc() {
    ...
	dev->hw_fib_va = dma_alloc_coherent(&dev->pdev->dev,
		(dev->max_cmd_size + sizeof(struct aac_fib_xporthdr))
		* (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) + (ALIGN32 - 1),
		&dev->hw_fib_pa, GFP_KERNEL);
    ...
}

However, for Rocket adapters, can_queue is shrunk after the allocation
successfully completes:

drivers/scsi/aacraid/rkt.c:aac_rkt_select_comm() {
    ...
			dev->scsi_host_ptr->can_queue = AAC_NUM_IO_FIB_RKT;
    ...
}

When aac_fib_map_free() is called, it recalculates the unmap size using the
newly shrunken can_queue, which causes a smaller size to be passed to
dma_free_coherent(). 

Will passing a mismatched smaller size to dma_free_coherent() violate the
DMA API contract and lead to leaked memory or corrupt allocator state?

>  
>  	dma_free_coherent(&dev->pdev->dev, alloc_size, dev->hw_fib_va,
>  			  dev->hw_fib_pa);
>  
>  	dev->hw_fib_va = NULL;
>  	dev->hw_fib_pa = 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261016145420.50870-2-fourier.thomas@gmail.com?part=1

      reply	other threads:[~2026-10-16 15:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 14:54 [PATCH] scsi: aacraid: fix dma_free_coherent() size Thomas Fourier
2026-10-16 15:06 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-174530@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fourier.thomas@gmail.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox