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

scsi: ipr: Use sgl_alloc_order() and sgl_free_order()

Use the sgl_alloc_order() and sgl_free_order() functions instead of open
coding these functions.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Acked-by: Brian King <brking@linux.vnet.ibm.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
f95dc1bb b22ee87d

+10 -42
+1
drivers/scsi/Kconfig
··· 1059 1059 depends on PCI && SCSI && ATA 1060 1060 select FW_LOADER 1061 1061 select IRQ_POLL 1062 + select SGL_ALLOC 1062 1063 ---help--- 1063 1064 This driver supports the IBM Power Linux family RAID adapters. 1064 1065 This includes IBM pSeries 5712, 5703, 5709, and 570A, as well
+8 -41
drivers/scsi/ipr.c
··· 3816 3816 **/ 3817 3817 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len) 3818 3818 { 3819 - int sg_size, order, bsize_elem, num_elem, i, j; 3819 + int sg_size, order; 3820 3820 struct ipr_sglist *sglist; 3821 - struct scatterlist *scatterlist; 3822 - struct page *page; 3823 3821 3824 3822 /* Get the minimum size per scatter/gather element */ 3825 3823 sg_size = buf_len / (IPR_MAX_SGLIST - 1); ··· 3825 3827 /* Get the actual size per element */ 3826 3828 order = get_order(sg_size); 3827 3829 3828 - /* Determine the actual number of bytes per element */ 3829 - bsize_elem = PAGE_SIZE * (1 << order); 3830 - 3831 - /* Determine the actual number of sg entries needed */ 3832 - if (buf_len % bsize_elem) 3833 - num_elem = (buf_len / bsize_elem) + 1; 3834 - else 3835 - num_elem = buf_len / bsize_elem; 3836 - 3837 3830 /* Allocate a scatter/gather list for the DMA */ 3838 - sglist = kzalloc(sizeof(struct ipr_sglist) + 3839 - (sizeof(struct scatterlist) * (num_elem - 1)), 3840 - GFP_KERNEL); 3841 - 3831 + sglist = kzalloc(sizeof(struct ipr_sglist), GFP_KERNEL); 3842 3832 if (sglist == NULL) { 3843 3833 ipr_trace; 3844 3834 return NULL; 3845 3835 } 3846 - 3847 - scatterlist = sglist->scatterlist; 3848 - sg_init_table(scatterlist, num_elem); 3849 - 3850 3836 sglist->order = order; 3851 - sglist->num_sg = num_elem; 3852 - 3853 - /* Allocate a bunch of sg elements */ 3854 - for (i = 0; i < num_elem; i++) { 3855 - page = alloc_pages(GFP_KERNEL, order); 3856 - if (!page) { 3857 - ipr_trace; 3858 - 3859 - /* Free up what we already allocated */ 3860 - for (j = i - 1; j >= 0; j--) 3861 - __free_pages(sg_page(&scatterlist[j]), order); 3862 - kfree(sglist); 3863 - return NULL; 3864 - } 3865 - 3866 - sg_set_page(&scatterlist[i], page, 0, 0); 3837 + sglist->scatterlist = sgl_alloc_order(buf_len, order, false, GFP_KERNEL, 3838 + &sglist->num_sg); 3839 + if (!sglist->scatterlist) { 3840 + kfree(sglist); 3841 + return NULL; 3867 3842 } 3868 3843 3869 3844 return sglist; ··· 3854 3883 **/ 3855 3884 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist) 3856 3885 { 3857 - int i; 3858 - 3859 - for (i = 0; i < sglist->num_sg; i++) 3860 - __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order); 3861 - 3886 + sgl_free_order(sglist->scatterlist, sglist->order); 3862 3887 kfree(sglist); 3863 3888 } 3864 3889
+1 -1
drivers/scsi/ipr.h
··· 1454 1454 u32 num_sg; 1455 1455 u32 num_dma_sg; 1456 1456 u32 buffer_len; 1457 - struct scatterlist scatterlist[1]; 1457 + struct scatterlist *scatterlist; 1458 1458 }; 1459 1459 1460 1460 enum ipr_sdt_state {