[PATCH 1/2] soundwire: bus: downgrade expected unattach warnings to dev_dbg

Cole Leavitt posted 2 patches 1 month, 2 weeks ago
[PATCH 1/2] soundwire: bus: downgrade expected unattach warnings to dev_dbg
Posted by Cole Leavitt 1 month, 2 weeks ago
The sdw_handle_slave_status() function emits dev_warn() whenever a
peripheral transitions to UNATTACHED from a previously ATTACHED state.
While useful for debugging genuinely unexpected detachments, this
warning also fires during normal operation when a codec driver
intentionally triggers a system reset (e.g., after firmware download),
causing unnecessary noise in the kernel log on every boot.

Add an 'unattach_pending' flag to struct sdw_slave that codec drivers
can set before triggering an expected detach. When this flag is set,
the bus layer emits a dev_dbg() instead of dev_warn() and clears the
flag, preserving the warning for genuinely unexpected detachments.

Signed-off-by: Cole Leavitt <cole@unwrap.rs>
---
 drivers/soundwire/bus.c       | 9 +++++++--
 include/linux/soundwire/sdw.h | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index fb68738dfb9b..a5a71ab1feed 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -1899,8 +1899,13 @@ int sdw_handle_slave_status(struct sdw_bus *bus,
 
 		if (status[i] == SDW_SLAVE_UNATTACHED &&
 		    slave->status != SDW_SLAVE_UNATTACHED) {
-			dev_warn(&slave->dev, "Slave %d state check1: UNATTACHED, status was %d\n",
-				 i, slave->status);
+			if (slave->unattach_pending)
+				dev_dbg(&slave->dev, "Slave %d state check1: UNATTACHED (expected), status was %d\n",
+					i, slave->status);
+			else
+				dev_warn(&slave->dev, "Slave %d state check1: UNATTACHED, status was %d\n",
+					 i, slave->status);
+			slave->unattach_pending = false;
 			sdw_modify_slave_status(slave, SDW_SLAVE_UNATTACHED);
 
 			/* Ensure driver knows that peripheral unattached */
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index f462717acf20..4318f2b144e1 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -682,6 +682,7 @@ struct sdw_slave {
 	struct completion enumeration_complete;
 	struct completion initialization_complete;
 	u32 unattach_request;
+	bool unattach_pending;
 	bool first_interrupt_done;
 	bool is_mockup_device;
 	struct mutex sdw_dev_lock; /* protect callbacks/remove races */
-- 
2.52.0