[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1603971787-16784-4-git-send-email-mihai.carabas@oracle.com>
Date: Thu, 29 Oct 2020 13:43:06 +0200
From: Mihai Carabas <mihai.carabas@...cle.com>
To: linux-kernel@...r.kernel.org
Cc: Peng Hao <peng.hao2@....com.cn>,
Mihai Carabas <mihai.carabas@...cle.com>
Subject: [PATCH 3/4] misc/pvpanic: Avoid initializing multiple pvpanic devices
From: Peng Hao <peng.hao2@....com.cn>
Avoid initializing multiple pvpanic devices when configure multiple
pvpanic device driver type. Make sure that only one pvpanic device
is working.
Signed-off-by: Peng Hao <peng.hao2@....com.cn>
Signed-off-by: Mihai Carabas <mihai.carabas@...cle.com>
---
drivers/misc/pvpanic/pvpanic.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/misc/pvpanic/pvpanic.c b/drivers/misc/pvpanic/pvpanic.c
index 4c831f5..8c7b534 100644
--- a/drivers/misc/pvpanic/pvpanic.c
+++ b/drivers/misc/pvpanic/pvpanic.c
@@ -17,10 +17,13 @@
#include <uapi/misc/pvpanic.h>
static struct {
+ struct mutex lock;
struct platform_device *pdev;
void __iomem *base;
bool is_ioport;
-} pvpanic_data;
+} pvpanic_data = {
+ .lock = __MUTEX_INITIALIZER(pvpanic_data.lock),
+};
MODULE_AUTHOR("Hu Tao <hutao@...fujitsu.com>");
MODULE_DESCRIPTION("pvpanic device driver");
@@ -56,9 +59,17 @@ int pvpanic_add_device(struct device *dev, struct resource *res)
struct platform_device *pdev;
int ret;
+ mutex_lock(&pvpanic_data.lock);
+ if (pvpanic_data.pdev) {
+ mutex_unlock(&pvpanic_data.lock);
+ return -EEXIST;
+ }
+
pdev = platform_device_alloc("pvpanic", -1);
- if (!pdev)
+ if (!pdev) {
+ mutex_unlock(&pvpanic_data.lock);
return -ENOMEM;
+ }
pdev->dev.parent = dev;
@@ -70,9 +81,11 @@ int pvpanic_add_device(struct device *dev, struct resource *res)
if (ret)
goto err;
pvpanic_data.pdev = pdev;
+ mutex_unlock(&pvpanic_data.lock);
return 0;
err:
+ mutex_unlock(&pvpanic_data.lock);
platform_device_put(pdev);
return ret;
}
@@ -80,8 +93,10 @@ int pvpanic_add_device(struct device *dev, struct resource *res)
void pvpanic_remove_device(void)
{
+ mutex_lock(&pvpanic_data.lock);
platform_device_unregister(pvpanic_data.pdev);
pvpanic_data.pdev = NULL;
+ mutex_unlock(&pvpanic_data.lock);
}
EXPORT_SYMBOL_GPL(pvpanic_remove_device);
--
1.8.3.1
Powered by blists - more mailing lists