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

ALSA: es1688: allocate snd_es1688 structure as a part of snd_card structure

Allocate the snd_es1688 during the snd_card allocation.
This allows to remove the card pointer from the snd_es1688 structure.

Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Krzysztof Helt and committed by
Takashi Iwai
396fa827 02a2ad40

+46 -57
+5 -5
include/sound/es1688.h
··· 44 44 unsigned char pad; 45 45 unsigned int dma_size; 46 46 47 - struct snd_card *card; 48 47 struct snd_pcm *pcm; 49 48 struct snd_pcm_substream *playback_substream; 50 49 struct snd_pcm_substream *capture_substream; ··· 107 108 void snd_es1688_mixer_write(struct snd_es1688 *chip, unsigned char reg, unsigned char data); 108 109 109 110 int snd_es1688_create(struct snd_card *card, 111 + struct snd_es1688 *chip, 110 112 unsigned long port, 111 113 unsigned long mpu_port, 112 114 int irq, 113 115 int mpu_irq, 114 116 int dma8, 115 - unsigned short hardware, 116 - struct snd_es1688 ** rchip); 117 - int snd_es1688_pcm(struct snd_es1688 *chip, int device, struct snd_pcm ** rpcm); 118 - int snd_es1688_mixer(struct snd_es1688 *chip); 117 + unsigned short hardware); 118 + int snd_es1688_pcm(struct snd_card *card, struct snd_es1688 *chip, int device, 119 + struct snd_pcm **rpcm); 120 + int snd_es1688_mixer(struct snd_card *card, struct snd_es1688 *chip); 119 121 120 122 #endif /* __SOUND_ES1688_H */
+13 -10
sound/isa/es1688/es1688.c
··· 79 79 return enable[n]; 80 80 } 81 81 82 - static int __devinit snd_es1688_legacy_create(struct snd_card *card, 83 - struct device *dev, unsigned int n, struct snd_es1688 **rchip) 82 + static int __devinit snd_es1688_legacy_create(struct snd_card *card, 83 + struct snd_es1688 *chip, struct device *dev, unsigned int n) 84 84 { 85 85 static long possible_ports[] = {0x220, 0x240, 0x260}; 86 86 static int possible_irqs[] = {5, 9, 10, 7, -1}; ··· 104 104 } 105 105 106 106 if (port[n] != SNDRV_AUTO_PORT) 107 - return snd_es1688_create(card, port[n], mpu_port[n], irq[n], 108 - mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip); 107 + return snd_es1688_create(card, chip, port[n], mpu_port[n], 108 + irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO); 109 109 110 110 i = 0; 111 111 do { 112 112 port[n] = possible_ports[i]; 113 - error = snd_es1688_create(card, port[n], mpu_port[n], irq[n], 114 - mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip); 113 + error = snd_es1688_create(card, chip, port[n], mpu_port[n], 114 + irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO); 115 115 } while (error < 0 && ++i < ARRAY_SIZE(possible_ports)); 116 116 117 117 return error; ··· 125 125 struct snd_pcm *pcm; 126 126 int error; 127 127 128 - error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card); 128 + error = snd_card_create(index[n], id[n], THIS_MODULE, 129 + sizeof(struct snd_es1688), &card); 129 130 if (error < 0) 130 131 return error; 131 132 132 - error = snd_es1688_legacy_create(card, dev, n, &chip); 133 + chip = card->private_data; 134 + 135 + error = snd_es1688_legacy_create(card, chip, dev, n); 133 136 if (error < 0) 134 137 goto out; 135 138 136 - error = snd_es1688_pcm(chip, 0, &pcm); 139 + error = snd_es1688_pcm(card, chip, 0, &pcm); 137 140 if (error < 0) 138 141 goto out; 139 142 140 - error = snd_es1688_mixer(chip); 143 + error = snd_es1688_mixer(card, chip); 141 144 if (error < 0) 142 145 goto out; 143 146
+14 -30
sound/isa/es1688/es1688_lib.c
··· 620 620 disable_dma(chip->dma8); 621 621 free_dma(chip->dma8); 622 622 } 623 - kfree(chip); 624 623 return 0; 625 624 } 626 625 ··· 637 638 } 638 639 639 640 int snd_es1688_create(struct snd_card *card, 641 + struct snd_es1688 *chip, 640 642 unsigned long port, 641 643 unsigned long mpu_port, 642 644 int irq, 643 645 int mpu_irq, 644 646 int dma8, 645 - unsigned short hardware, 646 - struct snd_es1688 **rchip) 647 + unsigned short hardware) 647 648 { 648 649 static struct snd_device_ops ops = { 649 650 .dev_free = snd_es1688_dev_free, 650 651 }; 651 652 652 - struct snd_es1688 *chip; 653 653 int err; 654 654 655 - *rchip = NULL; 656 - chip = kzalloc(sizeof(*chip), GFP_KERNEL); 657 655 if (chip == NULL) 658 656 return -ENOMEM; 659 657 chip->irq = -1; ··· 658 662 659 663 if ((chip->res_port = request_region(port + 4, 12, "ES1688")) == NULL) { 660 664 snd_printk(KERN_ERR "es1688: can't grab port 0x%lx\n", port + 4); 661 - snd_es1688_free(chip); 662 665 return -EBUSY; 663 666 } 664 667 if (request_irq(irq, snd_es1688_interrupt, IRQF_DISABLED, "ES1688", (void *) chip)) { 665 668 snd_printk(KERN_ERR "es1688: can't grab IRQ %d\n", irq); 666 - snd_es1688_free(chip); 667 669 return -EBUSY; 668 670 } 669 671 chip->irq = irq; 670 672 if (request_dma(dma8, "ES1688")) { 671 673 snd_printk(KERN_ERR "es1688: can't grab DMA8 %d\n", dma8); 672 - snd_es1688_free(chip); 673 674 return -EBUSY; 674 675 } 675 676 chip->dma8 = dma8; 676 677 677 678 spin_lock_init(&chip->reg_lock); 678 679 spin_lock_init(&chip->mixer_lock); 679 - chip->card = card; 680 680 chip->port = port; 681 681 mpu_port &= ~0x000f; 682 682 if (mpu_port < 0x300 || mpu_port > 0x330) ··· 681 689 chip->mpu_irq = mpu_irq; 682 690 chip->hardware = hardware; 683 691 684 - if ((err = snd_es1688_probe(chip)) < 0) { 685 - snd_es1688_free(chip); 692 + err = snd_es1688_probe(chip); 693 + if (err < 0) 686 694 return err; 687 - } 688 - if ((err = snd_es1688_init(chip, 1)) < 0) { 689 - snd_es1688_free(chip); 695 + 696 + err = snd_es1688_init(chip, 1); 697 + if (err < 0) 690 698 return err; 691 - } 692 699 693 700 /* Register device */ 694 - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 695 - snd_es1688_free(chip); 696 - return err; 697 - } 698 - 699 - *rchip = chip; 700 - return 0; 701 + return snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 701 702 } 702 703 703 704 static struct snd_pcm_ops snd_es1688_playback_ops = { ··· 715 730 .pointer = snd_es1688_capture_pointer, 716 731 }; 717 732 718 - int snd_es1688_pcm(struct snd_es1688 * chip, int device, struct snd_pcm ** rpcm) 733 + int snd_es1688_pcm(struct snd_card *card, struct snd_es1688 *chip, 734 + int device, struct snd_pcm **rpcm) 719 735 { 720 736 struct snd_pcm *pcm; 721 737 int err; 722 738 723 - if ((err = snd_pcm_new(chip->card, "ESx688", device, 1, 1, &pcm)) < 0) 739 + err = snd_pcm_new(card, "ESx688", device, 1, 1, &pcm); 740 + if (err < 0) 724 741 return err; 725 742 726 743 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es1688_playback_ops); ··· 996 1009 { ES1688_REC_DEV, 0x17 } 997 1010 }; 998 1011 999 - int snd_es1688_mixer(struct snd_es1688 *chip) 1012 + int snd_es1688_mixer(struct snd_card *card, struct snd_es1688 *chip) 1000 1013 { 1001 - struct snd_card *card; 1002 1014 unsigned int idx; 1003 1015 int err; 1004 1016 unsigned char reg, val; 1005 1017 1006 - if (snd_BUG_ON(!chip || !chip->card)) 1018 + if (snd_BUG_ON(!chip || !card)) 1007 1019 return -EINVAL; 1008 - 1009 - card = chip->card; 1010 1020 1011 1021 strcpy(card->mixername, snd_es1688_chip_id(chip)); 1012 1022
+14 -12
sound/isa/gus/gusextreme.c
··· 95 95 } 96 96 97 97 static int __devinit snd_gusextreme_es1688_create(struct snd_card *card, 98 - struct device *dev, unsigned int n, struct snd_es1688 **rchip) 98 + struct snd_es1688 *chip, struct device *dev, unsigned int n) 99 99 { 100 100 static long possible_ports[] = {0x220, 0x240, 0x260}; 101 101 static int possible_irqs[] = {5, 9, 10, 7, -1}; ··· 119 119 } 120 120 121 121 if (port[n] != SNDRV_AUTO_PORT) 122 - return snd_es1688_create(card, port[n], mpu_port[n], irq[n], 123 - mpu_irq[n], dma8[n], ES1688_HW_1688, rchip); 122 + return snd_es1688_create(card, chip, port[n], mpu_port[n], 123 + irq[n], mpu_irq[n], dma8[n], ES1688_HW_1688); 124 124 125 125 i = 0; 126 126 do { 127 127 port[n] = possible_ports[i]; 128 - error = snd_es1688_create(card, port[n], mpu_port[n], irq[n], 129 - mpu_irq[n], dma8[n], ES1688_HW_1688, rchip); 128 + error = snd_es1688_create(card, chip, port[n], mpu_port[n], 129 + irq[n], mpu_irq[n], dma8[n], ES1688_HW_1688); 130 130 } while (error < 0 && ++i < ARRAY_SIZE(possible_ports)); 131 131 132 132 return error; ··· 206 206 return 0; 207 207 } 208 208 209 - static int __devinit snd_gusextreme_mixer(struct snd_es1688 *chip) 209 + static int __devinit snd_gusextreme_mixer(struct snd_card *card) 210 210 { 211 - struct snd_card *card = chip->card; 212 211 struct snd_ctl_elem_id id1, id2; 213 212 int error; 214 213 ··· 240 241 struct snd_opl3 *opl3; 241 242 int error; 242 243 243 - error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card); 244 + error = snd_card_create(index[n], id[n], THIS_MODULE, 245 + sizeof(struct snd_es1688), &card); 244 246 if (error < 0) 245 247 return error; 248 + 249 + es1688 = card->private_data; 246 250 247 251 if (mpu_port[n] == SNDRV_AUTO_PORT) 248 252 mpu_port[n] = 0; ··· 253 251 if (mpu_irq[n] > 15) 254 252 mpu_irq[n] = -1; 255 253 256 - error = snd_gusextreme_es1688_create(card, dev, n, &es1688); 254 + error = snd_gusextreme_es1688_create(card, es1688, dev, n); 257 255 if (error < 0) 258 256 goto out; 259 257 ··· 282 280 } 283 281 gus->codec_flag = 1; 284 282 285 - error = snd_es1688_pcm(es1688, 0, NULL); 283 + error = snd_es1688_pcm(card, es1688, 0, NULL); 286 284 if (error < 0) 287 285 goto out; 288 286 289 - error = snd_es1688_mixer(es1688); 287 + error = snd_es1688_mixer(card, es1688); 290 288 if (error < 0) 291 289 goto out; 292 290 ··· 302 300 if (error < 0) 303 301 goto out; 304 302 305 - error = snd_gusextreme_mixer(es1688); 303 + error = snd_gusextreme_mixer(card); 306 304 if (error < 0) 307 305 goto out; 308 306