From: Laurian Iacob <laurian.iacob@yahoo.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org,
Laurian Iacob <laurian.iacob@yahoo.com>
Subject: [PATCH] media: staging/ipu7: use guard(mutex) and simplify retry loop in buttress
Date: Thu, 5 Nov 2026 00:28:32 +0200 [thread overview]
Message-ID: <20261104222832.32471-1-laurian.iacob@yahoo.com> (raw)
In-Reply-To: <20261104222832.32471-1-laurian.iacob.ref@yahoo.com>
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@yahoo.com>
---
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
next parent reply other threads:[~2026-11-04 22:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261104222832.32471-1-laurian.iacob.ref@yahoo.com>
2026-11-04 22:28 ` Laurian Iacob [this message]
2026-11-05 7:14 ` Dan Carpenter
2026-11-05 7:52 ` Laurian Iacob
2026-11-05 8:15 ` [PATCH v2] media: staging/ipu7: use guard(mutex) in ipu7-buttress.c Laurian Iacob
2026-11-05 10:11 ` [PATCH] media: staging/ipu7: use guard(mutex) and simplify retry loop in buttress Sakari Ailus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261104222832.32471-1-laurian.iacob@yahoo.com \
--to=laurian.iacob@yahoo.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®