linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peng Hao <peng.hao2@zte.com.cn>
To: gregkh@linuxfoundation.org, arnd@arndb.de, andy.shevchenko@gmail.com
Cc: linux-kernel@vger.kernel.org, Peng Hao <peng.hao2@zte.com.cn>
Subject: [PATCH V5 3/4]  misc/pvpanic: Avoid initializing multiple pvpanic devices
Date: Sun, 17 Feb 2019 00:50:42 +0800	[thread overview]
Message-ID: <1550335843-108902-4-git-send-email-peng.hao2@zte.com.cn> (raw)
In-Reply-To: <1550335843-108902-1-git-send-email-peng.hao2@zte.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@zte.com.cn>
---
 drivers/misc/pvpanic/pvpanic.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/pvpanic/pvpanic.c b/drivers/misc/pvpanic/pvpanic.c
index ccadec0..fbb5038 100644
--- a/drivers/misc/pvpanic/pvpanic.c
+++ b/drivers/misc/pvpanic/pvpanic.c
@@ -15,10 +15,13 @@
 #include <linux/types.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),
+};
 
 #define PVPANIC_PANICKED        (1 << 0)
 
@@ -50,6 +53,12 @@ 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)
 		return -ENOMEM;
@@ -64,9 +73,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;
 }
-- 
1.8.3.1


  parent reply	other threads:[~2019-02-16  8:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-16 16:50 [PATCH V5 0/4] add pvpanic driver framework Peng Hao
2019-02-16 16:50 ` [PATCH V5 1/4] misc/pvpanic : preparing for " Peng Hao
2019-02-16 12:12   ` Andy Shevchenko
2019-02-16 16:50 ` [PATCH V5 2/4] misc/pvpanic: Add " Peng Hao
2019-02-16 16:50 ` Peng Hao [this message]
2019-02-16 12:11   ` [PATCH V5 3/4] misc/pvpanic: Avoid initializing multiple pvpanic devices Andy Shevchenko
2019-02-16 16:50 ` [PATCH V5 4/4] misc/pvpanic: add new pvpanic pci driver Peng Hao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1550335843-108902-4-git-send-email-peng.hao2@zte.com.cn \
    --to=peng.hao2@zte.com.cn \
    --cc=andy.shevchenko@gmail.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).