Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] counter: fix privdata alignment
@ 2024-02-05 15:58 Nuno Sa via B4 Relay
  2024-02-08 18:34 ` William Breathitt Gray
  0 siblings, 1 reply; 6+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-02-05 15:58 UTC (permalink / raw)
  To: linux-iio
  Cc: Greg Kroah-Hartman, Jonathan Cameron, Uwe Kleine-König,
	William Breathitt Gray

From: Nuno Sa <nuno.sa@analog.com>

Aligning to the L1 cache does guarantee the same alignment as kmallocing
an object [1]. Furthermore, in some platforms, that alignment is not
sufficient for DMA safety (in case someone wants to have a DMA safe
buffer in privdata) [2].

Sometime ago, we had the same fixes in IIO.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/base/devres.c#n35
[2]: https://lore.kernel.org/linux-iio/20220508175712.647246-2-jic23@kernel.org/

Fixes: c18e2760308e ("counter: Provide alternative counter registration functions")
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
William, if you prefer, we can do something like in IIO and add a
specific COUNTER_DMA_MINALIGN define
---
 drivers/counter/counter-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
index 09c77afb33ca..073bf6b67a57 100644
--- a/drivers/counter/counter-core.c
+++ b/drivers/counter/counter-core.c
@@ -34,7 +34,7 @@ struct counter_device_allochelper {
 	 * This is cache line aligned to ensure private data behaves like if it
 	 * were kmalloced separately.
 	 */
-	unsigned long privdata[] ____cacheline_aligned;
+	unsigned long privdata[] __aligned(ARCH_DMA_MINALIGN);
 };
 
 static void counter_device_release(struct device *dev)

---
base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d
change-id: 20240205-counter-align-fix-3faebfb572af
--

Thanks!
- Nuno Sá


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

end of thread, other threads:[~2024-02-09  9:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-05 15:58 [PATCH] counter: fix privdata alignment Nuno Sa via B4 Relay
2024-02-08 18:34 ` William Breathitt Gray
2024-02-09  7:42   ` Nuno Sá
2024-02-09  8:30     ` Uwe Kleine-König
2024-02-09  9:07       ` Nuno Sá
2024-02-09  9:53         ` William Breathitt Gray

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