Skip to content

Commit

Permalink
ALSA: vxpocket: Use container_of()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tiwai committed May 17, 2017
1 parent 5f976f5 commit 2e0de6e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
10 changes: 5 additions & 5 deletions sound/pcmcia/vx/vxp_mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ 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;
}

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)
Expand Down Expand Up @@ -88,15 +88,15 @@ 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;
}

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) {
Expand All @@ -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 */
Expand Down
28 changes: 14 additions & 14 deletions sound/pcmcia/vx/vxp_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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|
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions sound/pcmcia/vx/vxpocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions sound/pcmcia/vx/vxpocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2e0de6e

Please sign in to comment.