All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cristian Marussi <cristian.marussi@arm.com>
To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: sudeep.holla@arm.com, cristian.marussi@arm.com,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH 6/8] firmware: arm_scmi: Fix deferred_tx_wq release on error paths
Date: Fri, 28 Oct 2022 15:08:31 +0100	[thread overview]
Message-ID: <20221028140833.280091-6-cristian.marussi@arm.com> (raw)
In-Reply-To: <20221028140833.280091-1-cristian.marussi@arm.com>

Use devres to allocate the dedicated deferred_tx_wq polling workqueue so
as to automatically trigger the proper resource release on error path.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 5a3b7185c47c ("firmware: arm_scmi: Add atomic mode support to virtio transport")
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
 drivers/firmware/arm_scmi/virtio.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/firmware/arm_scmi/virtio.c b/drivers/firmware/arm_scmi/virtio.c
index 36b7686843a4..33c9b81a55cd 100644
--- a/drivers/firmware/arm_scmi/virtio.c
+++ b/drivers/firmware/arm_scmi/virtio.c
@@ -148,7 +148,6 @@ static void scmi_vio_channel_cleanup_sync(struct scmi_vio_channel *vioch)
 {
 	unsigned long flags;
 	DECLARE_COMPLETION_ONSTACK(vioch_shutdown_done);
-	void *deferred_wq = NULL;
 
 	/*
 	 * Prepare to wait for the last release if not already released
@@ -162,16 +161,11 @@ static void scmi_vio_channel_cleanup_sync(struct scmi_vio_channel *vioch)
 
 	vioch->shutdown_done = &vioch_shutdown_done;
 	virtio_break_device(vioch->vqueue->vdev);
-	if (!vioch->is_rx && vioch->deferred_tx_wq) {
-		deferred_wq = vioch->deferred_tx_wq;
+	if (!vioch->is_rx && vioch->deferred_tx_wq)
 		/* Cannot be kicked anymore after this...*/
 		vioch->deferred_tx_wq = NULL;
-	}
 	spin_unlock_irqrestore(&vioch->lock, flags);
 
-	if (deferred_wq)
-		destroy_workqueue(deferred_wq);
-
 	scmi_vio_channel_release(vioch);
 
 	/* Let any possibly concurrent RX path release the channel */
@@ -416,6 +410,11 @@ static bool virtio_chan_available(struct device *dev, int idx)
 	return vioch && !vioch->cinfo;
 }
 
+static void scmi_destroy_tx_workqueue(void *deferred_tx_wq)
+{
+	destroy_workqueue(deferred_tx_wq);
+}
+
 static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 			     bool tx)
 {
@@ -430,6 +429,8 @@ static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 
 	/* Setup a deferred worker for polling. */
 	if (tx && !vioch->deferred_tx_wq) {
+		int ret;
+
 		vioch->deferred_tx_wq =
 			alloc_workqueue(dev_name(&scmi_vdev->dev),
 					WQ_UNBOUND | WQ_FREEZABLE | WQ_SYSFS,
@@ -437,6 +438,11 @@ static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 		if (!vioch->deferred_tx_wq)
 			return -ENOMEM;
 
+		ret = devm_add_action_or_reset(dev, scmi_destroy_tx_workqueue,
+					       vioch->deferred_tx_wq);
+		if (ret)
+			return ret;
+
 		INIT_WORK(&vioch->deferred_tx_work,
 			  scmi_vio_deferred_tx_worker);
 	}
-- 
2.34.1


WARNING: multiple messages have this Message-ID (diff)
From: Cristian Marussi <cristian.marussi@arm.com>
To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: sudeep.holla@arm.com, cristian.marussi@arm.com,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH 6/8] firmware: arm_scmi: Fix deferred_tx_wq release on error paths
Date: Fri, 28 Oct 2022 15:08:31 +0100	[thread overview]
Message-ID: <20221028140833.280091-6-cristian.marussi@arm.com> (raw)
In-Reply-To: <20221028140833.280091-1-cristian.marussi@arm.com>

Use devres to allocate the dedicated deferred_tx_wq polling workqueue so
as to automatically trigger the proper resource release on error path.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 5a3b7185c47c ("firmware: arm_scmi: Add atomic mode support to virtio transport")
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
 drivers/firmware/arm_scmi/virtio.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/firmware/arm_scmi/virtio.c b/drivers/firmware/arm_scmi/virtio.c
index 36b7686843a4..33c9b81a55cd 100644
--- a/drivers/firmware/arm_scmi/virtio.c
+++ b/drivers/firmware/arm_scmi/virtio.c
@@ -148,7 +148,6 @@ static void scmi_vio_channel_cleanup_sync(struct scmi_vio_channel *vioch)
 {
 	unsigned long flags;
 	DECLARE_COMPLETION_ONSTACK(vioch_shutdown_done);
-	void *deferred_wq = NULL;
 
 	/*
 	 * Prepare to wait for the last release if not already released
@@ -162,16 +161,11 @@ static void scmi_vio_channel_cleanup_sync(struct scmi_vio_channel *vioch)
 
 	vioch->shutdown_done = &vioch_shutdown_done;
 	virtio_break_device(vioch->vqueue->vdev);
-	if (!vioch->is_rx && vioch->deferred_tx_wq) {
-		deferred_wq = vioch->deferred_tx_wq;
+	if (!vioch->is_rx && vioch->deferred_tx_wq)
 		/* Cannot be kicked anymore after this...*/
 		vioch->deferred_tx_wq = NULL;
-	}
 	spin_unlock_irqrestore(&vioch->lock, flags);
 
-	if (deferred_wq)
-		destroy_workqueue(deferred_wq);
-
 	scmi_vio_channel_release(vioch);
 
 	/* Let any possibly concurrent RX path release the channel */
@@ -416,6 +410,11 @@ static bool virtio_chan_available(struct device *dev, int idx)
 	return vioch && !vioch->cinfo;
 }
 
+static void scmi_destroy_tx_workqueue(void *deferred_tx_wq)
+{
+	destroy_workqueue(deferred_tx_wq);
+}
+
 static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 			     bool tx)
 {
@@ -430,6 +429,8 @@ static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 
 	/* Setup a deferred worker for polling. */
 	if (tx && !vioch->deferred_tx_wq) {
+		int ret;
+
 		vioch->deferred_tx_wq =
 			alloc_workqueue(dev_name(&scmi_vdev->dev),
 					WQ_UNBOUND | WQ_FREEZABLE | WQ_SYSFS,
@@ -437,6 +438,11 @@ static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 		if (!vioch->deferred_tx_wq)
 			return -ENOMEM;
 
+		ret = devm_add_action_or_reset(dev, scmi_destroy_tx_workqueue,
+					       vioch->deferred_tx_wq);
+		if (ret)
+			return ret;
+
 		INIT_WORK(&vioch->deferred_tx_work,
 			  scmi_vio_deferred_tx_worker);
 	}
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-10-28 14:09 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28 14:08 [PATCH 1/8] firmware: arm_scmi: Cleanup core driver removal callback Cristian Marussi
2022-10-28 14:08 ` Cristian Marussi
2022-10-28 14:08 ` [PATCH 2/8] firmware: arm_scmi: Suppress bind attributes Cristian Marussi
2022-10-28 14:08   ` Cristian Marussi
2022-10-28 14:08 ` [PATCH 3/8] firmware: arm_scmi: Make tx_prepare time out eventually Cristian Marussi
2022-10-28 14:08   ` Cristian Marussi
2022-10-28 14:08 ` [PATCH 4/8] firmware: arm_scmi: Make RX chan_setup fail on memory errors Cristian Marussi
2022-10-28 14:08   ` Cristian Marussi
2022-10-28 14:08 ` [PATCH 5/8] firmware: arm_scmi: Fix devres allocation device in virtio Cristian Marussi
2022-10-28 14:08   ` Cristian Marussi
2022-10-28 14:08 ` Cristian Marussi [this message]
2022-10-28 14:08   ` [PATCH 6/8] firmware: arm_scmi: Fix deferred_tx_wq release on error paths Cristian Marussi
2022-10-28 14:08 ` [PATCH 7/8] hwmon: (scmi) Register explicitly with Thermal Framework Cristian Marussi
2022-10-28 14:08   ` Cristian Marussi
2022-10-28 15:11   ` Guenter Roeck
2022-10-28 15:11     ` Guenter Roeck
2022-10-28 15:35     ` Cristian Marussi
2022-10-28 15:35       ` Cristian Marussi
2022-10-28 15:58       ` Guenter Roeck
2022-10-28 15:58         ` Guenter Roeck
2022-10-28 16:15         ` Cristian Marussi
2022-10-28 16:15           ` Cristian Marussi
2022-10-28 16:34           ` Guenter Roeck
2022-10-28 16:34             ` Guenter Roeck
2022-10-28 17:12             ` Cristian Marussi
2022-10-28 17:12               ` Cristian Marussi
2022-10-31 11:40             ` [PATCH v2 " Cristian Marussi
2022-10-31 11:40               ` Cristian Marussi
2022-10-31 13:25               ` Sudeep Holla
2022-10-31 13:25                 ` Sudeep Holla
2022-10-31 14:00                 ` Guenter Roeck
2022-10-31 14:00                   ` Guenter Roeck
2022-10-31 14:04                   ` Sudeep Holla
2022-10-31 14:04                     ` Sudeep Holla
2022-10-28 14:08 ` [PATCH 8/8] arm64: dts: juno: Add Thermal critical trip points Cristian Marussi
2022-10-28 14:08   ` Cristian Marussi
2022-11-03  7:14   ` Sudeep Holla
2022-11-03  7:14     ` Sudeep Holla
2022-11-03  7:09 ` [PATCH 1/8] firmware: arm_scmi: Cleanup core driver removal callback Sudeep Holla
2022-11-03  7:09   ` Sudeep Holla

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=20221028140833.280091-6-cristian.marussi@arm.com \
    --to=cristian.marussi@arm.com \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sudeep.holla@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.