[PATCH 4/4] tty: goldfish: use guard() for locks

From: Jiri Slaby (SUSE)

Date: Fri Jul 03 2026 - 04:52:46 EST


Using guard()s is cleaner and safer.

goldfish_tty_probe() is omitted due to the crossing err_unmap
goto-label. Using scoped_guard() does not look that nice there. Perhaps
if someone refactored the locked part into a separate function...

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@xxxxxxxxxx>
---
drivers/tty/goldfish.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/goldfish.c b/drivers/tty/goldfish.c
index c643d76e9d1b..fa723a4ba7b3 100644
--- a/drivers/tty/goldfish.c
+++ b/drivers/tty/goldfish.c
@@ -60,10 +60,10 @@ static inline void gf_write_addr(unsigned long addr, void __iomem *portl, void _
static void do_rw_io(struct goldfish_tty *qtty, unsigned long address,
size_t count, bool is_write)
{
- unsigned long irq_flags;
void __iomem *base = qtty->base;

- spin_lock_irqsave(&qtty->lock, irq_flags);
+ guard(spinlock_irqsave)(&qtty->lock);
+
gf_write_addr(address, base + GOLDFISH_TTY_REG_DATA_PTR,
base + GOLDFISH_TTY_REG_DATA_PTR_HIGH);
gf_iowrite32(count, base + GOLDFISH_TTY_REG_DATA_LEN);
@@ -74,8 +74,6 @@ static void do_rw_io(struct goldfish_tty *qtty, unsigned long address,
else
gf_iowrite32(GOLDFISH_TTY_CMD_READ_BUFFER,
base + GOLDFISH_TTY_REG_CMD);
-
- spin_unlock_irqrestore(&qtty->lock, irq_flags);
}

static void goldfish_tty_rw(struct goldfish_tty *qtty, unsigned long addr,
@@ -417,7 +415,7 @@ static void goldfish_tty_remove(struct platform_device *pdev)
{
struct goldfish_tty *qtty = platform_get_drvdata(pdev);

- mutex_lock(&goldfish_tty_lock);
+ guard(mutex)(&goldfish_tty_lock);

unregister_console(&qtty->console);
tty_unregister_device(goldfish_tty_driver, qtty->console.index);
@@ -428,7 +426,6 @@ static void goldfish_tty_remove(struct platform_device *pdev)
goldfish_tty_current_line_count--;
if (goldfish_tty_current_line_count == 0)
goldfish_tty_delete_driver();
- mutex_unlock(&goldfish_tty_lock);
}

#ifdef CONFIG_GOLDFISH_TTY_EARLY_CONSOLE
--
2.54.0