Thread (10 messages) 10 messages, 2 authors, 2020-08-21

Re: [PATCH v8 1/3] devres: provide devm_krealloc()

From: Bartosz Golaszewski <hidden>
Date: 2020-08-21 16:00:22
Also in: linux-iio, lkml

On Fri, Aug 21, 2020 at 1:04 PM Andy Shevchenko
[off-list ref] wrote:
On Fri, Aug 21, 2020 at 01:51:19PM +0300, Andy Shevchenko wrote:
quoted
On Fri, Aug 21, 2020 at 10:59:19AM +0200, Bartosz Golaszewski wrote:
quoted
On Fri, Aug 21, 2020 at 10:35 AM Andy Shevchenko
[off-list ref] wrote:
quoted
On Thu, Aug 20, 2020 at 08:51:08PM +0200, Bartosz Golaszewski wrote:
...
quoted
quoted
quoted
quoted
+static struct devres *to_devres(void *data)
+{
+     return data - ALIGN(sizeof(struct devres), ARCH_KMALLOC_MINALIGN);
+}
+
+static size_t devres_data_size(size_t total_size)
+{
+     return total_size - ALIGN(sizeof(struct devres), ARCH_KMALLOC_MINALIGN);
+}
quoted
quoted
The data pointer in struct devres is defined as:

    u8 __aligned(ARCH_KMALLOC_MINALIGN) data[];

And this value (assigned the value of ARCH_DMA_MINALIGN) varies from
one arch to another. I wasn't really sure if offsetof() would work for
every case so I went with something very explicit.
I have checked with a small program simulating to_devres() with your variant,
offsetof() and container_of().

The result is this: if MINALIGN < sizeof(long) and since struct is unpacked the
offsetof(), and thus container_of(), gives correct result, while ALIGN()
approach mistakenly moves pointer too back.
...
quoted
I think you need to change this to use container_of() and offsetof().
To be clear, there is probably no real problem, except unlikely possible
MINALIGN=4 on 64-bit arch, but for sake of the correctness.
Thanks for taking the time to check it. I'll switch to container_of()
for (hopefully) the last iteration.

Bart

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help