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

[libata] ATAPI pad allocation fixes/cleanup

Use ata_pad_{alloc,free} in two drivers, to factor out common code.

Add ata_pad_{alloc,free} to two other drivers, which needed the padding
but had not been updated.

+71 -26
+6 -5
drivers/scsi/ahci.c
··· 307 307 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 308 308 void *mem; 309 309 dma_addr_t mem_dma; 310 + int rc; 310 311 311 312 pp = kmalloc(sizeof(*pp), GFP_KERNEL); 312 313 if (!pp) 313 314 return -ENOMEM; 314 315 memset(pp, 0, sizeof(*pp)); 315 316 316 - ap->pad = dma_alloc_coherent(dev, ATA_DMA_PAD_BUF_SZ, &ap->pad_dma, GFP_KERNEL); 317 - if (!ap->pad) { 317 + rc = ata_pad_alloc(ap, dev); 318 + if (rc) { 318 319 kfree(pp); 319 - return -ENOMEM; 320 + return rc; 320 321 } 321 322 322 323 mem = dma_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma, GFP_KERNEL); 323 324 if (!mem) { 324 - dma_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma); 325 + ata_pad_free(ap, dev); 325 326 kfree(pp); 326 327 return -ENOMEM; 327 328 } ··· 398 397 ap->private_data = NULL; 399 398 dma_free_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, 400 399 pp->cmd_slot, pp->cmd_slot_dma); 401 - dma_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma); 400 + ata_pad_free(ap, dev); 402 401 kfree(pp); 403 402 } 404 403
+5 -4
drivers/scsi/libata-core.c
··· 4091 4091 int ata_port_start (struct ata_port *ap) 4092 4092 { 4093 4093 struct device *dev = ap->host_set->dev; 4094 + int rc; 4094 4095 4095 4096 ap->prd = dma_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma, GFP_KERNEL); 4096 4097 if (!ap->prd) 4097 4098 return -ENOMEM; 4098 4099 4099 - ap->pad = dma_alloc_coherent(dev, ATA_DMA_PAD_BUF_SZ, &ap->pad_dma, GFP_KERNEL); 4100 - if (!ap->pad) { 4100 + rc = ata_pad_alloc(ap, dev); 4101 + if (rc) { 4101 4102 dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma); 4102 - return -ENOMEM; 4103 + return rc; 4103 4104 } 4104 4105 4105 4106 DPRINTK("prd alloc, virt %p, dma %llx\n", ap->prd, (unsigned long long) ap->prd_dma); ··· 4126 4125 struct device *dev = ap->host_set->dev; 4127 4126 4128 4127 dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma); 4129 - dma_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma); 4128 + ata_pad_free(ap, dev); 4130 4129 } 4131 4130 4132 4131 void ata_host_stop (struct ata_host_set *host_set)
+23 -8
drivers/scsi/sata_mv.c
··· 670 670 ata_host_stop(host_set); 671 671 } 672 672 673 + static inline void mv_priv_free(struct mv_port_priv *pp, struct device *dev) 674 + { 675 + dma_free_coherent(dev, MV_PORT_PRIV_DMA_SZ, pp->crpb, pp->crpb_dma); 676 + } 677 + 673 678 /** 674 679 * mv_port_start - Port specific init/start routine. 675 680 * @ap: ATA channel to manipulate ··· 692 687 void __iomem *port_mmio = mv_ap_base(ap); 693 688 void *mem; 694 689 dma_addr_t mem_dma; 690 + int rc = -ENOMEM; 695 691 696 692 pp = kmalloc(sizeof(*pp), GFP_KERNEL); 697 - if (!pp) { 698 - return -ENOMEM; 699 - } 693 + if (!pp) 694 + goto err_out; 700 695 memset(pp, 0, sizeof(*pp)); 701 696 702 697 mem = dma_alloc_coherent(dev, MV_PORT_PRIV_DMA_SZ, &mem_dma, 703 698 GFP_KERNEL); 704 - if (!mem) { 705 - kfree(pp); 706 - return -ENOMEM; 707 - } 699 + if (!mem) 700 + goto err_out_pp; 708 701 memset(mem, 0, MV_PORT_PRIV_DMA_SZ); 702 + 703 + rc = ata_pad_alloc(ap, dev); 704 + if (rc) 705 + goto err_out_priv; 709 706 710 707 /* First item in chunk of DMA memory: 711 708 * 32-slot command request table (CRQB), 32 bytes each in size ··· 753 746 */ 754 747 ap->private_data = pp; 755 748 return 0; 749 + 750 + err_out_priv: 751 + mv_priv_free(pp, dev); 752 + err_out_pp: 753 + kfree(pp); 754 + err_out: 755 + return rc; 756 756 } 757 757 758 758 /** ··· 782 768 spin_unlock_irqrestore(&ap->host_set->lock, flags); 783 769 784 770 ap->private_data = NULL; 785 - dma_free_coherent(dev, MV_PORT_PRIV_DMA_SZ, pp->crpb, pp->crpb_dma); 771 + ata_pad_free(ap, dev); 772 + mv_priv_free(pp, dev); 786 773 kfree(pp); 787 774 } 788 775
+24 -9
drivers/scsi/sata_sil24.c
··· 635 635 return IRQ_RETVAL(handled); 636 636 } 637 637 638 + static inline void sil24_cblk_free(struct sil24_port_priv *pp, struct device *dev) 639 + { 640 + const size_t cb_size = sizeof(*pp->cmd_block); 641 + 642 + dma_free_coherent(dev, cb_size, pp->cmd_block, pp->cmd_block_dma); 643 + } 644 + 638 645 static int sil24_port_start(struct ata_port *ap) 639 646 { 640 647 struct device *dev = ap->host_set->dev; ··· 649 642 struct sil24_cmd_block *cb; 650 643 size_t cb_size = sizeof(*cb); 651 644 dma_addr_t cb_dma; 645 + int rc = -ENOMEM; 652 646 653 - pp = kmalloc(sizeof(*pp), GFP_KERNEL); 647 + pp = kzalloc(sizeof(*pp), GFP_KERNEL); 654 648 if (!pp) 655 - return -ENOMEM; 656 - memset(pp, 0, sizeof(*pp)); 649 + goto err_out; 657 650 658 651 pp->tf.command = ATA_DRDY; 659 652 660 653 cb = dma_alloc_coherent(dev, cb_size, &cb_dma, GFP_KERNEL); 661 - if (!cb) { 662 - kfree(pp); 663 - return -ENOMEM; 664 - } 654 + if (!cb) 655 + goto err_out_pp; 665 656 memset(cb, 0, cb_size); 657 + 658 + rc = ata_pad_alloc(ap, dev); 659 + if (rc) 660 + goto err_out_pad; 666 661 667 662 pp->cmd_block = cb; 668 663 pp->cmd_block_dma = cb_dma; ··· 672 663 ap->private_data = pp; 673 664 674 665 return 0; 666 + 667 + err_out_pad: 668 + sil24_cblk_free(pp, dev); 669 + err_out_pp: 670 + kfree(pp); 671 + err_out: 672 + return rc; 675 673 } 676 674 677 675 static void sil24_port_stop(struct ata_port *ap) 678 676 { 679 677 struct device *dev = ap->host_set->dev; 680 678 struct sil24_port_priv *pp = ap->private_data; 681 - size_t cb_size = sizeof(*pp->cmd_block); 682 679 683 - dma_free_coherent(dev, cb_size, pp->cmd_block, pp->cmd_block_dma); 680 + sil24_cblk_free(pp, dev); 684 681 kfree(pp); 685 682 } 686 683
+13
include/linux/libata.h
··· 777 777 return mask; 778 778 } 779 779 780 + static inline int ata_pad_alloc(struct ata_port *ap, struct device *dev) 781 + { 782 + ap->pad_dma = 0; 783 + ap->pad = dma_alloc_coherent(dev, ATA_DMA_PAD_BUF_SZ, 784 + &ap->pad_dma, GFP_KERNEL); 785 + return (ap->pad == NULL) ? -ENOMEM : 0; 786 + } 787 + 788 + static inline void ata_pad_free(struct ata_port *ap, struct device *dev) 789 + { 790 + dma_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma); 791 + } 792 + 780 793 #endif /* __LINUX_LIBATA_H__ */