{
        u32 arm_gpio_lock_val;
 
-       spin_lock(&gs->gc.bgpio_lock);
        mutex_lock(yu_arm_gpio_lock_param.lock);
+       spin_lock(&gs->gc.bgpio_lock);
 
        arm_gpio_lock_val = readl(yu_arm_gpio_lock_param.io);
 
         * When lock active bit[31] is set, ModeX is write enabled
         */
        if (YU_LOCK_ACTIVE_BIT(arm_gpio_lock_val)) {
-               mutex_unlock(yu_arm_gpio_lock_param.lock);
                spin_unlock(&gs->gc.bgpio_lock);
+               mutex_unlock(yu_arm_gpio_lock_param.lock);
                return -EINVAL;
        }
 
 static void mlxbf2_gpio_lock_release(struct mlxbf2_gpio_context *gs)
 {
        writel(YU_ARM_GPIO_LOCK_RELEASE, yu_arm_gpio_lock_param.io);
-       mutex_unlock(yu_arm_gpio_lock_param.lock);
        spin_unlock(&gs->gc.bgpio_lock);
+       mutex_unlock(yu_arm_gpio_lock_param.lock);
 }
 
 /*