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

ALSA: ak411x: Use array instead of offsetof()

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>

+60 -48
+9 -4
include/sound/ak4113.h
··· 281 281 unsigned char data); 282 282 typedef unsigned char (ak4113_read_t)(void *private_data, unsigned char addr); 283 283 284 + enum { 285 + AK4113_PARITY_ERRORS, 286 + AK4113_V_BIT_ERRORS, 287 + AK4113_QCRC_ERRORS, 288 + AK4113_CCRC_ERRORS, 289 + AK4113_NUM_ERRORS 290 + }; 291 + 284 292 struct ak4113 { 285 293 struct snd_card *card; 286 294 ak4113_write_t *write; ··· 300 292 unsigned char regmap[AK4113_WRITABLE_REGS]; 301 293 struct snd_kcontrol *kctls[AK4113_CONTROLS]; 302 294 struct snd_pcm_substream *substream; 303 - unsigned long parity_errors; 304 - unsigned long v_bit_errors; 305 - unsigned long qcrc_errors; 306 - unsigned long ccrc_errors; 295 + unsigned long errors[AK4113_NUM_ERRORS]; 307 296 unsigned char rcs0; 308 297 unsigned char rcs1; 309 298 unsigned char rcs2;
+9 -4
include/sound/ak4114.h
··· 163 163 typedef void (ak4114_write_t)(void *private_data, unsigned char addr, unsigned char data); 164 164 typedef unsigned char (ak4114_read_t)(void *private_data, unsigned char addr); 165 165 166 + enum { 167 + AK4114_PARITY_ERRORS, 168 + AK4114_V_BIT_ERRORS, 169 + AK4114_QCRC_ERRORS, 170 + AK4114_CCRC_ERRORS, 171 + AK4114_NUM_ERRORS 172 + }; 173 + 166 174 struct ak4114 { 167 175 struct snd_card *card; 168 176 ak4114_write_t * write; ··· 184 176 struct snd_kcontrol *kctls[AK4114_CONTROLS]; 185 177 struct snd_pcm_substream *playback_substream; 186 178 struct snd_pcm_substream *capture_substream; 187 - unsigned long parity_errors; 188 - unsigned long v_bit_errors; 189 - unsigned long qcrc_errors; 190 - unsigned long ccrc_errors; 179 + unsigned long errors[AK4114_NUM_ERRORS]; 191 180 unsigned char rcs0; 192 181 unsigned char rcs1; 193 182 struct delayed_work work;
+9 -4
include/sound/ak4117.h
··· 155 155 typedef void (ak4117_write_t)(void *private_data, unsigned char addr, unsigned char data); 156 156 typedef unsigned char (ak4117_read_t)(void *private_data, unsigned char addr); 157 157 158 + enum { 159 + AK4117_PARITY_ERRORS, 160 + AK4117_V_BIT_ERRORS, 161 + AK4117_QCRC_ERRORS, 162 + AK4117_CCRC_ERRORS, 163 + AK4117_NUM_ERRORS 164 + }; 165 + 158 166 struct ak4117 { 159 167 struct snd_card *card; 160 168 ak4117_write_t * write; ··· 173 165 unsigned char regmap[5]; 174 166 struct snd_kcontrol *kctls[AK4117_CONTROLS]; 175 167 struct snd_pcm_substream *substream; 176 - unsigned long parity_errors; 177 - unsigned long v_bit_errors; 178 - unsigned long qcrc_errors; 179 - unsigned long ccrc_errors; 168 + unsigned long errors[AK4117_NUM_ERRORS]; 180 169 unsigned char rcs0; 181 170 unsigned char rcs1; 182 171 unsigned char rcs2;
+11 -12
sound/i2c/other/ak4113.c
··· 199 199 struct snd_ctl_elem_value *ucontrol) 200 200 { 201 201 struct ak4113 *chip = snd_kcontrol_chip(kcontrol); 202 - long *ptr; 203 202 204 203 spin_lock_irq(&chip->lock); 205 - ptr = (long *)(((char *)chip) + kcontrol->private_value); 206 - ucontrol->value.integer.value[0] = *ptr; 207 - *ptr = 0; 204 + ucontrol->value.integer.value[0] = 205 + chip->errors[kcontrol->private_value]; 206 + chip->errors[kcontrol->private_value] = 0; 208 207 spin_unlock_irq(&chip->lock); 209 208 return 0; 210 209 } ··· 372 373 SNDRV_CTL_ELEM_ACCESS_VOLATILE, 373 374 .info = snd_ak4113_in_error_info, 374 375 .get = snd_ak4113_in_error_get, 375 - .private_value = offsetof(struct ak4113, parity_errors), 376 + .private_value = AK4113_PARITY_ERRORS, 376 377 }, 377 378 { 378 379 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 381 382 SNDRV_CTL_ELEM_ACCESS_VOLATILE, 382 383 .info = snd_ak4113_in_error_info, 383 384 .get = snd_ak4113_in_error_get, 384 - .private_value = offsetof(struct ak4113, v_bit_errors), 385 + .private_value = AK4113_V_BIT_ERRORS, 385 386 }, 386 387 { 387 388 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 390 391 SNDRV_CTL_ELEM_ACCESS_VOLATILE, 391 392 .info = snd_ak4113_in_error_info, 392 393 .get = snd_ak4113_in_error_get, 393 - .private_value = offsetof(struct ak4113, ccrc_errors), 394 + .private_value = AK4113_CCRC_ERRORS, 394 395 }, 395 396 { 396 397 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 399 400 SNDRV_CTL_ELEM_ACCESS_VOLATILE, 400 401 .info = snd_ak4113_in_error_info, 401 402 .get = snd_ak4113_in_error_get, 402 - .private_value = offsetof(struct ak4113, qcrc_errors), 403 + .private_value = AK4113_QCRC_ERRORS, 403 404 }, 404 405 { 405 406 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 550 551 rcs2 = reg_read(ak4113, AK4113_REG_RCS2); 551 552 spin_lock_irqsave(&ak4113->lock, _flags); 552 553 if (rcs0 & AK4113_PAR) 553 - ak4113->parity_errors++; 554 + ak4113->errors[AK4113_PARITY_ERRORS]++; 554 555 if (rcs0 & AK4113_V) 555 - ak4113->v_bit_errors++; 556 + ak4113->errors[AK4113_V_BIT_ERRORS]++; 556 557 if (rcs2 & AK4113_CCRC) 557 - ak4113->ccrc_errors++; 558 + ak4113->errors[AK4113_CCRC_ERRORS]++; 558 559 if (rcs2 & AK4113_QCRC) 559 - ak4113->qcrc_errors++; 560 + ak4113->errors[AK4113_QCRC_ERRORS]++; 560 561 c0 = (ak4113->rcs0 & (AK4113_QINT | AK4113_CINT | AK4113_STC | 561 562 AK4113_AUDION | AK4113_AUTO | AK4113_UNLCK)) ^ 562 563 (rcs0 & (AK4113_QINT | AK4113_CINT | AK4113_STC |
+11 -12
sound/i2c/other/ak4114.c
··· 194 194 struct snd_ctl_elem_value *ucontrol) 195 195 { 196 196 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); 197 - long *ptr; 198 197 199 198 spin_lock_irq(&chip->lock); 200 - ptr = (long *)(((char *)chip) + kcontrol->private_value); 201 - ucontrol->value.integer.value[0] = *ptr; 202 - *ptr = 0; 199 + ucontrol->value.integer.value[0] = 200 + chip->errors[kcontrol->private_value]; 201 + chip->errors[kcontrol->private_value] = 0; 203 202 spin_unlock_irq(&chip->lock); 204 203 return 0; 205 204 } ··· 340 341 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 341 342 .info = snd_ak4114_in_error_info, 342 343 .get = snd_ak4114_in_error_get, 343 - .private_value = offsetof(struct ak4114, parity_errors), 344 + .private_value = AK4114_PARITY_ERRORS, 344 345 }, 345 346 { 346 347 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 348 349 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 349 350 .info = snd_ak4114_in_error_info, 350 351 .get = snd_ak4114_in_error_get, 351 - .private_value = offsetof(struct ak4114, v_bit_errors), 352 + .private_value = AK4114_V_BIT_ERRORS, 352 353 }, 353 354 { 354 355 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 356 357 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 357 358 .info = snd_ak4114_in_error_info, 358 359 .get = snd_ak4114_in_error_get, 359 - .private_value = offsetof(struct ak4114, ccrc_errors), 360 + .private_value = AK4114_CCRC_ERRORS, 360 361 }, 361 362 { 362 363 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 364 365 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 365 366 .info = snd_ak4114_in_error_info, 366 367 .get = snd_ak4114_in_error_get, 367 - .private_value = offsetof(struct ak4114, qcrc_errors), 368 + .private_value = AK4114_QCRC_ERRORS, 368 369 }, 369 370 { 370 371 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 580 581 rcs0 = reg_read(ak4114, AK4114_REG_RCS0); 581 582 spin_lock_irqsave(&ak4114->lock, _flags); 582 583 if (rcs0 & AK4114_PAR) 583 - ak4114->parity_errors++; 584 + ak4114->errors[AK4114_PARITY_ERRORS]++; 584 585 if (rcs1 & AK4114_V) 585 - ak4114->v_bit_errors++; 586 + ak4114->errors[AK4114_V_BIT_ERRORS]++; 586 587 if (rcs1 & AK4114_CCRC) 587 - ak4114->ccrc_errors++; 588 + ak4114->errors[AK4114_CCRC_ERRORS]++; 588 589 if (rcs1 & AK4114_QCRC) 589 - ak4114->qcrc_errors++; 590 + ak4114->errors[AK4114_QCRC_ERRORS]++; 590 591 c0 = (ak4114->rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK)) ^ 591 592 (rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK)); 592 593 c1 = (ak4114->rcs1 & 0xf0) ^ (rcs1 & 0xf0);
+11 -12
sound/i2c/other/ak4117.c
··· 168 168 struct snd_ctl_elem_value *ucontrol) 169 169 { 170 170 struct ak4117 *chip = snd_kcontrol_chip(kcontrol); 171 - long *ptr; 172 171 173 172 spin_lock_irq(&chip->lock); 174 - ptr = (long *)(((char *)chip) + kcontrol->private_value); 175 - ucontrol->value.integer.value[0] = *ptr; 176 - *ptr = 0; 173 + ucontrol->value.integer.value[0] = 174 + chip->errors[kcontrol->private_value]; 175 + chip->errors[kcontrol->private_value] = 0; 177 176 spin_unlock_irq(&chip->lock); 178 177 return 0; 179 178 } ··· 327 328 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 328 329 .info = snd_ak4117_in_error_info, 329 330 .get = snd_ak4117_in_error_get, 330 - .private_value = offsetof(struct ak4117, parity_errors), 331 + .private_value = AK4117_PARITY_ERRORS, 331 332 }, 332 333 { 333 334 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 335 336 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 336 337 .info = snd_ak4117_in_error_info, 337 338 .get = snd_ak4117_in_error_get, 338 - .private_value = offsetof(struct ak4117, v_bit_errors), 339 + .private_value = AK4117_V_BIT_ERRORS, 339 340 }, 340 341 { 341 342 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 343 344 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 344 345 .info = snd_ak4117_in_error_info, 345 346 .get = snd_ak4117_in_error_get, 346 - .private_value = offsetof(struct ak4117, ccrc_errors), 347 + .private_value = AK4117_CCRC_ERRORS, 347 348 }, 348 349 { 349 350 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 351 352 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 352 353 .info = snd_ak4117_in_error_info, 353 354 .get = snd_ak4117_in_error_get, 354 - .private_value = offsetof(struct ak4117, qcrc_errors), 355 + .private_value = AK4117_QCRC_ERRORS, 355 356 }, 356 357 { 357 358 .iface = SNDRV_CTL_ELEM_IFACE_PCM, ··· 469 470 // printk(KERN_DEBUG "AK IRQ: rcs0 = 0x%x, rcs1 = 0x%x, rcs2 = 0x%x\n", rcs0, rcs1, rcs2); 470 471 spin_lock_irqsave(&ak4117->lock, _flags); 471 472 if (rcs0 & AK4117_PAR) 472 - ak4117->parity_errors++; 473 + ak4117->errors[AK4117_PARITY_ERRORS]++; 473 474 if (rcs0 & AK4117_V) 474 - ak4117->v_bit_errors++; 475 + ak4117->errors[AK4117_V_BIT_ERRORS]++; 475 476 if (rcs2 & AK4117_CCRC) 476 - ak4117->ccrc_errors++; 477 + ak4117->errors[AK4117_CCRC_ERRORS]++; 477 478 if (rcs2 & AK4117_QCRC) 478 - ak4117->qcrc_errors++; 479 + ak4117->errors[AK4117_QCRC_ERRORS]++; 479 480 c0 = (ak4117->rcs0 & (AK4117_QINT | AK4117_CINT | AK4117_STC | AK4117_AUDION | AK4117_AUTO | AK4117_UNLCK)) ^ 480 481 (rcs0 & (AK4117_QINT | AK4117_CINT | AK4117_STC | AK4117_AUDION | AK4117_AUTO | AK4117_UNLCK)); 481 482 c1 = (ak4117->rcs1 & (AK4117_DTSCD | AK4117_NPCM | AK4117_PEM | 0x0f)) ^