Commit cc58055b authored by Charles Keepax's avatar Charles Keepax Committed by Mark Brown
Browse files

ASoC: SDCA: Correct FDL locking in sdca_fdl_process()



The current locking in sdca_fdl_process() locks over
sdca_ump_cancel_timeout() and the timeout work function takes the same
lock, this can lead to a deadlock if the work runs as part of the
cancel. To fix this use scoped_guard and move the cancel timeout to be
outside the lock.

Fixes: e92e25f7 ("ASoC: SDCA: Add UMP timeout handling for FDL")
Tested-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: default avatarMaciej Strozek <mstrozek@opensource.cirrus.com>
Reviewed-by: default avatarPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Tested-by: default avatarRichard Fitzgerald <rf@opensource.cirrus.com>
Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
Link: https://patch.msgid.link/20251120153023.2105663-5-ckeepax@opensource.cirrus.com


Reviewed-by: default avatarVinod Koul <vkoul@kernel.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 5fe65824
Loading
Loading
Loading
Loading
+45 −44
Original line number Diff line number Diff line
@@ -402,8 +402,6 @@ int sdca_fdl_process(struct sdca_interrupt *interrupt)
	unsigned int reg, status;
	int response, ret;

	guard(mutex)(&fdl_state->lock);

	ret = sdca_ump_get_owner_host(dev, interrupt->function_regmap,
				      interrupt->function, interrupt->entity,
				      interrupt->control);
@@ -412,8 +410,9 @@ int sdca_fdl_process(struct sdca_interrupt *interrupt)

	sdca_ump_cancel_timeout(&fdl_state->timeout);

	reg = SDW_SDCA_CTL(interrupt->function->desc->adr, interrupt->entity->id,
			   SDCA_CTL_XU_FDL_STATUS, 0);
	scoped_guard(mutex, &fdl_state->lock) {
		reg = SDW_SDCA_CTL(interrupt->function->desc->adr,
				   interrupt->entity->id, SDCA_CTL_XU_FDL_STATUS, 0);
		ret = regmap_read(interrupt->function_regmap, reg, &status);
		if (ret < 0) {
			dev_err(dev, "failed to read FDL status: %d\n", ret);
@@ -438,7 +437,8 @@ int sdca_fdl_process(struct sdca_interrupt *interrupt)
		}

		ret = sdca_ump_set_owner_device(dev, interrupt->function_regmap,
					interrupt->function, interrupt->entity,
						interrupt->function,
						interrupt->entity,
						interrupt->control);
		if (ret)
			return ret;
@@ -463,6 +463,7 @@ int sdca_fdl_process(struct sdca_interrupt *interrupt)
			sdca_ump_schedule_timeout(&fdl_state->timeout, xu->max_delay);
			return 0;
		}
	}

reset_function:
	sdca_reset_function(dev, interrupt->function, interrupt->function_regmap);