From 99111d8fb25a016e0b32c2fe2f35ea35b61df36e Mon Sep 17 00:00:00 2001 From: Frank Wang Date: Thu, 11 Jan 2024 15:15:39 +0800 Subject: [PATCH] hwspinlock: rockchip: object to unlocking someone else's lock Check hwlock user id and object to unlocking someone else's lock when invoking unlock() API. Signed-off-by: Frank Wang Change-Id: I46c256fd703fa56ce3d175ff2d721f53d3615ec0 --- drivers/hwspinlock/rockchip_hwspinlock.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/hwspinlock/rockchip_hwspinlock.c b/drivers/hwspinlock/rockchip_hwspinlock.c index 312376707687..94830aa54bb0 100644 --- a/drivers/hwspinlock/rockchip_hwspinlock.c +++ b/drivers/hwspinlock/rockchip_hwspinlock.c @@ -45,6 +45,14 @@ static int rockchip_hwspinlock_trylock(struct hwspinlock *lock) static void rockchip_hwspinlock_unlock(struct hwspinlock *lock) { void __iomem *lock_addr = lock->priv; + u32 lock_owner = readl(lock_addr) & HWSPINLOCK_ID_MASK; + + if (lock_owner != hwlock_user_id) { + dev_warn(lock->bank->dev, + "WARNING: against user %u release a lock held by %u\n", + hwlock_user_id, lock_owner); + return; + } /* Release the lock by writing 0 to it */ writel(0, lock_addr);