ASoC: cs35l56: Set access permissions on volatile read-only controls
Subsystems (3)
Richard Fitzgerald
maintainercover ASoC: cs35l56: Set access permissions on volatile read-only controls
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(-)
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH 1/4 ASoC: soc.h: Add SOC_ENUM_EXT_ACC() to allow setting access flags
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.
--- include/sound/soc.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/sound/soc.h +7 -0
@@ -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, \
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH 2/4 ASoC: soc.h: Add SND_SOC_BYTES_E_ACC() to allow setting access flags
In reply to Richard FitzgeraldAdd 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.
--- include/sound/soc.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/sound/soc.h +7 -0
@@ -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, \
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH 3/4 ASoC: cs35l56: Use SOC_ENUM_EXT_ACC() for CAL_SET_STATUS control
In reply to Richard FitzgeraldUse 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.
--- sound/soc/codecs/cs35l56.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
sound/soc/codecs/cs35l56.c +6 -4
@@ -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,
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH 4/4 ASoC: cs35l56: Use SND_SOC_BYTES_E_ACC() for CAL_DATA_RB control
In reply to Richard FitzgeraldUse 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.
--- sound/soc/codecs/cs35l56.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
sound/soc/codecs/cs35l56.c +3 -2
@@ -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)
Signature · 1 line
2.47.3
Mark Brown
maintainerQuoted 5 lines · Richard Fitzgerald
The
CAL_SET_STATUSandCAL_DATA_RBcontrols 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.
Quoted 7 lines
The first two patches add two new control macros to
soc.h. I really don't like codec drivers open-coding akcontrol_newcontent 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 insoc.hso all the dependencies between ASoC and thekcontrol_newcontent 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: 33822d795ab93067d9a65f42003c0d01c65d4a9dAll 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