void *match_data)
 {
        struct kunit_resource *res, *found = NULL;
+       unsigned long flags;
 
-       spin_lock(&test->lock);
+       spin_lock_irqsave(&test->lock, flags);
 
        list_for_each_entry_reverse(res, &test->resources, node) {
                if (match(test, res, (void *)match_data)) {
                }
        }
 
-       spin_unlock(&test->lock);
+       spin_unlock_irqrestore(&test->lock, flags);
 
        return found;
 }
 
                       void *data)
 {
        int ret = 0;
+       unsigned long flags;
 
        res->free = free;
        kref_init(&res->refcount);
                res->data = data;
        }
 
-       spin_lock(&test->lock);
+       spin_lock_irqsave(&test->lock, flags);
        list_add_tail(&res->node, &test->resources);
        /* refcount for list is established by kref_init() */
-       spin_unlock(&test->lock);
+       spin_unlock_irqrestore(&test->lock, flags);
 
        return ret;
 }
 
 void kunit_remove_resource(struct kunit *test, struct kunit_resource *res)
 {
-       spin_lock(&test->lock);
+       unsigned long flags;
+
+       spin_lock_irqsave(&test->lock, flags);
        list_del(&res->node);
-       spin_unlock(&test->lock);
+       spin_unlock_irqrestore(&test->lock, flags);
        kunit_put_resource(res);
 }
 EXPORT_SYMBOL_GPL(kunit_remove_resource);
 void kunit_cleanup(struct kunit *test)
 {
        struct kunit_resource *res;
+       unsigned long flags;
 
        /*
         * test->resources is a stack - each allocation must be freed in the
         * protect against the current node being deleted, not the next.
         */
        while (true) {
-               spin_lock(&test->lock);
+               spin_lock_irqsave(&test->lock, flags);
                if (list_empty(&test->resources)) {
-                       spin_unlock(&test->lock);
+                       spin_unlock_irqrestore(&test->lock, flags);
                        break;
                }
                res = list_last_entry(&test->resources,
                 * resource, and this can't happen if the test->lock
                 * is held.
                 */
-               spin_unlock(&test->lock);
+               spin_unlock_irqrestore(&test->lock, flags);
                kunit_remove_resource(test, res);
        }
        current->kunit_test = NULL;