Skip to content

Commit c83ccdc

Browse files
nunojsaWilliam Breathitt Gray
authored andcommitted
counter: fix privdata alignment
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: c18e276 ("counter: Provide alternative counter registration functions") Signed-off-by: Nuno Sa <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20240209-counter-align-fix-v2-1-5777ea0a2722@analog.com Signed-off-by: William Breathitt Gray <william.gray@linaro.org>
1 parent 6613476 commit c83ccdc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/counter/counter-core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ struct counter_device_allochelper {
3131
struct counter_device counter;
3232

3333
/*
34-
* This is cache line aligned to ensure private data behaves like if it
35-
* were kmalloced separately.
34+
* This ensures private data behaves like if it were kmalloced
35+
* separately. Also ensures the minimum alignment for safe DMA
36+
* operations (which may or may not mean cache alignment).
3637
*/
37-
unsigned long privdata[] ____cacheline_aligned;
38+
unsigned long privdata[] __aligned(ARCH_DMA_MINALIGN);
3839
};
3940

4041
static void counter_device_release(struct device *dev)

0 commit comments

Comments
 (0)