]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
spi: virtio: Fix confusing cleanup.h syntax
authorKrzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Mon, 8 Dec 2025 02:08:31 +0000 (03:08 +0100)
committerMark Brown <broonie@kernel.org>
Sun, 14 Dec 2025 10:39:28 +0000 (19:39 +0900)
Initializing automatic __free variables to NULL without need (e.g.
branches with different allocations), followed by actual allocation is
in contrary to explicit coding rules guiding cleanup.h:

"Given that the "__free(...) = NULL" pattern for variables defined at
the top of the function poses this potential interdependency problem the
recommendation is to always define and assign variables in one statement
and not group variable definitions at the top of the function when
__free() is used."

Code does not have a bug, but is less readable and uses discouraged
coding practice, so fix that by moving declaration to the place of
assignment.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Link: https://patch.msgid.link/20251208020830.5225-2-krzysztof.kozlowski@oss.qualcomm.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-virtio.c

index 2acb929b2c6907d6b073829c153d1e1d3bb729b5..6aad9f1fd01641132f87f70bc0c7a0726a559a60 100644 (file)
@@ -150,7 +150,6 @@ static int virtio_spi_transfer_one(struct spi_controller *ctrl,
                                   struct spi_transfer *xfer)
 {
        struct virtio_spi_priv *priv = spi_controller_get_devdata(ctrl);
-       struct virtio_spi_req *spi_req __free(kfree) = NULL;
        struct spi_transfer_head *th;
        struct scatterlist sg_out_head, sg_out_payload;
        struct scatterlist sg_in_result, sg_in_payload;
@@ -159,7 +158,8 @@ static int virtio_spi_transfer_one(struct spi_controller *ctrl,
        unsigned int incnt = 0;
        int ret;
 
-       spi_req = kzalloc(sizeof(*spi_req), GFP_KERNEL);
+       struct virtio_spi_req *spi_req __free(kfree) = kzalloc(sizeof(*spi_req),
+                                                              GFP_KERNEL);
        if (!spi_req)
                return -ENOMEM;