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

ALSA: wavefront: Allocate resources with device-managed APIs

This patch converts the resource management in ISA wavefront driver
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-72-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+9 -37
+9 -37
sound/isa/wavefront/wavefront.c
··· 308 308 return rmidi; 309 309 } 310 310 311 - static void 312 - snd_wavefront_free(struct snd_card *card) 313 - { 314 - snd_wavefront_card_t *acard = (snd_wavefront_card_t *)card->private_data; 315 - 316 - if (acard) { 317 - release_and_free_resource(acard->wavefront.res_base); 318 - if (acard->wavefront.irq > 0) 319 - free_irq(acard->wavefront.irq, (void *)acard); 320 - } 321 - } 322 - 323 311 static int snd_wavefront_card_new(struct device *pdev, int dev, 324 312 struct snd_card **cardp) 325 313 { ··· 315 327 snd_wavefront_card_t *acard; 316 328 int err; 317 329 318 - err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE, 319 - sizeof(snd_wavefront_card_t), &card); 330 + err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE, 331 + sizeof(snd_wavefront_card_t), &card); 320 332 if (err < 0) 321 333 return err; 322 334 ··· 327 339 spin_lock_init(&acard->wavefront.midi.open); 328 340 spin_lock_init(&acard->wavefront.midi.virtual); 329 341 acard->wavefront.card = card; 330 - card->private_free = snd_wavefront_free; 331 342 332 343 *cardp = card; 333 344 return 0; ··· 381 394 382 395 /* ------- ICS2115 Wavetable synth ------- */ 383 396 384 - acard->wavefront.res_base = request_region(ics2115_port[dev], 16, 385 - "ICS2115"); 397 + acard->wavefront.res_base = 398 + devm_request_region(card->dev, ics2115_port[dev], 16, 399 + "ICS2115"); 386 400 if (acard->wavefront.res_base == NULL) { 387 401 snd_printk(KERN_ERR "unable to grab ICS2115 i/o region 0x%lx-0x%lx\n", 388 402 ics2115_port[dev], ics2115_port[dev] + 16 - 1); 389 403 return -EBUSY; 390 404 } 391 - if (request_irq(ics2115_irq[dev], snd_wavefront_ics2115_interrupt, 392 - 0, "ICS2115", acard)) { 405 + if (devm_request_irq(card->dev, ics2115_irq[dev], 406 + snd_wavefront_ics2115_interrupt, 407 + 0, "ICS2115", acard)) { 393 408 snd_printk(KERN_ERR "unable to use ICS2115 IRQ %d\n", ics2115_irq[dev]); 394 409 return -EBUSY; 395 410 } ··· 545 556 if (err < 0) 546 557 return err; 547 558 err = snd_wavefront_probe(card, dev); 548 - if (err < 0) { 549 - snd_card_free(card); 559 + if (err < 0) 550 560 return err; 551 - } 552 561 553 562 dev_set_drvdata(pdev, card); 554 563 return 0; 555 - } 556 - 557 - static void snd_wavefront_isa_remove(struct device *devptr, 558 - unsigned int dev) 559 - { 560 - snd_card_free(dev_get_drvdata(devptr)); 561 564 } 562 565 563 566 #define DEV_NAME "wavefront" ··· 557 576 static struct isa_driver snd_wavefront_driver = { 558 577 .match = snd_wavefront_isa_match, 559 578 .probe = snd_wavefront_isa_probe, 560 - .remove = snd_wavefront_isa_remove, 561 579 /* FIXME: suspend, resume */ 562 580 .driver = { 563 581 .name = DEV_NAME ··· 586 606 if (snd_wavefront_pnp (dev, card->private_data, pcard, pid) < 0) { 587 607 if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) { 588 608 snd_printk (KERN_ERR "isapnp detection failed\n"); 589 - snd_card_free (card); 590 609 return -ENODEV; 591 610 } 592 611 } ··· 599 620 return 0; 600 621 } 601 622 602 - static void snd_wavefront_pnp_remove(struct pnp_card_link *pcard) 603 - { 604 - snd_card_free(pnp_get_card_drvdata(pcard)); 605 - pnp_set_card_drvdata(pcard, NULL); 606 - } 607 - 608 623 static struct pnp_card_driver wavefront_pnpc_driver = { 609 624 .flags = PNP_DRIVER_RES_DISABLE, 610 625 .name = "wavefront", 611 626 .id_table = snd_wavefront_pnpids, 612 627 .probe = snd_wavefront_pnp_detect, 613 - .remove = snd_wavefront_pnp_remove, 614 628 /* FIXME: suspend,resume */ 615 629 }; 616 630