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

scsi: pmcraid: 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>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Cc: Anil Ravindranath <anil_ravindranath@pmc-sierra.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
ed4414ce f5594686

+6 -40
+1
drivers/scsi/Kconfig
··· 1577 1577 config SCSI_PMCRAID 1578 1578 tristate "PMC SIERRA Linux MaxRAID adapter support" 1579 1579 depends on PCI && SCSI && NET 1580 + select SGL_ALLOC 1580 1581 ---help--- 1581 1582 This driver supports the PMC SIERRA MaxRAID adapters. 1582 1583
+4 -39
drivers/scsi/pmcraid.c
··· 3225 3225 */ 3226 3226 static void pmcraid_free_sglist(struct pmcraid_sglist *sglist) 3227 3227 { 3228 - int i; 3229 - 3230 - for (i = 0; i < sglist->num_sg; i++) 3231 - __free_pages(sg_page(&(sglist->scatterlist[i])), 3232 - sglist->order); 3233 - 3228 + sgl_free_order(sglist->scatterlist, sglist->order); 3234 3229 kfree(sglist); 3235 3230 } 3236 3231 ··· 3242 3247 static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen) 3243 3248 { 3244 3249 struct pmcraid_sglist *sglist; 3245 - struct scatterlist *scatterlist; 3246 - struct page *page; 3247 - int num_elem, i, j; 3248 3250 int sg_size; 3249 3251 int order; 3250 - int bsize_elem; 3251 3252 3252 3253 sg_size = buflen / (PMCRAID_MAX_IOADLS - 1); 3253 3254 order = (sg_size > 0) ? get_order(sg_size) : 0; 3254 - bsize_elem = PAGE_SIZE * (1 << order); 3255 - 3256 - /* Determine the actual number of sg entries needed */ 3257 - if (buflen % bsize_elem) 3258 - num_elem = (buflen / bsize_elem) + 1; 3259 - else 3260 - num_elem = buflen / bsize_elem; 3261 3255 3262 3256 /* Allocate a scatter/gather list for the DMA */ 3263 - sglist = kzalloc(sizeof(struct pmcraid_sglist) + 3264 - (sizeof(struct scatterlist) * (num_elem - 1)), 3265 - GFP_KERNEL); 3266 - 3257 + sglist = kzalloc(sizeof(struct pmcraid_sglist), GFP_KERNEL); 3267 3258 if (sglist == NULL) 3268 3259 return NULL; 3269 3260 3270 - scatterlist = sglist->scatterlist; 3271 - sg_init_table(scatterlist, num_elem); 3272 3261 sglist->order = order; 3273 - sglist->num_sg = num_elem; 3274 - sg_size = buflen; 3275 - 3276 - for (i = 0; i < num_elem; i++) { 3277 - page = alloc_pages(GFP_KERNEL|GFP_DMA|__GFP_ZERO, order); 3278 - if (!page) { 3279 - for (j = i - 1; j >= 0; j--) 3280 - __free_pages(sg_page(&scatterlist[j]), order); 3281 - kfree(sglist); 3282 - return NULL; 3283 - } 3284 - 3285 - sg_set_page(&scatterlist[i], page, 3286 - sg_size < bsize_elem ? sg_size : bsize_elem, 0); 3287 - sg_size -= bsize_elem; 3288 - } 3262 + sgl_alloc_order(buflen, order, false, 3263 + GFP_KERNEL | GFP_DMA | __GFP_ZERO, &sglist->num_sg); 3289 3264 3290 3265 return sglist; 3291 3266 }
+1 -1
drivers/scsi/pmcraid.h
··· 542 542 u32 order; 543 543 u32 num_sg; 544 544 u32 num_dma_sg; 545 - struct scatterlist scatterlist[1]; 545 + struct scatterlist *scatterlist; 546 546 }; 547 547 548 548 /* page D0 inquiry data of focal point resource */