Unverified Commit 061fade7 authored by Charles Keepax's avatar Charles Keepax Committed by Mark Brown
Browse files

ASoC: SDCA: Fix some holes in the regmap readable/writeable helpers



The current regmap readable/writeable helper functions always
allow the Next flag and allows any Control Number. Mask the Next
flag based on SDCA_ACCESS_MODE_DUAL which is the only Mode that
supports it. Also check that the Control Number is valid for
the given control.

Fixes: e3f7caf7 ("ASoC: SDCA: Add generic regmap SDCA helpers")
Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
Link: https://patch.msgid.link/20250718135432.1048566-2-ckeepax@opensource.cirrus.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent c58c35ef
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -72,12 +72,18 @@ bool sdca_regmap_readable(struct sdca_function_data *function, unsigned int reg)
	if (!control)
		return false;

	if (!(BIT(SDW_SDCA_CTL_CNUM(reg)) & control->cn_list))
		return false;

	switch (control->mode) {
	case SDCA_ACCESS_MODE_RW:
	case SDCA_ACCESS_MODE_RO:
	case SDCA_ACCESS_MODE_DUAL:
	case SDCA_ACCESS_MODE_RW1S:
	case SDCA_ACCESS_MODE_RW1C:
		if (SDW_SDCA_NEXT_CTL(0) & reg)
			return false;
		fallthrough;
	case SDCA_ACCESS_MODE_DUAL:
		/* No access to registers marked solely for device use */
		return control->layers & ~SDCA_ACCESS_LAYER_DEVICE;
	default:
@@ -104,11 +110,17 @@ bool sdca_regmap_writeable(struct sdca_function_data *function, unsigned int reg
	if (!control)
		return false;

	if (!(BIT(SDW_SDCA_CTL_CNUM(reg)) & control->cn_list))
		return false;

	switch (control->mode) {
	case SDCA_ACCESS_MODE_RW:
	case SDCA_ACCESS_MODE_DUAL:
	case SDCA_ACCESS_MODE_RW1S:
	case SDCA_ACCESS_MODE_RW1C:
		if (SDW_SDCA_NEXT_CTL(0) & reg)
			return false;
		fallthrough;
	case SDCA_ACCESS_MODE_DUAL:
		/* No access to registers marked solely for device use */
		return control->layers & ~SDCA_ACCESS_LAYER_DEVICE;
	default: