]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
firmware: arm_scmi: Refactor iterators internal allocation
authorCristian Marussi <cristian.marussi@arm.com>
Fri, 8 May 2026 15:32:54 +0000 (16:32 +0100)
committerSudeep Holla <sudeep.holla@kernel.org>
Tue, 12 May 2026 14:29:11 +0000 (15:29 +0100)
Use cleanup handlers to manage iterator data structures.

No functional change.

Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://patch.msgid.link/20260508153300.2224715-10-cristian.marussi@arm.com
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
drivers/firmware/arm_scmi/driver.c

index 53310beb67a879272b7b48f35d65ada484c2af66..143f0ec60aaef937d643c8ce80d1b5b1c04ce097 100644 (file)
@@ -17,6 +17,7 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/bitmap.h>
+#include <linux/cleanup.h>
 #include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/export.h>
@@ -1789,39 +1790,41 @@ static void *scmi_iterator_init(const struct scmi_protocol_handle *ph,
                                size_t tx_size, void *priv)
 {
        int ret;
-       struct scmi_iterator *i;
 
-       i = devm_kzalloc(ph->dev, sizeof(*i), GFP_KERNEL);
+       struct scmi_iterator *i __free(kfree) = kzalloc(sizeof(*i), GFP_KERNEL);
        if (!i)
                return ERR_PTR(-ENOMEM);
 
+       if (!ops || !ph)
+               return ERR_PTR(-EINVAL);
+
        i->ph = ph;
        i->ops = ops;
        i->priv = priv;
 
        ret = ph->xops->xfer_get_init(ph, msg_id, tx_size, 0, &i->t);
-       if (ret) {
-               devm_kfree(ph->dev, i);
+       if (ret)
                return ERR_PTR(ret);
-       }
 
        i->state.max_resources = max_resources;
        i->msg = i->t->tx.buf;
        i->resp = i->t->rx.buf;
 
-       return i;
+       return no_free_ptr(i);
 }
 
 static int scmi_iterator_run(void *iter)
 {
-       int ret = -EINVAL;
+       int ret;
        struct scmi_iterator_ops *iops;
        const struct scmi_protocol_handle *ph;
        struct scmi_iterator_state *st;
-       struct scmi_iterator *i = iter;
 
-       if (!i || !i->ops || !i->ph)
-               return ret;
+       if (!iter)
+               return -EINVAL;
+
+       /* Take ownership of the iterator */
+       struct scmi_iterator *i __free(kfree) = iter;
 
        iops = i->ops;
        ph = i->ph;
@@ -1846,12 +1849,12 @@ static int scmi_iterator_run(void *iter)
                        break;
                }
 
-               for (st->loop_idx = 0; st->loop_idx < st->num_returned;
-                    st->loop_idx++) {
+               for (st->loop_idx = 0; !ret && st->loop_idx < st->num_returned;
+                    st->loop_idx++)
                        ret = iops->process_response(ph, i->resp, st, i->priv);
-                       if (ret)
-                               goto out;
-               }
+
+               if (ret)
+                       break;
 
                st->desc_index += st->num_returned;
                ph->xops->reset_rx_to_maxsz(ph, i->t);
@@ -1861,10 +1864,8 @@ static int scmi_iterator_run(void *iter)
                 */
        } while (st->num_returned && st->num_remaining);
 
-out:
        /* Finalize and destroy iterator */
        ph->xops->xfer_put(ph, i->t);
-       devm_kfree(ph->dev, i);
 
        return ret;
 }