[PATCH] media: staging/ipu7: use guard(mutex) and simplify retry loop in buttress
From: Laurian Iacob
Date: Wed Nov 04 2026 - 18:17:22 EST
Use scope-based guard(mutex) from linux/cleanup.h in
ipu_buttress_ipc_send_msg() and ipu_buttress_authenticate() to simplify
error handling and remove redundant goto unlock paths.
Additionally, replace the backward goto retry label in
ipu_buttress_ipc_send_msg() with a standard for (;;) loop to improve
control flow readability.
Signed-off-by: Laurian Iacob <laurian.iacob@xxxxxxxxx>
---
drivers/staging/media/ipu7/ipu7-buttress.c | 56 ++++++++++------------
1 file changed, 26 insertions(+), 30 deletions(-)
diff --git a/drivers/staging/media/ipu7/ipu7-buttress.c b/drivers/staging/media/ipu7/ipu7-buttress.c
index 40c6c8473357..7ec8290c4432 100644
--- a/drivers/staging/media/ipu7/ipu7-buttress.c
+++ b/drivers/staging/media/ipu7/ipu7-buttress.c
@@ -6,6 +6,7 @@
#include <asm/cpu_device_id.h>
#include <linux/bitfield.h>
#include <linux/bits.h>
+#include <linux/cleanup.h>
#include <linux/completion.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
@@ -229,39 +230,39 @@ static int ipu_buttress_ipc_send_msg(struct ipu7_device *isp,
u32 val;
int ret;
- mutex_lock(&b->ipc_mutex);
+ guard(mutex)(&b->ipc_mutex);
ret = ipu_buttress_ipc_validity_open(isp, ipc);
if (ret) {
dev_err(dev, "IPC validity open failed\n");
- goto out;
+ return ret;
}
tx_timeout_jiffies = msecs_to_jiffies(BUTTRESS_IPC_TX_TIMEOUT_MS);
rx_timeout_jiffies = msecs_to_jiffies(BUTTRESS_IPC_RX_TIMEOUT_MS);
-try:
- reinit_completion(&ipc->send_complete);
- if (msg->require_resp)
- reinit_completion(&ipc->recv_complete);
+ for (;;) {
+ reinit_completion(&ipc->send_complete);
+ if (msg->require_resp)
+ reinit_completion(&ipc->recv_complete);
- dev_dbg(dev, "IPC command: 0x%x\n", msg->cmd);
- writel(msg->cmd, isp->base + ipc->data0_out);
- val = BUTTRESS_IU2CSEDB0_BUSY | msg->cmd_size;
- writel(val, isp->base + ipc->db0_out);
+ dev_dbg(dev, "IPC command: 0x%x\n", msg->cmd);
+ writel(msg->cmd, isp->base + ipc->data0_out);
+ val = BUTTRESS_IU2CSEDB0_BUSY | msg->cmd_size;
+ writel(val, isp->base + ipc->db0_out);
- tout = wait_for_completion_timeout(&ipc->send_complete,
- tx_timeout_jiffies);
- if (!tout) {
+ tout = wait_for_completion_timeout(&ipc->send_complete,
+ tx_timeout_jiffies);
+ if (tout)
+ break;
dev_err(dev, "send IPC response timeout\n");
- if (!retry--) {
+ if (retry-- == 0) {
ret = -ETIMEDOUT;
goto out;
}
/* Try again if CSE is not responding on first try */
writel(0, isp->base + ipc->db0_out);
- goto try;
}
if (!msg->require_resp) {
@@ -852,11 +853,11 @@ int ipu_buttress_authenticate(struct ipu7_device *isp)
return 0;
}
- mutex_lock(&b->auth_mutex);
+ guard(mutex)(&b->auth_mutex);
if (ipu_buttress_auth_done(isp)) {
ret = 0;
- goto out_unlock;
+ return 0;
}
/*
@@ -879,7 +880,7 @@ int ipu_buttress_authenticate(struct ipu7_device *isp)
BUTTRESS_CSE2IUDATA0_IPC_BOOT_LOAD_DONE);
if (ret) {
dev_err(dev, "CSE boot_load failed\n");
- goto out_unlock;
+ return ret;
}
mask = BUTTRESS_SECURITY_CTL_FW_SETUP_MASK;
@@ -891,13 +892,12 @@ int ipu_buttress_authenticate(struct ipu7_device *isp)
BUTTRESS_CSE_BOOTLOAD_TIMEOUT_US);
if (ret) {
dev_err(dev, "CSE boot_load timeout\n");
- goto out_unlock;
+ return ret;
}
if ((data & mask) == fail) {
dev_err(dev, "CSE auth failed\n");
- ret = -EINVAL;
- goto out_unlock;
+ return -EINVAL;
}
ret = readl_poll_timeout(isp->base + BOOTLOADER_STATUS_OFFSET,
@@ -905,7 +905,7 @@ int ipu_buttress_authenticate(struct ipu7_device *isp)
BUTTRESS_CSE_BOOTLOAD_TIMEOUT_US);
if (ret) {
dev_err(dev, "Unexpected magic number 0x%x\n", data);
- goto out_unlock;
+ return ret;
}
/*
@@ -919,7 +919,7 @@ int ipu_buttress_authenticate(struct ipu7_device *isp)
BUTTRESS_CSE2IUDATA0_IPC_AUTH_RUN_DONE);
if (ret) {
dev_err(dev, "CSE authenticate_run failed\n");
- goto out_unlock;
+ return ret;
}
done = BUTTRESS_SECURITY_CTL_AUTH_DONE;
@@ -929,21 +929,17 @@ int ipu_buttress_authenticate(struct ipu7_device *isp)
BUTTRESS_CSE_AUTHENTICATE_TIMEOUT_US);
if (ret) {
dev_err(dev, "CSE authenticate timeout\n");
- goto out_unlock;
+ return ret;
}
if ((data & mask) == fail) {
dev_err(dev, "CSE boot_load failed\n");
- ret = -EINVAL;
- goto out_unlock;
+ return -EINVAL;
}
dev_info(dev, "CSE authenticate_run done\n");
-out_unlock:
- mutex_unlock(&b->auth_mutex);
-
- return ret;
+ return 0;
}
static int ipu_buttress_send_tsc_request(struct ipu7_device *isp)
--
2.43.0