Skip to contentSkip to conversation

dmaengine: at_hdmac: fix sparse '__iomem' cast warning in memset helpers

PATCH Superseded Rosen Penev 2 participants 2 messages Jul 23

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: at_hdmac: fix sparse '__iomem' cast warning in memset helpers

Both atc_prep_dma_memset() and atc_prep_dma_memset_sg() declare vaddr as 'void __iomem *' but assign the return of dma_pool_alloc(), which returns 'void *' (not iomem memory). This causes sparse to warn about a cast removing the __iomem address space at the dereference site.

The struct field memset_vaddr is also typed as 'int *', which is neither the type returned by dma_pool_alloc() nor the type used for the actual writes.

Fix by declaring vaddr as 'u32 *' in both functions and changing memset_vaddr in struct at_desc from 'int *' to 'u32 *'. This matches the actual usage and eliminates the need for the (u32 *) cast.

Fixes 5d8c5bea0da9 ("dmaengine: at_hdmac: add COMPILE_TEST support")
Assisted-by opencode:big-pickle
---
 drivers/dma/at_hdmac.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/dma/at_hdmac.c +7 -7
index e5b30a57c477..f9c336630fa2 100644
@@ -244,7 +244,7 @@ struct at_desc {
 	/* Memset temporary buffer */
 	bool				memset_buffer;
 	dma_addr_t			memset_paddr;
-	int				*memset_vaddr;
+	u32				*memset_vaddr;
 	struct atdma_sg			sg[] __counted_by(sglen);
 };
 
@@ -1097,7 +1097,7 @@ atc_prep_dma_memset(struct dma_chan *chan, dma_addr_t dest, int value,
 	struct at_dma_chan	*atchan = to_at_dma_chan(chan);
 	struct at_dma		*atdma = to_at_dma(chan->device);
 	struct at_desc		*desc;
-	void __iomem		*vaddr;
+	u32			*vaddr;
 	dma_addr_t		paddr;
 	char			fill_pattern;
 	int			ret;
@@ -1126,10 +1126,10 @@ atc_prep_dma_memset(struct dma_chan *chan, dma_addr_t dest, int value,
 	/* Only the first byte of value is to be used according to dmaengine */
 	fill_pattern = (char)value;
 
-	*(u32*)vaddr = (fill_pattern << 24) |
-		       (fill_pattern << 16) |
-		       (fill_pattern << 8) |
-		       fill_pattern;
+	*vaddr = (fill_pattern << 24) |
+		 (fill_pattern << 16) |
+		 (fill_pattern << 8) |
+		  fill_pattern;
 
 	desc = kzalloc_flex(*desc, sg, 1, GFP_ATOMIC);
 	if (!desc)
@@ -1168,7 +1168,7 @@ atc_prep_dma_memset_sg(struct dma_chan *chan,
 	struct at_dma		*atdma = to_at_dma(chan->device);
 	struct at_desc		*desc;
 	struct scatterlist	*sg;
-	void __iomem		*vaddr;
+	u32			*vaddr;
 	dma_addr_t		paddr;
 	size_t			total_len = 0;
 	int			i;
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Low] The patch leaves a redundant (u32 *) cast in atc_prep_dma_memset_sg() despite the commit message claiming to eliminate it.

Pre-existing issues:
- [High] Scatter-gather memset does not duplicate the fill byte across the 32-bit hardware transfer word, breaking memset for non-zero values. --

--- Patch [1]: [PATCH] dmaengine: at_hdmac: fix sparse '__iomem' cast warning in memset helpers --- commit dc753f3b1d4af7a33d407969b7dd8472cf0ea85c
Author: Rosen Penev <[email protected]>

dmaengine: at_hdmac: fix sparse '__iomem' cast warning in memset helpers

This commit fixes a sparse warning caused by assigning a dma pool pointer to an iomem pointer. It changes the type of the memset_vaddr to match its actual usage and removes the need for type casting.

Quoted 4 lines
drivers/dma/at_hdmac.c +0 -0
index e5b30a57c477a..f9c336630fa25 100644

[ ... ]

drivers/dma/at_hdmac.c atc_prep_dma_memset_sg(struct dma_chan *chan, · line 1174

Quoted 9 lines
drivers/dma/at_hdmac.c +1 -1
@@ -1168,7 +1168,7 @@ atc_prep_dma_memset_sg(struct dma_chan *chan,
 	struct at_dma		*atdma = to_at_dma(chan->device);
 	struct at_desc		*desc;
 	struct scatterlist	*sg;
-	void __iomem		*vaddr;
+	u32			*vaddr;
 	dma_addr_t		paddr;
 	size_t			total_len = 0;
 	int			i;

Further down in atc_prep_dma_memset_sg(), the code assigns the fill value to vaddr:

Quoted 1 line
	*(u32*)vaddr = value;

[Severity: High]
This is a pre-existing issue, but does this assignment properly duplicate the fill byte across the 32-bit transfer word for non-zero values?

In atc_prep_dma_memset(), the fill pattern is explicitly shifted and combined across all 4 bytes. Here it seems to just assign the raw value directly. Could this result in the DMA hardware copying a pattern like 0x000000AB instead of 0xABABABAB, zeroing out 3 out of every 4 bytes for non-zero fills?

[Severity: Low]
This isn't a bug, but since vaddr is now declared as u32 *, is the (u32 *) cast still needed here?

The commit message states that changing the vaddr type eliminates the need for the cast, but it looks like the cast was only removed in atc_prep_dma_memset() and remains here in atc_prep_dma_memset_sg().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1