[alsa-devel] [PATCH 1/3] ALSA: vx222: Use container_of()
The vx222 driver is using the explicit cast from the parent class pointer, but it'll be broken when the structure field randomization is applied. Use container_of() in a modern manner, instead.
Signed-off-by: Takashi Iwai tiwai@suse.de --- sound/pci/vx222/vx222.c | 4 ++-- sound/pci/vx222/vx222.h | 2 ++ sound/pci/vx222/vx222_ops.c | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/sound/pci/vx222/vx222.c b/sound/pci/vx222/vx222.c index ecbaf473fc1e..55861849d7df 100644 --- a/sound/pci/vx222/vx222.c +++ b/sound/pci/vx222/vx222.c @@ -116,7 +116,7 @@ static struct snd_vx_hardware vx222_mic_hw = { */ static int snd_vx222_free(struct vx_core *chip) { - struct snd_vx222 *vx = (struct snd_vx222 *)chip; + struct snd_vx222 *vx = to_vx222(chip);
if (chip->irq >= 0) free_irq(chip->irq, (void*)chip); @@ -158,7 +158,7 @@ static int snd_vx222_create(struct snd_card *card, struct pci_dev *pci, pci_disable_device(pci); return -ENOMEM; } - vx = (struct snd_vx222 *)chip; + vx = to_vx222(chip); vx->pci = pci;
if ((err = pci_request_regions(pci, CARD_NAME)) < 0) { diff --git a/sound/pci/vx222/vx222.h b/sound/pci/vx222/vx222.h index 2f0d78f609a6..cae355c8ed28 100644 --- a/sound/pci/vx222/vx222.h +++ b/sound/pci/vx222/vx222.h @@ -39,6 +39,8 @@ struct snd_vx222 { int mic_level; /* mic level for vx222 mic */ };
+#define to_vx222(x) container_of(x, struct snd_vx222, core) + /* we use a lookup table with 148 values, see vx_mixer.c */ #define VX2_AKM_LEVEL_MAX 0x93
diff --git a/sound/pci/vx222/vx222_ops.c b/sound/pci/vx222/vx222_ops.c index 7df1663ea510..d4298af6d3ee 100644 --- a/sound/pci/vx222/vx222_ops.c +++ b/sound/pci/vx222/vx222_ops.c @@ -86,7 +86,7 @@ static int vx2_reg_index[VX_REG_MAX] = {
static inline unsigned long vx2_reg_addr(struct vx_core *_chip, int reg) { - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip); return chip->port[vx2_reg_index[reg]] + vx2_reg_offset[reg]; }
@@ -159,7 +159,7 @@ static void vx2_outl(struct vx_core *chip, int offset, unsigned int val)
static void vx2_reset_dsp(struct vx_core *_chip) { - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip);
/* set the reset dsp bit to 0 */ vx_outl(chip, CDSP, chip->regCDSP & ~VX_CDSP_DSP_RESET_MASK); @@ -174,7 +174,7 @@ static void vx2_reset_dsp(struct vx_core *_chip)
static int vx2_test_xilinx(struct vx_core *_chip) { - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip); unsigned int data;
dev_dbg(_chip->card->dev, "testing xilinx...\n"); @@ -479,7 +479,7 @@ static int vx2_test_and_ack(struct vx_core *chip) */ static void vx2_validate_irq(struct vx_core *_chip, int enable) { - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip);
/* Set the interrupt enable bit to 1 in CDSP register */ if (enable) { @@ -730,7 +730,7 @@ static void vx2_old_write_codec_bit(struct vx_core *chip, int codec, unsigned in */ static void vx2_reset_codec(struct vx_core *_chip) { - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip);
/* Set the reset CODEC bit to 0. */ vx_outl(chip, CDSP, chip->regCDSP &~ VX_CDSP_CODEC_RESET_MASK); @@ -772,7 +772,7 @@ static void vx2_reset_codec(struct vx_core *_chip) */ static void vx2_change_audio_source(struct vx_core *_chip, int src) { - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip);
switch (src) { case VX_AUDIO_SRC_DIGITAL: @@ -791,7 +791,7 @@ static void vx2_change_audio_source(struct vx_core *_chip, int src) */ static void vx2_set_clock_source(struct vx_core *_chip, int source) { - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip);
if (source == INTERNAL_QUARTZ) chip->regCFG &= ~VX_CFG_CLOCKIN_SEL_MASK; @@ -805,7 +805,7 @@ static void vx2_set_clock_source(struct vx_core *_chip, int source) */ static void vx2_reset_board(struct vx_core *_chip, int cold_reset) { - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip);
/* initialize the register values */ chip->regCDSP = VX_CDSP_CODEC_RESET_MASK | VX_CDSP_DSP_RESET_MASK ; @@ -878,7 +878,7 @@ static int vx_input_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_ele static int vx_input_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip); mutex_lock(&_chip->mixer_mutex); ucontrol->value.integer.value[0] = chip->input_level[0]; ucontrol->value.integer.value[1] = chip->input_level[1]; @@ -889,7 +889,7 @@ static int vx_input_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem static int vx_input_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip); if (ucontrol->value.integer.value[0] < 0 || ucontrol->value.integer.value[0] > MIC_LEVEL_MAX) return -EINVAL; @@ -922,7 +922,7 @@ static int vx_mic_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip); ucontrol->value.integer.value[0] = chip->mic_level; return 0; } @@ -930,7 +930,7 @@ static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip); if (ucontrol->value.integer.value[0] < 0 || ucontrol->value.integer.value[0] > MIC_LEVEL_MAX) return -EINVAL; @@ -973,7 +973,7 @@ static const struct snd_kcontrol_new vx_control_mic_level = {
static int vx2_add_mic_controls(struct vx_core *_chip) { - struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + struct snd_vx222 *chip = to_vx222(_chip); int err;
if (_chip->type != VX_TYPE_MIC)
The vxpocket driver is using the explicit cast from the parent class pointer, but it'll be broken when the structure field randomization is applied. Use container_of() in a modern manner, instead.
Signed-off-by: Takashi Iwai tiwai@suse.de --- sound/pcmcia/vx/vxp_mixer.c | 10 +++++----- sound/pcmcia/vx/vxp_ops.c | 28 ++++++++++++++-------------- sound/pcmcia/vx/vxpocket.c | 4 ++-- sound/pcmcia/vx/vxpocket.h | 2 ++ 4 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/sound/pcmcia/vx/vxp_mixer.c b/sound/pcmcia/vx/vxp_mixer.c index a4a664259f0d..1ca3eef9e305 100644 --- a/sound/pcmcia/vx/vxp_mixer.c +++ b/sound/pcmcia/vx/vxp_mixer.c @@ -43,7 +43,7 @@ static int vx_mic_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip); ucontrol->value.integer.value[0] = chip->mic_level; return 0; } @@ -51,7 +51,7 @@ static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip); unsigned int val = ucontrol->value.integer.value[0];
if (val > MIC_LEVEL_MAX) @@ -88,7 +88,7 @@ static struct snd_kcontrol_new vx_control_mic_level = { static int vx_mic_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip); ucontrol->value.integer.value[0] = chip->mic_level; return 0; } @@ -96,7 +96,7 @@ static int vx_mic_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v static int vx_mic_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip); int val = !!ucontrol->value.integer.value[0]; mutex_lock(&_chip->mixer_mutex); if (chip->mic_level != val) { @@ -120,7 +120,7 @@ static struct snd_kcontrol_new vx_control_mic_boost = {
int vxp_add_mic_controls(struct vx_core *_chip) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip); int err;
/* mute input levels */ diff --git a/sound/pcmcia/vx/vxp_ops.c b/sound/pcmcia/vx/vxp_ops.c index 5f97791f00d7..217cc76e3102 100644 --- a/sound/pcmcia/vx/vxp_ops.c +++ b/sound/pcmcia/vx/vxp_ops.c @@ -50,7 +50,7 @@ static int vxp_reg_offset[VX_REG_MAX] = {
static inline unsigned long vxp_reg_addr(struct vx_core *_chip, int reg) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip); return chip->port + vxp_reg_offset[reg]; }
@@ -110,7 +110,7 @@ static int vx_check_magic(struct vx_core *chip)
static void vxp_reset_dsp(struct vx_core *_chip) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip);
/* set the reset dsp bit to 1 */ vx_outb(chip, CDSP, chip->regCDSP | VXP_CDSP_DSP_RESET_MASK); @@ -128,7 +128,7 @@ static void vxp_reset_dsp(struct vx_core *_chip) */ static void vxp_reset_codec(struct vx_core *_chip) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip);
/* Set the reset CODEC bit to 1. */ vx_outb(chip, CDSP, chip->regCDSP | VXP_CDSP_CODEC_RESET_MASK); @@ -147,7 +147,7 @@ static void vxp_reset_codec(struct vx_core *_chip) */ static int vxp_load_xilinx_binary(struct vx_core *_chip, const struct firmware *fw) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip); unsigned int i; int c; int regCSUER, regRUER; @@ -280,7 +280,7 @@ static int vxp_load_dsp(struct vx_core *vx, int index, const struct firmware *fw */ static int vxp_test_and_ack(struct vx_core *_chip) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip);
/* not booted yet? */ if (! (_chip->chip_status & VX_STAT_XILINX_LOADED)) @@ -307,7 +307,7 @@ static int vxp_test_and_ack(struct vx_core *_chip) */ static void vxp_validate_irq(struct vx_core *_chip, int enable) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip);
/* Set the interrupt enable bit to 1 in CDSP register */ if (enable) @@ -323,7 +323,7 @@ static void vxp_validate_irq(struct vx_core *_chip, int enable) */ static void vx_setup_pseudo_dma(struct vx_core *_chip, int do_write) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip);
/* Interrupt mode and HREQ pin enabled for host transmit / receive data transfers */ vx_outb(chip, ICR, do_write ? ICR_TREQ : ICR_RREQ); @@ -343,7 +343,7 @@ static void vx_setup_pseudo_dma(struct vx_core *_chip, int do_write) */ static void vx_release_pseudo_dma(struct vx_core *_chip) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip);
/* Disable DMA and 16-bit accesses */ chip->regDIALOG &= ~(VXP_DLG_DMAWRITE_SEL_MASK| @@ -403,7 +403,7 @@ static void vxp_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime, static void vxp_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime, struct vx_pipe *pipe, int count) { - struct snd_vxpocket *pchip = (struct snd_vxpocket *)chip; + struct snd_vxpocket *pchip = to_vxpocket(_chip); long port = vxp_reg_addr(chip, VX_DMA); int offset = pipe->hw_ptr; unsigned short *addr = (unsigned short *)(runtime->dma_area + offset); @@ -467,7 +467,7 @@ static void vxp_write_codec_reg(struct vx_core *chip, int codec, unsigned int da */ void vx_set_mic_boost(struct vx_core *chip, int boost) { - struct snd_vxpocket *pchip = (struct snd_vxpocket *)chip; + struct snd_vxpocket *pchip = to_vxpocket(_chip);
if (chip->chip_status & VX_STAT_IS_STALE) return; @@ -509,7 +509,7 @@ static int vx_compute_mic_level(int level) */ void vx_set_mic_level(struct vx_core *chip, int level) { - struct snd_vxpocket *pchip = (struct snd_vxpocket *)chip; + struct snd_vxpocket *pchip = to_vxpocket(_chip);
if (chip->chip_status & VX_STAT_IS_STALE) return; @@ -528,7 +528,7 @@ void vx_set_mic_level(struct vx_core *chip, int level) */ static void vxp_change_audio_source(struct vx_core *_chip, int src) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip);
switch (src) { case VX_AUDIO_SRC_DIGITAL: @@ -568,7 +568,7 @@ static void vxp_change_audio_source(struct vx_core *_chip, int src) */ static void vxp_set_clock_source(struct vx_core *_chip, int source) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip);
if (source == INTERNAL_QUARTZ) chip->regCDSP &= ~VXP_CDSP_CLOCKIN_SEL_MASK; @@ -583,7 +583,7 @@ static void vxp_set_clock_source(struct vx_core *_chip, int source) */ static void vxp_reset_board(struct vx_core *_chip, int cold_reset) { - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + struct snd_vxpocket *chip = to_vxpocket(_chip);
chip->regCDSP = 0; chip->regDIALOG = 0; diff --git a/sound/pcmcia/vx/vxpocket.c b/sound/pcmcia/vx/vxpocket.c index b16f42deed67..ca0d19e723fd 100644 --- a/sound/pcmcia/vx/vxpocket.c +++ b/sound/pcmcia/vx/vxpocket.c @@ -155,7 +155,7 @@ static int snd_vxpocket_new(struct snd_card *card, int ibl, } chip->ibl.size = ibl;
- vxp = (struct snd_vxpocket *)chip; + vxp = to_vxpocket(chip);
vxp->p_dev = link; link->priv = chip; @@ -187,7 +187,7 @@ static int snd_vxpocket_assign_resources(struct vx_core *chip, int port, int irq { int err; struct snd_card *card = chip->card; - struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip; + struct snd_vxpocket *vxp = to_vxpocket(chip);
snd_printdd(KERN_DEBUG "vxpocket assign resources: port = 0x%x, irq = %d\n", port, irq); vxp->port = port; diff --git a/sound/pcmcia/vx/vxpocket.h b/sound/pcmcia/vx/vxpocket.h index 13d658c1a216..26f4255e132e 100644 --- a/sound/pcmcia/vx/vxpocket.h +++ b/sound/pcmcia/vx/vxpocket.h @@ -43,6 +43,8 @@ struct snd_vxpocket { struct pcmcia_device *p_dev; };
+#define to_vxpocket(x) container_of(x, struct snd_vxpocket, core) + extern struct snd_vx_ops snd_vxpocket_ops;
void vx_set_mic_boost(struct vx_core *chip, int boost);
The ak4113, ak4114 and ak4117 i2c drivers have some tricky codes to access the struct fields in the callback. This can be simplified by replacing the struct fields with the array.
Signed-off-by: Takashi Iwai tiwai@suse.de --- include/sound/ak4113.h | 13 +++++++++---- include/sound/ak4114.h | 13 +++++++++---- include/sound/ak4117.h | 13 +++++++++---- sound/i2c/other/ak4113.c | 23 +++++++++++------------ sound/i2c/other/ak4114.c | 23 +++++++++++------------ sound/i2c/other/ak4117.c | 23 +++++++++++------------ 6 files changed, 60 insertions(+), 48 deletions(-)
diff --git a/include/sound/ak4113.h b/include/sound/ak4113.h index 58c145620c3c..b2d09fd09559 100644 --- a/include/sound/ak4113.h +++ b/include/sound/ak4113.h @@ -281,6 +281,14 @@ typedef void (ak4113_write_t)(void *private_data, unsigned char addr, unsigned char data); typedef unsigned char (ak4113_read_t)(void *private_data, unsigned char addr);
+enum { + AK4113_PARITY_ERRORS, + AK4113_V_BIT_ERRORS, + AK4113_QCRC_ERRORS, + AK4113_CCRC_ERRORS, + AK4113_NUM_ERRORS +}; + struct ak4113 { struct snd_card *card; ak4113_write_t *write; @@ -292,10 +300,7 @@ struct ak4113 { unsigned char regmap[AK4113_WRITABLE_REGS]; struct snd_kcontrol *kctls[AK4113_CONTROLS]; struct snd_pcm_substream *substream; - unsigned long parity_errors; - unsigned long v_bit_errors; - unsigned long qcrc_errors; - unsigned long ccrc_errors; + unsigned long errors[AK4113_NUM_ERRORS]; unsigned char rcs0; unsigned char rcs1; unsigned char rcs2; diff --git a/include/sound/ak4114.h b/include/sound/ak4114.h index b6feb7e225f2..39df064c82fc 100644 --- a/include/sound/ak4114.h +++ b/include/sound/ak4114.h @@ -163,6 +163,14 @@ typedef void (ak4114_write_t)(void *private_data, unsigned char addr, unsigned char data); typedef unsigned char (ak4114_read_t)(void *private_data, unsigned char addr);
+enum { + AK4114_PARITY_ERRORS, + AK4114_V_BIT_ERRORS, + AK4114_QCRC_ERRORS, + AK4114_CCRC_ERRORS, + AK4114_NUM_ERRORS +}; + struct ak4114 { struct snd_card *card; ak4114_write_t * write; @@ -176,10 +184,7 @@ struct ak4114 { struct snd_kcontrol *kctls[AK4114_CONTROLS]; struct snd_pcm_substream *playback_substream; struct snd_pcm_substream *capture_substream; - unsigned long parity_errors; - unsigned long v_bit_errors; - unsigned long qcrc_errors; - unsigned long ccrc_errors; + unsigned long errors[AK4114_NUM_ERRORS]; unsigned char rcs0; unsigned char rcs1; struct delayed_work work; diff --git a/include/sound/ak4117.h b/include/sound/ak4117.h index 1e8178171baf..5fab517cfe46 100644 --- a/include/sound/ak4117.h +++ b/include/sound/ak4117.h @@ -155,6 +155,14 @@ typedef void (ak4117_write_t)(void *private_data, unsigned char addr, unsigned char data); typedef unsigned char (ak4117_read_t)(void *private_data, unsigned char addr);
+enum { + AK4117_PARITY_ERRORS, + AK4117_V_BIT_ERRORS, + AK4117_QCRC_ERRORS, + AK4117_CCRC_ERRORS, + AK4117_NUM_ERRORS +}; + struct ak4117 { struct snd_card *card; ak4117_write_t * write; @@ -165,10 +173,7 @@ struct ak4117 { unsigned char regmap[5]; struct snd_kcontrol *kctls[AK4117_CONTROLS]; struct snd_pcm_substream *substream; - unsigned long parity_errors; - unsigned long v_bit_errors; - unsigned long qcrc_errors; - unsigned long ccrc_errors; + unsigned long errors[AK4117_NUM_ERRORS]; unsigned char rcs0; unsigned char rcs1; unsigned char rcs2; diff --git a/sound/i2c/other/ak4113.c b/sound/i2c/other/ak4113.c index 2183e9ebaa6d..4099e6062d3c 100644 --- a/sound/i2c/other/ak4113.c +++ b/sound/i2c/other/ak4113.c @@ -199,12 +199,11 @@ static int snd_ak4113_in_error_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct ak4113 *chip = snd_kcontrol_chip(kcontrol); - long *ptr;
spin_lock_irq(&chip->lock); - ptr = (long *)(((char *)chip) + kcontrol->private_value); - ucontrol->value.integer.value[0] = *ptr; - *ptr = 0; + ucontrol->value.integer.value[0] = + chip->errors[kcontrol->private_value]; + chip->errors[kcontrol->private_value] = 0; spin_unlock_irq(&chip->lock); return 0; } @@ -373,7 +372,7 @@ static struct snd_kcontrol_new snd_ak4113_iec958_controls[] = { SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4113_in_error_info, .get = snd_ak4113_in_error_get, - .private_value = offsetof(struct ak4113, parity_errors), + .private_value = AK4113_PARITY_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -382,7 +381,7 @@ static struct snd_kcontrol_new snd_ak4113_iec958_controls[] = { SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4113_in_error_info, .get = snd_ak4113_in_error_get, - .private_value = offsetof(struct ak4113, v_bit_errors), + .private_value = AK4113_V_BIT_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -391,7 +390,7 @@ static struct snd_kcontrol_new snd_ak4113_iec958_controls[] = { SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4113_in_error_info, .get = snd_ak4113_in_error_get, - .private_value = offsetof(struct ak4113, ccrc_errors), + .private_value = AK4113_CCRC_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -400,7 +399,7 @@ static struct snd_kcontrol_new snd_ak4113_iec958_controls[] = { SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4113_in_error_info, .get = snd_ak4113_in_error_get, - .private_value = offsetof(struct ak4113, qcrc_errors), + .private_value = AK4113_QCRC_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -551,13 +550,13 @@ int snd_ak4113_check_rate_and_errors(struct ak4113 *ak4113, unsigned int flags) rcs2 = reg_read(ak4113, AK4113_REG_RCS2); spin_lock_irqsave(&ak4113->lock, _flags); if (rcs0 & AK4113_PAR) - ak4113->parity_errors++; + ak4113->errors[AK4113_PARITY_ERRORS]++; if (rcs0 & AK4113_V) - ak4113->v_bit_errors++; + ak4113->errors[AK4113_V_BIT_ERRORS]++; if (rcs2 & AK4113_CCRC) - ak4113->ccrc_errors++; + ak4113->errors[AK4113_CCRC_ERRORS]++; if (rcs2 & AK4113_QCRC) - ak4113->qcrc_errors++; + ak4113->errors[AK4113_QCRC_ERRORS]++; c0 = (ak4113->rcs0 & (AK4113_QINT | AK4113_CINT | AK4113_STC | AK4113_AUDION | AK4113_AUTO | AK4113_UNLCK)) ^ (rcs0 & (AK4113_QINT | AK4113_CINT | AK4113_STC | diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c index d53c9bb36281..7fb1aeb46915 100644 --- a/sound/i2c/other/ak4114.c +++ b/sound/i2c/other/ak4114.c @@ -194,12 +194,11 @@ static int snd_ak4114_in_error_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct ak4114 *chip = snd_kcontrol_chip(kcontrol); - long *ptr;
spin_lock_irq(&chip->lock); - ptr = (long *)(((char *)chip) + kcontrol->private_value); - ucontrol->value.integer.value[0] = *ptr; - *ptr = 0; + ucontrol->value.integer.value[0] = + chip->errors[kcontrol->private_value]; + chip->errors[kcontrol->private_value] = 0; spin_unlock_irq(&chip->lock); return 0; } @@ -341,7 +340,7 @@ static struct snd_kcontrol_new snd_ak4114_iec958_controls[] = { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4114_in_error_info, .get = snd_ak4114_in_error_get, - .private_value = offsetof(struct ak4114, parity_errors), + .private_value = AK4114_PARITY_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -349,7 +348,7 @@ static struct snd_kcontrol_new snd_ak4114_iec958_controls[] = { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4114_in_error_info, .get = snd_ak4114_in_error_get, - .private_value = offsetof(struct ak4114, v_bit_errors), + .private_value = AK4114_V_BIT_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -357,7 +356,7 @@ static struct snd_kcontrol_new snd_ak4114_iec958_controls[] = { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4114_in_error_info, .get = snd_ak4114_in_error_get, - .private_value = offsetof(struct ak4114, ccrc_errors), + .private_value = AK4114_CCRC_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -365,7 +364,7 @@ static struct snd_kcontrol_new snd_ak4114_iec958_controls[] = { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4114_in_error_info, .get = snd_ak4114_in_error_get, - .private_value = offsetof(struct ak4114, qcrc_errors), + .private_value = AK4114_QCRC_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -581,13 +580,13 @@ int snd_ak4114_check_rate_and_errors(struct ak4114 *ak4114, unsigned int flags) rcs0 = reg_read(ak4114, AK4114_REG_RCS0); spin_lock_irqsave(&ak4114->lock, _flags); if (rcs0 & AK4114_PAR) - ak4114->parity_errors++; + ak4114->errors[AK4114_PARITY_ERRORS]++; if (rcs1 & AK4114_V) - ak4114->v_bit_errors++; + ak4114->errors[AK4114_V_BIT_ERRORS]++; if (rcs1 & AK4114_CCRC) - ak4114->ccrc_errors++; + ak4114->errors[AK4114_CCRC_ERRORS]++; if (rcs1 & AK4114_QCRC) - ak4114->qcrc_errors++; + ak4114->errors[AK4114_QCRC_ERRORS]++; c0 = (ak4114->rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK)) ^ (rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK)); c1 = (ak4114->rcs1 & 0xf0) ^ (rcs1 & 0xf0); diff --git a/sound/i2c/other/ak4117.c b/sound/i2c/other/ak4117.c index 0702f0552d19..3ab099fb8c15 100644 --- a/sound/i2c/other/ak4117.c +++ b/sound/i2c/other/ak4117.c @@ -168,12 +168,11 @@ static int snd_ak4117_in_error_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct ak4117 *chip = snd_kcontrol_chip(kcontrol); - long *ptr;
spin_lock_irq(&chip->lock); - ptr = (long *)(((char *)chip) + kcontrol->private_value); - ucontrol->value.integer.value[0] = *ptr; - *ptr = 0; + ucontrol->value.integer.value[0] = + chip->errors[kcontrol->private_value]; + chip->errors[kcontrol->private_value] = 0; spin_unlock_irq(&chip->lock); return 0; } @@ -328,7 +327,7 @@ static struct snd_kcontrol_new snd_ak4117_iec958_controls[] = { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4117_in_error_info, .get = snd_ak4117_in_error_get, - .private_value = offsetof(struct ak4117, parity_errors), + .private_value = AK4117_PARITY_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -336,7 +335,7 @@ static struct snd_kcontrol_new snd_ak4117_iec958_controls[] = { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4117_in_error_info, .get = snd_ak4117_in_error_get, - .private_value = offsetof(struct ak4117, v_bit_errors), + .private_value = AK4117_V_BIT_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -344,7 +343,7 @@ static struct snd_kcontrol_new snd_ak4117_iec958_controls[] = { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4117_in_error_info, .get = snd_ak4117_in_error_get, - .private_value = offsetof(struct ak4117, ccrc_errors), + .private_value = AK4117_CCRC_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -352,7 +351,7 @@ static struct snd_kcontrol_new snd_ak4117_iec958_controls[] = { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = snd_ak4117_in_error_info, .get = snd_ak4117_in_error_get, - .private_value = offsetof(struct ak4117, qcrc_errors), + .private_value = AK4117_QCRC_ERRORS, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -470,13 +469,13 @@ int snd_ak4117_check_rate_and_errors(struct ak4117 *ak4117, unsigned int flags) // printk(KERN_DEBUG "AK IRQ: rcs0 = 0x%x, rcs1 = 0x%x, rcs2 = 0x%x\n", rcs0, rcs1, rcs2); spin_lock_irqsave(&ak4117->lock, _flags); if (rcs0 & AK4117_PAR) - ak4117->parity_errors++; + ak4117->errors[AK4117_PARITY_ERRORS]++; if (rcs0 & AK4117_V) - ak4117->v_bit_errors++; + ak4117->errors[AK4117_V_BIT_ERRORS]++; if (rcs2 & AK4117_CCRC) - ak4117->ccrc_errors++; + ak4117->errors[AK4117_CCRC_ERRORS]++; if (rcs2 & AK4117_QCRC) - ak4117->qcrc_errors++; + ak4117->errors[AK4117_QCRC_ERRORS]++; c0 = (ak4117->rcs0 & (AK4117_QINT | AK4117_CINT | AK4117_STC | AK4117_AUDION | AK4117_AUTO | AK4117_UNLCK)) ^ (rcs0 & (AK4117_QINT | AK4117_CINT | AK4117_STC | AK4117_AUDION | AK4117_AUTO | AK4117_UNLCK)); c1 = (ak4117->rcs1 & (AK4117_DTSCD | AK4117_NPCM | AK4117_PEM | 0x0f)) ^
participants (1)
-
Takashi Iwai