diff options
author | Bart Van Assche <bart.vanassche@wdc.com> | 2018-02-12 11:58:19 -0500 |
---|---|---|
committer | Martin K. Petersen <martin.petersen@oracle.com> | 2018-02-13 21:49:15 -0500 |
commit | ed4414cef2ad0ad0afb3d77a6fdde425d7f7ec4d (patch) | |
tree | d76cd830f86a373d7f3c23391d04af20725accfd /drivers/scsi/pmcraid.c | |
parent | f5594686f5f06637bea144159dfe147dae3040d2 (diff) |
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>
Diffstat (limited to 'drivers/scsi/pmcraid.c')
-rw-r--r-- | drivers/scsi/pmcraid.c | 43 |
1 files changed, 4 insertions, 39 deletions
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c index 9330cc5ba34d..95530393872d 100644 --- a/drivers/scsi/pmcraid.c +++ b/drivers/scsi/pmcraid.c | |||
@@ -3225,12 +3225,7 @@ static int pmcraid_build_ioadl( | |||
3225 | */ | 3225 | */ |
3226 | static void pmcraid_free_sglist(struct pmcraid_sglist *sglist) | 3226 | static void pmcraid_free_sglist(struct pmcraid_sglist *sglist) |
3227 | { | 3227 | { |
3228 | int i; | 3228 | sgl_free_order(sglist->scatterlist, sglist->order); |
3229 | |||
3230 | for (i = 0; i < sglist->num_sg; i++) | ||
3231 | __free_pages(sg_page(&(sglist->scatterlist[i])), | ||
3232 | sglist->order); | ||
3233 | |||
3234 | kfree(sglist); | 3229 | kfree(sglist); |
3235 | } | 3230 | } |
3236 | 3231 | ||
@@ -3247,50 +3242,20 @@ static void pmcraid_free_sglist(struct pmcraid_sglist *sglist) | |||
3247 | static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen) | 3242 | static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen) |
3248 | { | 3243 | { |
3249 | struct pmcraid_sglist *sglist; | 3244 | struct pmcraid_sglist *sglist; |
3250 | struct scatterlist *scatterlist; | ||
3251 | struct page *page; | ||
3252 | int num_elem, i, j; | ||
3253 | int sg_size; | 3245 | int sg_size; |
3254 | int order; | 3246 | int order; |
3255 | int bsize_elem; | ||
3256 | 3247 | ||
3257 | sg_size = buflen / (PMCRAID_MAX_IOADLS - 1); | 3248 | sg_size = buflen / (PMCRAID_MAX_IOADLS - 1); |
3258 | order = (sg_size > 0) ? get_order(sg_size) : 0; | 3249 | order = (sg_size > 0) ? get_order(sg_size) : 0; |
3259 | bsize_elem = PAGE_SIZE * (1 << order); | ||
3260 | |||
3261 | /* Determine the actual number of sg entries needed */ | ||
3262 | if (buflen % bsize_elem) | ||
3263 | num_elem = (buflen / bsize_elem) + 1; | ||
3264 | else | ||
3265 | num_elem = buflen / bsize_elem; | ||
3266 | 3250 | ||
3267 | /* Allocate a scatter/gather list for the DMA */ | 3251 | /* Allocate a scatter/gather list for the DMA */ |
3268 | sglist = kzalloc(sizeof(struct pmcraid_sglist) + | 3252 | sglist = kzalloc(sizeof(struct pmcraid_sglist), GFP_KERNEL); |
3269 | (sizeof(struct scatterlist) * (num_elem - 1)), | ||
3270 | GFP_KERNEL); | ||
3271 | |||
3272 | if (sglist == NULL) | 3253 | if (sglist == NULL) |
3273 | return NULL; | 3254 | return NULL; |
3274 | 3255 | ||
3275 | scatterlist = sglist->scatterlist; | ||
3276 | sg_init_table(scatterlist, num_elem); | ||
3277 | sglist->order = order; | 3256 | sglist->order = order; |
3278 | sglist->num_sg = num_elem; | 3257 | sgl_alloc_order(buflen, order, false, |
3279 | sg_size = buflen; | 3258 | GFP_KERNEL | GFP_DMA | __GFP_ZERO, &sglist->num_sg); |
3280 | |||
3281 | for (i = 0; i < num_elem; i++) { | ||
3282 | page = alloc_pages(GFP_KERNEL|GFP_DMA|__GFP_ZERO, order); | ||
3283 | if (!page) { | ||
3284 | for (j = i - 1; j >= 0; j--) | ||
3285 | __free_pages(sg_page(&scatterlist[j]), order); | ||
3286 | kfree(sglist); | ||
3287 | return NULL; | ||
3288 | } | ||
3289 | |||
3290 | sg_set_page(&scatterlist[i], page, | ||
3291 | sg_size < bsize_elem ? sg_size : bsize_elem, 0); | ||
3292 | sg_size -= bsize_elem; | ||
3293 | } | ||
3294 | 3259 | ||
3295 | return sglist; | 3260 | return sglist; |
3296 | } | 3261 | } |