From b31c94a60c841f61572c7f27afda1f688573f4c2 Mon Sep 17 00:00:00 2001
From: ArchStacker <ArchStacker@gmail.com>
Date: Thu, 17 Sep 2015 11:19:53 +0800
Subject: [PATCH] Add check when store disk cache

---
 grub-core/kern/disk.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c
index 789f8c0..acd0894 100644
--- a/grub-core/kern/disk.c
+++ b/grub-core/kern/disk.c
@@ -124,10 +124,12 @@ grub_disk_cache_store (unsigned long dev_id, unsigned long disk_id,
   cache_index = grub_disk_cache_get_index (dev_id, disk_id, sector);
   cache = grub_disk_cache_table + cache_index;
 
+  if(cache->lock)
+    return GRUB_ERR_NONE;
+
   cache->lock = 1;
   grub_free (cache->data);
   cache->data = 0;
-  cache->lock = 0;
 
   cache->data = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
   if (! cache->data)
@@ -138,6 +140,7 @@ grub_disk_cache_store (unsigned long dev_id, unsigned long disk_id,
   cache->dev_id = dev_id;
   cache->disk_id = disk_id;
   cache->sector = sector;
+  cache->lock = 0;
 
   return GRUB_ERR_NONE;
 }
-- 
2.4.3

