Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/4] ASoC: cs35l56: Set access permissions on volatile read-only controls
@ 2025-11-20 13:44 Richard Fitzgerald
  2025-11-20 13:44 ` [PATCH 1/4] ASoC: soc.h: Add SOC_ENUM_EXT_ACC() to allow setting access flags Richard Fitzgerald
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2025-11-20 13:44 UTC (permalink / raw)
  To: broonie; +Cc: linux-sound, linux-kernel, patches

The CAL_SET_STATUS and CAL_DATA_RB controls are volatile and read-only, but
the existing ASoC macros to define controls don't allow setting access
permissions, so those controls were marked as non-volatile read/write.
These four patches fix that.

The first two patches add two new control macros to soc.h. I really don't
like codec drivers open-coding a kcontrol_new content for a control that
will be managed by the ASoC info/get/put handlers. If a new type of ASoC
control definition is needed it's better to have it in soc.h so all the
dependencies between ASoC and the kcontrol_new content are in one place.

Richard Fitzgerald (4):
  ASoC: soc.h: Add SOC_ENUM_EXT_ACC() to allow setting access flags
  ASoC: soc.h: Add SND_SOC_BYTES_E_ACC() to allow setting access flags
  ASoC: cs35l56: Use SOC_ENUM_EXT_ACC() for CAL_SET_STATUS control
  ASoC: cs35l56: Use SND_SOC_BYTES_E_ACC() for CAL_DATA_RB control

 include/sound/soc.h        | 14 ++++++++++++++
 sound/soc/codecs/cs35l56.c | 15 +++++++++------
 2 files changed, 23 insertions(+), 6 deletions(-)

-- 
2.47.3


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] ASoC: soc.h: Add SOC_ENUM_EXT_ACC() to allow setting access flags
  2025-11-20 13:44 [PATCH 0/4] ASoC: cs35l56: Set access permissions on volatile read-only controls Richard Fitzgerald
@ 2025-11-20 13:44 ` Richard Fitzgerald
  2025-11-20 13:44 ` [PATCH 2/4] ASoC: soc.h: Add SND_SOC_BYTES_E_ACC() " Richard Fitzgerald
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2025-11-20 13:44 UTC (permalink / raw)
  To: broonie; +Cc: linux-sound, linux-kernel, patches

Add a macro SOC_ENUM_EXT_ACC() to allow the access permission flags
to be set. This is the same as SOC_ENUM_EXT() but with an extra
argument for the access flags.

This will be used by the cs35l56.c driver to create a read-only
volatile enum. It's preferable to avoid custom control macros in codec
drivers. Code maintenance is easier if all control macros are defined
together in soc.h.

This commit only creates this one macro that is actually going to be used.
There's no point cluttering soc.h with unused macros - that just adds a
maintenance burden. People can add equivalents for the other macros if
they need them.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 include/sound/soc.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 37dc6f6fc63f..b1b6b6a497da 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -319,6 +319,13 @@ struct platform_device;
 #define SOC_VALUE_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
 	SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put)
 
+#define SOC_ENUM_EXT_ACC(xname, xenum, xhandler_get, xhandler_put, xaccess) \
+{	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
+	.access = xaccess, \
+	.info = snd_soc_info_enum_double, \
+	.get = xhandler_get, .put = xhandler_put, \
+	.private_value = (unsigned long)&xenum }
+
 #define SND_SOC_BYTES(xname, xbase, xregs)		      \
 {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,   \
 	.info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] ASoC: soc.h: Add SND_SOC_BYTES_E_ACC() to allow setting access flags
  2025-11-20 13:44 [PATCH 0/4] ASoC: cs35l56: Set access permissions on volatile read-only controls Richard Fitzgerald
  2025-11-20 13:44 ` [PATCH 1/4] ASoC: soc.h: Add SOC_ENUM_EXT_ACC() to allow setting access flags Richard Fitzgerald
@ 2025-11-20 13:44 ` Richard Fitzgerald
  2025-11-20 13:44 ` [PATCH 3/4] ASoC: cs35l56: Use SOC_ENUM_EXT_ACC() for CAL_SET_STATUS control Richard Fitzgerald
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2025-11-20 13:44 UTC (permalink / raw)
  To: broonie; +Cc: linux-sound, linux-kernel, patches

Add a macro SND_SOC_BYTES_E_ACC() to allow the access permission flags
to be set. This is the same as SND_SOC_BYTES_E() but with an extra
argument for the access flags.

This will be used by the cs35l56.c driver to create a read-only
volatile byte control. It's preferable to avoid custom control macros
in codec drivers. Code maintenance is easier if all control macros are
defined together in soc.h.

This commit only creates this one macro that is actually going to be used.
There's no point cluttering soc.h with unused macros - that just adds a
maintenance burden. People can add equivalents for the other macros if
they need them.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 include/sound/soc.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index b1b6b6a497da..aa0fe6b80293 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -338,6 +338,13 @@ struct platform_device;
 	.put = xhandler_put, .private_value = \
 		((unsigned long)&(struct soc_bytes) \
 		{.base = xbase, .num_regs = xregs }) }
+#define SND_SOC_BYTES_E_ACC(xname, xbase, xregs, xhandler_get, xhandler_put, xaccess) \
+{	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
+	.access = xaccess, \
+	.info = snd_soc_bytes_info, .get = xhandler_get, \
+	.put = xhandler_put, .private_value = \
+		((unsigned long)&(struct soc_bytes) \
+		{.base = xbase, .num_regs = xregs }) }
 
 #define SND_SOC_BYTES_MASK(xname, xbase, xregs, xmask)	      \
 {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,   \
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] ASoC: cs35l56: Use SOC_ENUM_EXT_ACC() for CAL_SET_STATUS control
  2025-11-20 13:44 [PATCH 0/4] ASoC: cs35l56: Set access permissions on volatile read-only controls Richard Fitzgerald
  2025-11-20 13:44 ` [PATCH 1/4] ASoC: soc.h: Add SOC_ENUM_EXT_ACC() to allow setting access flags Richard Fitzgerald
  2025-11-20 13:44 ` [PATCH 2/4] ASoC: soc.h: Add SND_SOC_BYTES_E_ACC() " Richard Fitzgerald
@ 2025-11-20 13:44 ` Richard Fitzgerald
  2025-11-20 13:44 ` [PATCH 4/4] ASoC: cs35l56: Use SND_SOC_BYTES_E_ACC() for CAL_DATA_RB control Richard Fitzgerald
  2025-11-21 22:11 ` [PATCH 0/4] ASoC: cs35l56: Set access permissions on volatile read-only controls Mark Brown
  4 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2025-11-20 13:44 UTC (permalink / raw)
  To: broonie; +Cc: linux-sound, linux-kernel, patches

Use the new SOC_ENUM_EXT_ACC() macro instead of SOC_ENUM_EXT() to
define the CAL_SET_STATUS control, so that it is marked as read-only
and volatile.

This avoids userland code expecting to be able to write to it and
then getting an unexpected EPERM error, or assuming that its value
can never change.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 sound/soc/codecs/cs35l56.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/cs35l56.c b/sound/soc/codecs/cs35l56.c
index 802658720510..f5fd20c8cce1 100644
--- a/sound/soc/codecs/cs35l56.c
+++ b/sound/soc/codecs/cs35l56.c
@@ -95,8 +95,9 @@ static const struct snd_kcontrol_new cs35l56_controls[] = {
 	SOC_SINGLE_EXT("Posture Number", CS35L56_MAIN_POSTURE_NUMBER,
 		       0, 255, 0,
 		       cs35l56_dspwait_get_volsw, cs35l56_dspwait_put_volsw),
-	SOC_ENUM_EXT("CAL_SET_STATUS", cs35l56_cal_set_status_enum,
-		     cs35l56_cal_set_status_ctl_get, NULL),
+	SOC_ENUM_EXT_ACC("CAL_SET_STATUS", cs35l56_cal_set_status_enum,
+			 cs35l56_cal_set_status_ctl_get, NULL,
+			 SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE),
 };
 
 static const struct snd_kcontrol_new cs35l63_controls[] = {
@@ -116,8 +117,9 @@ static const struct snd_kcontrol_new cs35l63_controls[] = {
 	SOC_SINGLE_EXT("Posture Number", CS35L63_MAIN_POSTURE_NUMBER,
 		       0, 255, 0,
 		       cs35l56_dspwait_get_volsw, cs35l56_dspwait_put_volsw),
-	SOC_ENUM_EXT("CAL_SET_STATUS", cs35l56_cal_set_status_enum,
-		     cs35l56_cal_set_status_ctl_get, NULL),
+	SOC_ENUM_EXT_ACC("CAL_SET_STATUS", cs35l56_cal_set_status_enum,
+			 cs35l56_cal_set_status_ctl_get, NULL,
+			 SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE),
 };
 
 static SOC_VALUE_ENUM_SINGLE_DECL(cs35l56_asp1tx1_enum,
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] ASoC: cs35l56: Use SND_SOC_BYTES_E_ACC() for CAL_DATA_RB control
  2025-11-20 13:44 [PATCH 0/4] ASoC: cs35l56: Set access permissions on volatile read-only controls Richard Fitzgerald
                   ` (2 preceding siblings ...)
  2025-11-20 13:44 ` [PATCH 3/4] ASoC: cs35l56: Use SOC_ENUM_EXT_ACC() for CAL_SET_STATUS control Richard Fitzgerald
@ 2025-11-20 13:44 ` Richard Fitzgerald
  2025-11-21 22:11 ` [PATCH 0/4] ASoC: cs35l56: Set access permissions on volatile read-only controls Mark Brown
  4 siblings, 0 replies; 6+ messages in thread
From: Richard Fitzgerald @ 2025-11-20 13:44 UTC (permalink / raw)
  To: broonie; +Cc: linux-sound, linux-kernel, patches

Use the new SND_SOC_BYTES_E_ACC() macro instead of SND_SOC_BYTES_E()
to define the CAL_DATA_RB control, so that it is marked as read-only
and volatile.

This avoids userland code expecting to be able to write to it and
then getting an unexpected EPERM error, or assuming that its value
can never change.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 sound/soc/codecs/cs35l56.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/cs35l56.c b/sound/soc/codecs/cs35l56.c
index f5fd20c8cce1..d8a3babce0f6 100644
--- a/sound/soc/codecs/cs35l56.c
+++ b/sound/soc/codecs/cs35l56.c
@@ -1099,8 +1099,9 @@ static int cs35l56_cal_data_ctl_set(struct snd_kcontrol *kcontrol,
 static const struct snd_kcontrol_new cs35l56_cal_data_restore_controls[] = {
 	SND_SOC_BYTES_E("CAL_DATA", 0, sizeof(struct cirrus_amp_cal_data) / sizeof(u32),
 			cs35l56_cal_data_ctl_get, cs35l56_cal_data_ctl_set),
-	SND_SOC_BYTES_E("CAL_DATA_RB", 0, sizeof(struct cirrus_amp_cal_data) / sizeof(u32),
-			cs35l56_cal_data_rb_ctl_get, NULL),
+	SND_SOC_BYTES_E_ACC("CAL_DATA_RB", 0, sizeof(struct cirrus_amp_cal_data) / sizeof(u32),
+			cs35l56_cal_data_rb_ctl_get, NULL,
+			SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE),
 };
 
 static int cs35l56_set_fw_suffix(struct cs35l56_private *cs35l56)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] ASoC: cs35l56: Set access permissions on volatile read-only controls
  2025-11-20 13:44 [PATCH 0/4] ASoC: cs35l56: Set access permissions on volatile read-only controls Richard Fitzgerald
                   ` (3 preceding siblings ...)
  2025-11-20 13:44 ` [PATCH 4/4] ASoC: cs35l56: Use SND_SOC_BYTES_E_ACC() for CAL_DATA_RB control Richard Fitzgerald
@ 2025-11-21 22:11 ` Mark Brown
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2025-11-21 22:11 UTC (permalink / raw)
  To: Richard Fitzgerald; +Cc: linux-sound, linux-kernel, patches

On Thu, 20 Nov 2025 13:44:33 +0000, Richard Fitzgerald wrote:
> The CAL_SET_STATUS and CAL_DATA_RB controls are volatile and read-only, but
> the existing ASoC macros to define controls don't allow setting access
> permissions, so those controls were marked as non-volatile read/write.
> These four patches fix that.
> 
> The first two patches add two new control macros to soc.h. I really don't
> like codec drivers open-coding a kcontrol_new content for a control that
> will be managed by the ASoC info/get/put handlers. If a new type of ASoC
> control definition is needed it's better to have it in soc.h so all the
> dependencies between ASoC and the kcontrol_new content are in one place.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/4] ASoC: soc.h: Add SOC_ENUM_EXT_ACC() to allow setting access flags
      commit: cf6ec18ea6e12569b83af2709d0bd0cc09da198f
[2/4] ASoC: soc.h: Add SND_SOC_BYTES_E_ACC() to allow setting access flags
      commit: d7a82707f19c7a11ce42dd46cb22ca34a58cc9b0
[3/4] ASoC: cs35l56: Use SOC_ENUM_EXT_ACC() for CAL_SET_STATUS control
      commit: 4dd7f8aeed4c85234f3855ef3188ed2202f2c947
[4/4] ASoC: cs35l56: Use SND_SOC_BYTES_E_ACC() for CAL_DATA_RB control
      commit: 33822d795ab93067d9a65f42003c0d01c65d4a9d

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-11-21 22:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-20 13:44 [PATCH 0/4] ASoC: cs35l56: Set access permissions on volatile read-only controls Richard Fitzgerald
2025-11-20 13:44 ` [PATCH 1/4] ASoC: soc.h: Add SOC_ENUM_EXT_ACC() to allow setting access flags Richard Fitzgerald
2025-11-20 13:44 ` [PATCH 2/4] ASoC: soc.h: Add SND_SOC_BYTES_E_ACC() " Richard Fitzgerald
2025-11-20 13:44 ` [PATCH 3/4] ASoC: cs35l56: Use SOC_ENUM_EXT_ACC() for CAL_SET_STATUS control Richard Fitzgerald
2025-11-20 13:44 ` [PATCH 4/4] ASoC: cs35l56: Use SND_SOC_BYTES_E_ACC() for CAL_DATA_RB control Richard Fitzgerald
2025-11-21 22:11 ` [PATCH 0/4] ASoC: cs35l56: Set access permissions on volatile read-only controls Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox