Thread (38 messages) read the whole thread 38 messages, 9 authors, 2024-03-03

Re: [PATCH v4 4/8] iio: core: Calculate alloc_size only once in iio_device_alloc()

From: David Lechner <dlechner@baylibre.com>
Date: 2024-02-28 20:57:49
Also in: dmaengine, linux-hardening, linux-iio, linux-spi, lkml, netdev

On Wed, Feb 28, 2024 at 2:49 PM Andy Shevchenko
[off-list ref] wrote:
quoted hunk ↗ jump to hunk
No need to rewrite the value, instead use 'else' branch.
This will also help further refactoring the code later on.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/industrialio-core.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index bd305fa87093..1986b3386307 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1643,11 +1643,10 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
        struct iio_dev *indio_dev;
        size_t alloc_size;

-       alloc_size = sizeof(struct iio_dev_opaque);
-       if (sizeof_priv) {
-               alloc_size = ALIGN(alloc_size, IIO_DMA_MINALIGN);
-               alloc_size += sizeof_priv;
-       }
+       if (sizeof_priv)
+               alloc_size = ALIGN(alloc_size, IIO_DMA_MINALIGN) + sizeof_priv;
Isn't this using alloc_size before it is assigned? Perhaps you meant this:

    alloc_size = ALIGN(sizeof(struct iio_dev_opaque),
IIO_DMA_MINALIGN) + sizeof_priv;

+       else
+               alloc_size = sizeof(struct iio_dev_opaque);

        iio_dev_opaque = kzalloc(alloc_size, GFP_KERNEL);
        if (!iio_dev_opaque)
_______________________________________________
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