From 71860814428050f4f180e9a264bab34c1916f15d Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Wed, 13 Mar 2019 20:05:35 +0800
Subject: [PATCH 08/19] cov: check dev_close_immediate

Function can report log_error() on fail path.
---
 lib/device/dev-cache.c | 4 ++--
 lib/device/dev-io.c    | 6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index c866ff9..8af1de9 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -1344,8 +1344,8 @@ static int _check_for_open_devices(int close_immediate)
 			log_error("Device '%s' has been left open (%d remaining references).",
 				  dev_name(dev), dev->open_count);
 			num_open++;
-			if (close_immediate)
-				dev_close_immediate(dev);
+			if (close_immediate && !dev_close_immediate(dev))
+				stack;
 		}
 	}
 
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 2a4967f..8bf1847 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -510,7 +510,8 @@ int dev_open_flags(struct device *dev, int flags, int direct, int quiet)
 		/* dev_close_immediate will decrement this */
 		dev->open_count++;
 
-		dev_close_immediate(dev);
+		if (!dev_close_immediate(dev))
+			return_0;
 		// FIXME: dev with DEV_ALLOCED is released
 		// but code is referencing it
 	}
@@ -591,7 +592,8 @@ int dev_open_flags(struct device *dev, int flags, int direct, int quiet)
 	if (!(dev->flags & DEV_REGULAR) &&
 	    ((fstat(dev->fd, &buf) < 0) || (buf.st_rdev != dev->dev))) {
 		log_error("%s: fstat failed: Has device name changed?", name);
-		dev_close_immediate(dev);
+		if (!dev_close_immediate(dev))
+			stack;
 		return 0;
 	}
 
-- 
2.19.1

