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

ALSA: cs423x: Allocate resources with device-managed APIs

This patch converts the resource management in ISA cs423x drivers with
devres as a clean up. Each manual resource management is converted
with the corresponding devres helper. The remove callback became
superfluous and dropped.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-62-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+13 -60
+6 -15
sound/isa/cs423x/cs4231.c
··· 79 79 struct snd_wss *chip; 80 80 int error; 81 81 82 - error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card); 82 + error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card); 83 83 if (error < 0) 84 84 return error; 85 85 86 86 error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], dma2[n], 87 87 WSS_HW_DETECT, 0, &chip); 88 88 if (error < 0) 89 - goto out; 89 + return error; 90 90 91 91 card->private_data = chip; 92 92 93 93 error = snd_wss_pcm(chip, 0); 94 94 if (error < 0) 95 - goto out; 95 + return error; 96 96 97 97 strscpy(card->driver, "CS4231", sizeof(card->driver)); 98 98 strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); ··· 108 108 109 109 error = snd_wss_mixer(chip); 110 110 if (error < 0) 111 - goto out; 111 + return error; 112 112 113 113 error = snd_wss_timer(chip, 0); 114 114 if (error < 0) 115 - goto out; 115 + return error; 116 116 117 117 if (mpu_port[n] > 0 && mpu_port[n] != SNDRV_AUTO_PORT) { 118 118 if (mpu_irq[n] == SNDRV_AUTO_IRQ) ··· 125 125 126 126 error = snd_card_register(card); 127 127 if (error < 0) 128 - goto out; 128 + return error; 129 129 130 130 dev_set_drvdata(dev, card); 131 131 return 0; 132 - 133 - out: snd_card_free(card); 134 - return error; 135 - } 136 - 137 - static void snd_cs4231_remove(struct device *dev, unsigned int n) 138 - { 139 - snd_card_free(dev_get_drvdata(dev)); 140 132 } 141 133 142 134 #ifdef CONFIG_PM ··· 156 164 static struct isa_driver snd_cs4231_driver = { 157 165 .match = snd_cs4231_match, 158 166 .probe = snd_cs4231_probe, 159 - .remove = snd_cs4231_remove, 160 167 #ifdef CONFIG_PM 161 168 .suspend = snd_cs4231_suspend, 162 169 .resume = snd_cs4231_resume,
+7 -45
sound/isa/cs423x/cs4236.c
··· 76 76 77 77 struct snd_card_cs4236 { 78 78 struct snd_wss *chip; 79 - struct resource *res_sb_port; 80 79 #ifdef CONFIG_PNP 81 80 struct pnp_dev *wss; 82 81 struct pnp_dev *ctrl; ··· 308 309 #define is_isapnp_selected(dev) 0 309 310 #endif 310 311 311 - static void snd_card_cs4236_free(struct snd_card *card) 312 - { 313 - struct snd_card_cs4236 *acard = card->private_data; 314 - 315 - release_and_free_resource(acard->res_sb_port); 316 - } 317 - 318 312 static int snd_cs423x_card_new(struct device *pdev, int dev, 319 313 struct snd_card **cardp) 320 314 { 321 315 struct snd_card *card; 322 316 int err; 323 317 324 - err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE, 325 - sizeof(struct snd_card_cs4236), &card); 318 + err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE, 319 + sizeof(struct snd_card_cs4236), &card); 326 320 if (err < 0) 327 321 return err; 328 - card->private_free = snd_card_cs4236_free; 329 322 *cardp = card; 330 323 return 0; 331 324 } ··· 331 340 332 341 acard = card->private_data; 333 342 if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT) { 334 - acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB"); 335 - if (!acard->res_sb_port) { 343 + if (!devm_request_region(card->dev, sb_port[dev], 16, 344 + IDENT " SB")) { 336 345 printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]); 337 346 return -EBUSY; 338 347 } ··· 439 448 if (err < 0) 440 449 return err; 441 450 err = snd_cs423x_probe(card, dev); 442 - if (err < 0) { 443 - snd_card_free(card); 451 + if (err < 0) 444 452 return err; 445 - } 446 - 447 453 dev_set_drvdata(pdev, card); 448 454 return 0; 449 - } 450 - 451 - static void snd_cs423x_isa_remove(struct device *pdev, 452 - unsigned int dev) 453 - { 454 - snd_card_free(dev_get_drvdata(pdev)); 455 455 } 456 456 457 457 #ifdef CONFIG_PM ··· 477 495 static struct isa_driver cs423x_isa_driver = { 478 496 .match = snd_cs423x_isa_match, 479 497 .probe = snd_cs423x_isa_probe, 480 - .remove = snd_cs423x_isa_remove, 481 498 #ifdef CONFIG_PM 482 499 .suspend = snd_cs423x_isa_suspend, 483 500 .resume = snd_cs423x_isa_resume, ··· 520 539 err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev); 521 540 if (err < 0) { 522 541 printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n"); 523 - snd_card_free(card); 524 542 return err; 525 543 } 526 544 err = snd_cs423x_probe(card, dev); 527 - if (err < 0) { 528 - snd_card_free(card); 545 + if (err < 0) 529 546 return err; 530 - } 531 547 pnp_set_drvdata(pdev, card); 532 548 dev++; 533 549 return 0; 534 - } 535 - 536 - static void snd_cs423x_pnp_remove(struct pnp_dev *pdev) 537 - { 538 - snd_card_free(pnp_get_drvdata(pdev)); 539 550 } 540 551 541 552 #ifdef CONFIG_PM ··· 546 573 .name = "cs423x-pnpbios", 547 574 .id_table = snd_cs423x_pnpbiosids, 548 575 .probe = snd_cs423x_pnpbios_detect, 549 - .remove = snd_cs423x_pnp_remove, 550 576 #ifdef CONFIG_PM 551 577 .suspend = snd_cs423x_pnp_suspend, 552 578 .resume = snd_cs423x_pnp_resume, ··· 573 601 if (res < 0) { 574 602 printk(KERN_ERR "isapnp detection failed and probing for " IDENT 575 603 " is not supported\n"); 576 - snd_card_free(card); 577 604 return res; 578 605 } 579 606 res = snd_cs423x_probe(card, dev); 580 - if (res < 0) { 581 - snd_card_free(card); 607 + if (res < 0) 582 608 return res; 583 - } 584 609 pnp_set_card_drvdata(pcard, card); 585 610 dev++; 586 611 return 0; 587 - } 588 - 589 - static void snd_cs423x_pnpc_remove(struct pnp_card_link *pcard) 590 - { 591 - snd_card_free(pnp_get_card_drvdata(pcard)); 592 - pnp_set_card_drvdata(pcard, NULL); 593 612 } 594 613 595 614 #ifdef CONFIG_PM ··· 600 637 .name = CS423X_ISAPNP_DRIVER, 601 638 .id_table = snd_cs423x_pnpids, 602 639 .probe = snd_cs423x_pnpc_detect, 603 - .remove = snd_cs423x_pnpc_remove, 604 640 #ifdef CONFIG_PM 605 641 .suspend = snd_cs423x_pnpc_suspend, 606 642 .resume = snd_cs423x_pnpc_resume,