From e932c5da50a22e585a3cd08edb3d849e7715e244 Mon Sep 17 00:00:00 2001 From: Alasdair G Kergon Date: Tue, 12 Dec 2017 17:56:58 +0000 Subject: [PATCH] device: Fix an unpaired device close. dev_open_flags contains an unpaired dev_close_immediate so increment open_count before calling it. --- lib/device/dev-io.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c index dc9ad13f2..c321e61ad 100644 --- a/lib/device/dev-io.c +++ b/lib/device/dev-io.c @@ -491,11 +491,12 @@ int dev_open_flags(struct device *dev, int flags, int direct, int quiet) return 1; } - if (dev->open_count && !need_excl) { + if (dev->open_count && !need_excl) log_debug_devs("%s: Already opened read-only. Upgrading " "to read-write.", dev_name(dev)); - dev->open_count++; - } + + /* dev_close_immediate will decrement this */ + dev->open_count++; dev_close_immediate(dev); // FIXME: dev with DEV_ALLOCED is released