From: Abhijit Gangurde <abhijit.gangurde@amd.com>
To: <gregkh@linuxfoundation.org>, <masahiroy@kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: <michal.simek@amd.com>, <git@amd.com>, <nikhil.agarwal@amd.com>,
<Nipun.Gupta@amd.com>,
Abhijit Gangurde <abhijit.gangurde@amd.com>
Subject: [PATCH v2 1/4] cdx: Introduce lock to protect controller ops and controller list
Date: Mon, 31 Jul 2023 17:38:10 +0530 [thread overview]
Message-ID: <20230731120813.123247-2-abhijit.gangurde@amd.com> (raw)
In-Reply-To: <20230731120813.123247-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 | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c
index d2cad4c670a0..66797c8fe400 100644
--- a/drivers/cdx/cdx.c
+++ b/drivers/cdx/cdx.c
@@ -72,6 +72,8 @@
/* CDX controllers registered with the CDX bus */
static DEFINE_XARRAY_ALLOC(cdx_controllers);
+/* Lock to protect controller ops and controller list */
+static DEFINE_MUTEX(cdx_controller_lock);
/**
* cdx_dev_reset - Reset a CDX device
@@ -393,6 +395,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);
@@ -405,6 +409,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
dev_err(cdx->dev, "cdx bus scanning failed\n");
}
+ mutex_unlock(&cdx_controller_lock);
+
return count;
}
static BUS_ATTR_WO(rescan);
@@ -520,9 +526,12 @@ int cdx_register_controller(struct cdx_controller *cdx)
{
int ret;
+ mutex_lock(&cdx_controller_lock);
+
ret = xa_alloc(&cdx_controllers, &cdx->id, cdx,
XA_LIMIT(0, MAX_CDX_CONTROLLERS - 1), GFP_KERNEL);
if (ret) {
+ mutex_unlock(&cdx_controller_lock);
dev_err(cdx->dev,
"No free index available. Maximum controllers already registered\n");
cdx->id = (u8)MAX_CDX_CONTROLLERS;
@@ -531,6 +540,7 @@ int cdx_register_controller(struct cdx_controller *cdx)
/* Scan all the devices */
cdx->ops->scan(cdx);
+ mutex_unlock(&cdx_controller_lock);
return 0;
}
@@ -541,8 +551,12 @@ void cdx_unregister_controller(struct cdx_controller *cdx)
if (cdx->id >= MAX_CDX_CONTROLLERS)
return;
+ mutex_lock(&cdx_controller_lock);
+
device_for_each_child(cdx->dev, NULL, cdx_unregister_device);
xa_erase(&cdx_controllers, cdx->id);
+
+ mutex_unlock(&cdx_controller_lock);
}
EXPORT_SYMBOL_GPL(cdx_unregister_controller);
--
2.25.1
next prev parent reply other threads:[~2023-07-31 12:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 12:08 [PATCH v2 0/4] cdx: provide sysfs interface for cdx device resources Abhijit Gangurde
2023-07-31 12:08 ` Abhijit Gangurde [this message]
2023-07-31 12:24 ` [PATCH v2 1/4] cdx: Introduce lock to protect controller ops and controller list Greg KH
2023-08-01 8:34 ` Gangurde, Abhijit
2023-08-01 8:40 ` Greg KH
2023-08-02 11:20 ` Gangurde, Abhijit
2023-08-02 11:49 ` Greg KH
2023-08-04 11:11 ` Gangurde, Abhijit
2023-07-31 12:08 ` [PATCH v2 2/4] cdx: add support for bus enable and disable Abhijit Gangurde
2023-07-31 12:08 ` [PATCH v2 3/4] cdx: add sysfs for bus reset Abhijit Gangurde
2023-07-31 12:08 ` [PATCH v2 4/4] 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=20230731120813.123247-2-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 \
/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®