dma_resv: prime lockdep annotations
[linux-2.6-microblaze.git] / drivers / dma-buf / dma-resv.c
index 42a8f3f..9918a6e 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <linux/dma-resv.h>
 #include <linux/export.h>
+#include <linux/sched/mm.h>
 
 /**
  * DOC: Reservation Object Overview
@@ -95,6 +96,31 @@ static void dma_resv_list_free(struct dma_resv_list *list)
        kfree_rcu(list, rcu);
 }
 
+#if IS_ENABLED(CONFIG_LOCKDEP)
+static int __init dma_resv_lockdep(void)
+{
+       struct mm_struct *mm = mm_alloc();
+       struct dma_resv obj;
+
+       if (!mm)
+               return -ENOMEM;
+
+       dma_resv_init(&obj);
+
+       down_read(&mm->mmap_sem);
+       ww_mutex_lock(&obj.lock, NULL);
+       fs_reclaim_acquire(GFP_KERNEL);
+       fs_reclaim_release(GFP_KERNEL);
+       ww_mutex_unlock(&obj.lock);
+       up_read(&mm->mmap_sem);
+       
+       mmput(mm);
+
+       return 0;
+}
+subsys_initcall(dma_resv_lockdep);
+#endif
+
 /**
  * dma_resv_init - initialize a reservation object
  * @obj: the reservation object
@@ -471,7 +497,7 @@ unlock:
        if (pfence_excl)
                *pfence_excl = fence_excl;
        else if (fence_excl)
-               shared[++shared_count] = fence_excl;
+               shared[shared_count++] = fence_excl;
 
        if (!shared_count) {
                kfree(shared);