Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: vxpocket: Use container_of()

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>

+23 -21
+5 -5
sound/pcmcia/vx/vxp_mixer.c
··· 43 43 static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 44 44 { 45 45 struct vx_core *_chip = snd_kcontrol_chip(kcontrol); 46 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 46 + struct snd_vxpocket *chip = to_vxpocket(_chip); 47 47 ucontrol->value.integer.value[0] = chip->mic_level; 48 48 return 0; 49 49 } ··· 51 51 static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 52 52 { 53 53 struct vx_core *_chip = snd_kcontrol_chip(kcontrol); 54 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 54 + struct snd_vxpocket *chip = to_vxpocket(_chip); 55 55 unsigned int val = ucontrol->value.integer.value[0]; 56 56 57 57 if (val > MIC_LEVEL_MAX) ··· 88 88 static int vx_mic_boost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 89 89 { 90 90 struct vx_core *_chip = snd_kcontrol_chip(kcontrol); 91 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 91 + struct snd_vxpocket *chip = to_vxpocket(_chip); 92 92 ucontrol->value.integer.value[0] = chip->mic_level; 93 93 return 0; 94 94 } ··· 96 96 static int vx_mic_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 97 97 { 98 98 struct vx_core *_chip = snd_kcontrol_chip(kcontrol); 99 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 99 + struct snd_vxpocket *chip = to_vxpocket(_chip); 100 100 int val = !!ucontrol->value.integer.value[0]; 101 101 mutex_lock(&_chip->mixer_mutex); 102 102 if (chip->mic_level != val) { ··· 120 120 121 121 int vxp_add_mic_controls(struct vx_core *_chip) 122 122 { 123 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 123 + struct snd_vxpocket *chip = to_vxpocket(_chip); 124 124 int err; 125 125 126 126 /* mute input levels */
+14 -14
sound/pcmcia/vx/vxp_ops.c
··· 50 50 51 51 static inline unsigned long vxp_reg_addr(struct vx_core *_chip, int reg) 52 52 { 53 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 53 + struct snd_vxpocket *chip = to_vxpocket(_chip); 54 54 return chip->port + vxp_reg_offset[reg]; 55 55 } 56 56 ··· 110 110 111 111 static void vxp_reset_dsp(struct vx_core *_chip) 112 112 { 113 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 113 + struct snd_vxpocket *chip = to_vxpocket(_chip); 114 114 115 115 /* set the reset dsp bit to 1 */ 116 116 vx_outb(chip, CDSP, chip->regCDSP | VXP_CDSP_DSP_RESET_MASK); ··· 128 128 */ 129 129 static void vxp_reset_codec(struct vx_core *_chip) 130 130 { 131 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 131 + struct snd_vxpocket *chip = to_vxpocket(_chip); 132 132 133 133 /* Set the reset CODEC bit to 1. */ 134 134 vx_outb(chip, CDSP, chip->regCDSP | VXP_CDSP_CODEC_RESET_MASK); ··· 147 147 */ 148 148 static int vxp_load_xilinx_binary(struct vx_core *_chip, const struct firmware *fw) 149 149 { 150 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 150 + struct snd_vxpocket *chip = to_vxpocket(_chip); 151 151 unsigned int i; 152 152 int c; 153 153 int regCSUER, regRUER; ··· 280 280 */ 281 281 static int vxp_test_and_ack(struct vx_core *_chip) 282 282 { 283 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 283 + struct snd_vxpocket *chip = to_vxpocket(_chip); 284 284 285 285 /* not booted yet? */ 286 286 if (! (_chip->chip_status & VX_STAT_XILINX_LOADED)) ··· 307 307 */ 308 308 static void vxp_validate_irq(struct vx_core *_chip, int enable) 309 309 { 310 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 310 + struct snd_vxpocket *chip = to_vxpocket(_chip); 311 311 312 312 /* Set the interrupt enable bit to 1 in CDSP register */ 313 313 if (enable) ··· 323 323 */ 324 324 static void vx_setup_pseudo_dma(struct vx_core *_chip, int do_write) 325 325 { 326 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 326 + struct snd_vxpocket *chip = to_vxpocket(_chip); 327 327 328 328 /* Interrupt mode and HREQ pin enabled for host transmit / receive data transfers */ 329 329 vx_outb(chip, ICR, do_write ? ICR_TREQ : ICR_RREQ); ··· 343 343 */ 344 344 static void vx_release_pseudo_dma(struct vx_core *_chip) 345 345 { 346 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 346 + struct snd_vxpocket *chip = to_vxpocket(_chip); 347 347 348 348 /* Disable DMA and 16-bit accesses */ 349 349 chip->regDIALOG &= ~(VXP_DLG_DMAWRITE_SEL_MASK| ··· 403 403 static void vxp_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime, 404 404 struct vx_pipe *pipe, int count) 405 405 { 406 - struct snd_vxpocket *pchip = (struct snd_vxpocket *)chip; 406 + struct snd_vxpocket *pchip = to_vxpocket(chip); 407 407 long port = vxp_reg_addr(chip, VX_DMA); 408 408 int offset = pipe->hw_ptr; 409 409 unsigned short *addr = (unsigned short *)(runtime->dma_area + offset); ··· 467 467 */ 468 468 void vx_set_mic_boost(struct vx_core *chip, int boost) 469 469 { 470 - struct snd_vxpocket *pchip = (struct snd_vxpocket *)chip; 470 + struct snd_vxpocket *pchip = to_vxpocket(chip); 471 471 472 472 if (chip->chip_status & VX_STAT_IS_STALE) 473 473 return; ··· 509 509 */ 510 510 void vx_set_mic_level(struct vx_core *chip, int level) 511 511 { 512 - struct snd_vxpocket *pchip = (struct snd_vxpocket *)chip; 512 + struct snd_vxpocket *pchip = to_vxpocket(chip); 513 513 514 514 if (chip->chip_status & VX_STAT_IS_STALE) 515 515 return; ··· 528 528 */ 529 529 static void vxp_change_audio_source(struct vx_core *_chip, int src) 530 530 { 531 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 531 + struct snd_vxpocket *chip = to_vxpocket(_chip); 532 532 533 533 switch (src) { 534 534 case VX_AUDIO_SRC_DIGITAL: ··· 568 568 */ 569 569 static void vxp_set_clock_source(struct vx_core *_chip, int source) 570 570 { 571 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 571 + struct snd_vxpocket *chip = to_vxpocket(_chip); 572 572 573 573 if (source == INTERNAL_QUARTZ) 574 574 chip->regCDSP &= ~VXP_CDSP_CLOCKIN_SEL_MASK; ··· 583 583 */ 584 584 static void vxp_reset_board(struct vx_core *_chip, int cold_reset) 585 585 { 586 - struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; 586 + struct snd_vxpocket *chip = to_vxpocket(_chip); 587 587 588 588 chip->regCDSP = 0; 589 589 chip->regDIALOG = 0;
+2 -2
sound/pcmcia/vx/vxpocket.c
··· 155 155 } 156 156 chip->ibl.size = ibl; 157 157 158 - vxp = (struct snd_vxpocket *)chip; 158 + vxp = to_vxpocket(chip); 159 159 160 160 vxp->p_dev = link; 161 161 link->priv = chip; ··· 187 187 { 188 188 int err; 189 189 struct snd_card *card = chip->card; 190 - struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip; 190 + struct snd_vxpocket *vxp = to_vxpocket(chip); 191 191 192 192 snd_printdd(KERN_DEBUG "vxpocket assign resources: port = 0x%x, irq = %d\n", port, irq); 193 193 vxp->port = port;
+2
sound/pcmcia/vx/vxpocket.h
··· 43 43 struct pcmcia_device *p_dev; 44 44 }; 45 45 46 + #define to_vxpocket(x) container_of(x, struct snd_vxpocket, core) 47 + 46 48 extern struct snd_vx_ops snd_vxpocket_ops; 47 49 48 50 void vx_set_mic_boost(struct vx_core *chip, int boost);