public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Cristian Marussi" <cristian.marussi@arm.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Sudeep Holla" <sudeep.holla@arm.com>,
	"Sasha Levin" <sashal@kernel.org>,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH AUTOSEL 6.0 12/30] firmware: arm_scmi: Cleanup the core driver removal callback
Date: Thu, 10 Nov 2022 21:33:20 -0500	[thread overview]
Message-ID: <20221111023340.227279-12-sashal@kernel.org> (raw)
In-Reply-To: <20221111023340.227279-1-sashal@kernel.org>

From: Cristian Marussi <cristian.marussi@arm.com>

[ Upstream commit 3f4071cbd2063b917486d1047a4da47718215fee ]

Platform drivers .remove callbacks are not supposed to fail and report
errors. Such errors are indeed ignored by the core platform drivers
and the driver unbind process is anyway completed.

The SCMI core platform driver as it is now, instead, bails out reporting
an error in case of an explicit unbind request.

Fix the removal path by adding proper device links between the core SCMI
device and the SCMI protocol devices so that a full SCMI stack unbind is
triggered when the core driver is removed. The remove process does not
bail out anymore on the anomalous conditions triggered by an explicit
unbind but the user is still warned.

Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Link: https://lore.kernel.org/r/20221028140833.280091-1-cristian.marussi@arm.com
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/firmware/arm_scmi/bus.c    | 11 +++++++++++
 drivers/firmware/arm_scmi/common.h |  1 +
 drivers/firmware/arm_scmi/driver.c | 31 ++++++++++++++++++------------
 3 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index d4e23101448a..35bb70724d44 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -216,9 +216,20 @@ void scmi_device_destroy(struct scmi_device *scmi_dev)
 	device_unregister(&scmi_dev->dev);
 }
 
+void scmi_device_link_add(struct device *consumer, struct device *supplier)
+{
+	struct device_link *link;
+
+	link = device_link_add(consumer, supplier, DL_FLAG_AUTOREMOVE_CONSUMER);
+
+	WARN_ON(!link);
+}
+
 void scmi_set_handle(struct scmi_device *scmi_dev)
 {
 	scmi_dev->handle = scmi_handle_get(&scmi_dev->dev);
+	if (scmi_dev->handle)
+		scmi_device_link_add(&scmi_dev->dev, scmi_dev->handle->dev);
 }
 
 int scmi_protocol_register(const struct scmi_protocol *proto)
diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h
index 61aba7447c32..9b87b5b69535 100644
--- a/drivers/firmware/arm_scmi/common.h
+++ b/drivers/firmware/arm_scmi/common.h
@@ -97,6 +97,7 @@ static inline void unpack_scmi_header(u32 msg_hdr, struct scmi_msg_hdr *hdr)
 struct scmi_revision_info *
 scmi_revision_area_get(const struct scmi_protocol_handle *ph);
 int scmi_handle_put(const struct scmi_handle *handle);
+void scmi_device_link_add(struct device *consumer, struct device *supplier);
 struct scmi_handle *scmi_handle_get(struct device *dev);
 void scmi_set_handle(struct scmi_device *scmi_dev);
 void scmi_setup_protocol_implemented(const struct scmi_protocol_handle *ph,
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 609ebedee9cb..7e19b6055d75 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2273,10 +2273,16 @@ int scmi_protocol_device_request(const struct scmi_device_id *id_table)
 			sdev = scmi_get_protocol_device(child, info,
 							id_table->protocol_id,
 							id_table->name);
-			/* Set handle if not already set: device existed */
-			if (sdev && !sdev->handle)
-				sdev->handle =
-					scmi_handle_get_from_info_unlocked(info);
+			if (sdev) {
+				/* Set handle if not already set: device existed */
+				if (!sdev->handle)
+					sdev->handle =
+						scmi_handle_get_from_info_unlocked(info);
+				/* Relink consumer and suppliers */
+				if (sdev->handle)
+					scmi_device_link_add(&sdev->dev,
+							     sdev->handle->dev);
+			}
 		} else {
 			dev_err(info->dev,
 				"Failed. SCMI protocol %d not active.\n",
@@ -2475,20 +2481,17 @@ void scmi_free_channel(struct scmi_chan_info *cinfo, struct idr *idr, int id)
 
 static int scmi_remove(struct platform_device *pdev)
 {
-	int ret = 0, id;
+	int ret, id;
 	struct scmi_info *info = platform_get_drvdata(pdev);
 	struct device_node *child;
 
 	mutex_lock(&scmi_list_mutex);
 	if (info->users)
-		ret = -EBUSY;
-	else
-		list_del(&info->node);
+		dev_warn(&pdev->dev,
+			 "Still active SCMI users will be forcibly unbound.\n");
+	list_del(&info->node);
 	mutex_unlock(&scmi_list_mutex);
 
-	if (ret)
-		return ret;
-
 	scmi_notification_exit(&info->handle);
 
 	mutex_lock(&info->protocols_mtx);
@@ -2500,7 +2503,11 @@ static int scmi_remove(struct platform_device *pdev)
 	idr_destroy(&info->active_protocols);
 
 	/* Safe to free channels since no more users */
-	return scmi_cleanup_txrx_channels(info);
+	ret = scmi_cleanup_txrx_channels(info);
+	if (ret)
+		dev_warn(&pdev->dev, "Failed to cleanup SCMI channels.\n");
+
+	return 0;
 }
 
 static ssize_t protocol_version_show(struct device *dev,
-- 
2.35.1


  parent reply	other threads:[~2022-11-11  2:34 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11  2:33 [PATCH AUTOSEL 6.0 01/30] cxl/mbox: Add a check on input payload size Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 02/30] RDMA/efa: Add EFA 0xefa2 PCI ID Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 03/30] btrfs: raid56: properly handle the error when unable to find the missing stripe Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 04/30] NFSv4: Retry LOCK on OLD_STATEID during delegation return Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 05/30] SUNRPC: Fix crasher in gss_unwrap_resp_integ() Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 06/30] ACPI: x86: Add another system to quirk list for forcing StorageD3Enable Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 07/30] drm/rockchip: vop2: fix null pointer in plane_atomic_disable Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 08/30] drm/rockchip: vop2: disable planes when disabling the crtc Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 09/30] ksefltests: pidfd: Fix wait_states: Test terminated by timeout Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 10/30] powerpc/64e: Fix amdgpu build on Book3E w/o AltiVec Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 11/30] block: blk_add_rq_to_plug(): clear stale 'last' after flush Sasha Levin
2022-11-11  2:33 ` Sasha Levin [this message]
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 13/30] firmware: arm_scmi: Make tx_prepare time out eventually Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 14/30] i2c: tegra: Allocate DMA memory for DMA engine Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 15/30] i2c: i801: add lis3lv02d's I2C address for Vostro 5568 Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 16/30] drm/imx: imx-tve: Fix return type of imx_tve_connector_mode_valid Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 17/30] btrfs: remove pointless and double ulist frees in error paths of qgroup tests Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 18/30] drm/amd/display: Ignore Cable ID Feature Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 19/30] drm/amd/display: Enable timing sync on DCN32 Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 20/30] drm/amdgpu: set fb_modifiers_not_supported in vkms Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 21/30] drm/amd: Fail the suspend if resources can't be evicted Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 22/30] drm/amd/display: Fix DCN32 DSC delay calculation Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 23/30] drm/amd/display: Use forced DSC bpp in DML Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 24/30] drm/amd/display: Round up DST_after_scaler to nearest int Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 25/30] drm/amd/display: Investigate tool reported FCLK P-state deviations Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 26/30] Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 27/30] cxl/pmem: Use size_add() against integer overflow Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 28/30] x86/cpu: Add several Intel server CPU model numbers Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 29/30] tools/testing/cxl: Fix some error exits Sasha Levin
2022-11-11  2:33 ` [PATCH AUTOSEL 6.0 30/30] cifs: always iterate smb sessions using primary channel Sasha Levin

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=20221111023340.227279-12-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=cristian.marussi@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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