mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Abhijit Gangurde <abhijit.gangurde@amd.com>
To: <gregkh@linuxfoundation.org>, <masahiroy@kernel.org>,
	<linux-kernel@vger.kernel.org>
Cc: <Nipun.Gupta@amd.com>, <nikhil.agarwal@amd.com>,
	<puneet.gupta@amd.com>, <git@amd.com>, <michal.simek@amd.com>,
	Abhijit Gangurde <abhijit.gangurde@amd.com>
Subject: [PATCH v3 2/5] cdx: Introduce lock to protect controller ops
Date: Mon, 14 Aug 2023 15:52:20 +0530	[thread overview]
Message-ID: <20230814102223.418046-3-abhijit.gangurde@amd.com> (raw)
In-Reply-To: <20230814102223.418046-1-abhijit.gangurde@amd.com>

Add a mutex lock to prevent race between controller ops initiated by
the bus subsystem and the controller registration/unregistration.

Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com>
---
 drivers/cdx/cdx.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c
index 1c0f76cf4f15..50df061f4537 100644
--- a/drivers/cdx/cdx.c
+++ b/drivers/cdx/cdx.c
@@ -72,6 +72,8 @@
 
 /* IDA for CDX controllers registered with the CDX bus */
 DEFINE_IDA(cdx_controller_ida);
+/* Lock to protect controller ops */
+static DEFINE_MUTEX(cdx_controller_lock);
 
 static char *compat_node_name = "xlnx,versal-net-cdx";
 
@@ -396,6 +398,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
 	if (!val)
 		return -EINVAL;
 
+	mutex_lock(&cdx_controller_lock);
+
 	/* Unregister all the devices on the bus */
 	cdx_unregister_devices(&cdx_bus_type);
 
@@ -415,6 +419,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
 		put_device(&pd->dev);
 	}
 
+	mutex_unlock(&cdx_controller_lock);
+
 	return count;
 }
 static BUS_ATTR_WO(rescan);
@@ -538,11 +544,13 @@ int cdx_register_controller(struct cdx_controller *cdx)
 		return ret;
 	}
 
+	mutex_lock(&cdx_controller_lock);
 	cdx->id = ret;
 
 	/* Scan all the devices */
 	cdx->ops->scan(cdx);
 	cdx->controller_registered = true;
+	mutex_unlock(&cdx_controller_lock);
 
 	return 0;
 }
@@ -553,9 +561,13 @@ void cdx_unregister_controller(struct cdx_controller *cdx)
 	if (cdx->id >= MAX_CDX_CONTROLLERS)
 		return;
 
+	mutex_lock(&cdx_controller_lock);
+
 	cdx->controller_registered = false;
 	device_for_each_child(cdx->dev, NULL, cdx_unregister_device);
 	ida_free(&cdx_controller_ida, cdx->id);
+
+	mutex_unlock(&cdx_controller_lock);
 }
 EXPORT_SYMBOL_GPL(cdx_unregister_controller);
 
-- 
2.25.1


  parent reply	other threads:[~2023-08-14 10:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-14 10:22 [PATCH v3 0/5] cdx: provide sysfs interface for cdx device resources Abhijit Gangurde
2023-08-14 10:22 ` [PATCH v3 1/5] cdx: Remove cdx controller list from cdx bus system Abhijit Gangurde
2023-08-22 14:06   ` Greg KH
2023-08-24 12:10     ` Gangurde, Abhijit
2023-08-14 10:22 ` Abhijit Gangurde [this message]
2023-08-22 14:06   ` [PATCH v3 2/5] cdx: Introduce lock to protect controller ops Greg KH
2023-08-14 10:22 ` [PATCH v3 3/5] cdx: add support for bus enable and disable Abhijit Gangurde
2023-08-22 14:08   ` Greg KH
2023-08-24 12:11     ` Gangurde, Abhijit
2023-08-14 10:22 ` [PATCH v3 4/5] cdx: add sysfs for bus reset Abhijit Gangurde
2023-08-14 10:22 ` [PATCH v3 5/5] cdx: add sysfs for subsystem, class and revision Abhijit Gangurde

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=20230814102223.418046-3-abhijit.gangurde@amd.com \
    --to=abhijit.gangurde@amd.com \
    --cc=Nipun.Gupta@amd.com \
    --cc=git@amd.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=michal.simek@amd.com \
    --cc=nikhil.agarwal@amd.com \
    --cc=puneet.gupta@amd.com \
    /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

all inboxes | Powered by JetHome®