diff mbox series

[v2] counter: fix privdata alignment

Message ID 20240209-counter-align-fix-v2-1-5777ea0a2722@analog.com (mailing list archive)
State Handled Elsewhere
Headers show
Series [v2] counter: fix privdata alignment | expand

Commit Message

Nuno Sa Feb. 9, 2024, 3:50 p.m. UTC
Aligning to the L1 cache does not 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>
---
Changes in v2:
 * Fixed typo in commit message;
 * Updated the comment block above privdata.
---
 drivers/counter/counter-core.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)


---
base-commit: 81e8e40ea16329914f78ca1f454d04f570540ca8
change-id: 20240209-counter-align-fix-6fb38946af7f
--

Thanks!
- Nuno Sá

Comments

William Breathitt Gray Feb. 16, 2024, 11:41 p.m. UTC | #1
On Fri, Feb 09, 2024 at 04:50:34PM +0100, Nuno Sa wrote:
> Aligning to the L1 cache does not 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>

Applied as commit b6dce0452a02, thanks!

William Breathitt Gray
diff mbox series

Patch

diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
index 09c77afb33ca..3f24481fc04a 100644
--- a/drivers/counter/counter-core.c
+++ b/drivers/counter/counter-core.c
@@ -31,10 +31,11 @@  struct counter_device_allochelper {
 	struct counter_device counter;
 
 	/*
-	 * This is cache line aligned to ensure private data behaves like if it
-	 * were kmalloced separately.
+	 * This ensures private data behaves like if it were kmalloced
+	 * separately. Also ensures the minimum alignment for safe DMA
+	 * operations (which may or may not mean cache alignment).
 	 */
-	unsigned long privdata[] ____cacheline_aligned;
+	unsigned long privdata[] __aligned(ARCH_DMA_MINALIGN);
 };
 
 static void counter_device_release(struct device *dev)