瀏覽代碼

staging: ion: always initialize the free list parameters

Currently we initialize the heap free_lock and free list size in
ion_heap_init_deferred_free, which is only called when the
ION_HEAP_FLAG_DEFER_FREE heap flag is given.  However, the lock and size
are used in the shrinker path as well as the deferred free path, and we
can register a shrinker *without* enabling deferred freeing.  So, if a
heap provides a shrinker but *doesn't* set the DEFER_FREE flag we will
use these parameters uninitialized (resulting in a spinlock bug and
broken shrinker accounting).

Fix these problems by initializing the free list parameters directly in
ion_device_add_heap, which is always called no matter which heap
features are being used.

Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Mitchel Humpherys 10 年之前
父節點
當前提交
95e53ddd82
共有 2 個文件被更改,包括 3 次插入2 次删除
  1. 3 0
      drivers/staging/android/ion/ion.c
  2. 0 2
      drivers/staging/android/ion/ion_heap.c

+ 3 - 0
drivers/staging/android/ion/ion.c

@@ -1508,6 +1508,9 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
 		pr_err("%s: can not add heap with invalid ops struct.\n",
 		pr_err("%s: can not add heap with invalid ops struct.\n",
 		       __func__);
 		       __func__);
 
 
+	spin_lock_init(&heap->free_lock);
+	heap->free_list_size = 0;
+
 	if (heap->flags & ION_HEAP_FLAG_DEFER_FREE)
 	if (heap->flags & ION_HEAP_FLAG_DEFER_FREE)
 		ion_heap_init_deferred_free(heap);
 		ion_heap_init_deferred_free(heap);
 
 

+ 0 - 2
drivers/staging/android/ion/ion_heap.c

@@ -253,8 +253,6 @@ int ion_heap_init_deferred_free(struct ion_heap *heap)
 	struct sched_param param = { .sched_priority = 0 };
 	struct sched_param param = { .sched_priority = 0 };
 
 
 	INIT_LIST_HEAD(&heap->free_list);
 	INIT_LIST_HEAD(&heap->free_list);
-	heap->free_list_size = 0;
-	spin_lock_init(&heap->free_lock);
 	init_waitqueue_head(&heap->waitqueue);
 	init_waitqueue_head(&heap->waitqueue);
 	heap->task = kthread_run(ion_heap_deferred_free, heap,
 	heap->task = kthread_run(ion_heap_deferred_free, heap,
 				 "%s", heap->name);
 				 "%s", heap->name);