summaryrefslogtreecommitdiffstats
path: root/drivers/target
diff options
context:
space:
mode:
authorBart Van Assche <bart.vanassche@wdc.com>2018-01-05 11:26:50 -0500
committerJens Axboe <axboe@kernel.dk>2018-01-06 11:18:00 -0500
commit14db49172649aac001fd77a3fd53d12c6df22daf (patch)
treefdfd9c997ad5e268073438a55a95269d29654fe9 /drivers/target
parent68c6e9cd2fa4f0109364834475628b4b1dd12257 (diff)
target: Use sgl_alloc_order() and sgl_free()
Use the sgl_alloc_order() and sgl_free() functions instead of open coding these functions. Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com> Acked-by: Nicholas A. Bellinger <nab@linux-iscsi.org> Reviewed-by: Hannes Reinecke <hare@suse.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/target')
-rw-r--r--drivers/target/Kconfig1
-rw-r--r--drivers/target/target_core_transport.c46
2 files changed, 5 insertions, 42 deletions
diff --git a/drivers/target/Kconfig b/drivers/target/Kconfig
index e2bc99980f75..4c44d7bed01a 100644
--- a/drivers/target/Kconfig
+++ b/drivers/target/Kconfig
@@ -5,6 +5,7 @@ menuconfig TARGET_CORE
5 select CONFIGFS_FS 5 select CONFIGFS_FS
6 select CRC_T10DIF 6 select CRC_T10DIF
7 select BLK_SCSI_REQUEST # only for scsi_command_size_tbl.. 7 select BLK_SCSI_REQUEST # only for scsi_command_size_tbl..
8 select SGL_ALLOC
8 default n 9 default n
9 help 10 help
10 Say Y or M here to enable the TCM Storage Engine and ConfigFS enabled 11 Say Y or M here to enable the TCM Storage Engine and ConfigFS enabled
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 58caacd54a3b..a001ba711cca 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -2300,13 +2300,7 @@ queue_full:
2300 2300
2301void target_free_sgl(struct scatterlist *sgl, int nents) 2301void target_free_sgl(struct scatterlist *sgl, int nents)
2302{ 2302{
2303 struct scatterlist *sg; 2303 sgl_free(sgl);
2304 int count;
2305
2306 for_each_sg(sgl, sg, nents, count)
2307 __free_page(sg_page(sg));
2308
2309 kfree(sgl);
2310} 2304}
2311EXPORT_SYMBOL(target_free_sgl); 2305EXPORT_SYMBOL(target_free_sgl);
2312 2306
@@ -2414,42 +2408,10 @@ int
2414target_alloc_sgl(struct scatterlist **sgl, unsigned int *nents, u32 length, 2408target_alloc_sgl(struct scatterlist **sgl, unsigned int *nents, u32 length,
2415 bool zero_page, bool chainable) 2409 bool zero_page, bool chainable)
2416{ 2410{
2417 struct scatterlist *sg; 2411 gfp_t gfp = GFP_KERNEL | (zero_page ? __GFP_ZERO : 0);
2418 struct page *page;
2419 gfp_t zero_flag = (zero_page) ? __GFP_ZERO : 0;
2420 unsigned int nalloc, nent;
2421 int i = 0;
2422
2423 nalloc = nent = DIV_ROUND_UP(length, PAGE_SIZE);
2424 if (chainable)
2425 nalloc++;
2426 sg = kmalloc_array(nalloc, sizeof(struct scatterlist), GFP_KERNEL);
2427 if (!sg)
2428 return -ENOMEM;
2429 2412
2430 sg_init_table(sg, nalloc); 2413 *sgl = sgl_alloc_order(length, 0, chainable, gfp, nents);
2431 2414 return *sgl ? 0 : -ENOMEM;
2432 while (length) {
2433 u32 page_len = min_t(u32, length, PAGE_SIZE);
2434 page = alloc_page(GFP_KERNEL | zero_flag);
2435 if (!page)
2436 goto out;
2437
2438 sg_set_page(&sg[i], page, page_len, 0);
2439 length -= page_len;
2440 i++;
2441 }
2442 *sgl = sg;
2443 *nents = nent;
2444 return 0;
2445
2446out:
2447 while (i > 0) {
2448 i--;
2449 __free_page(sg_page(&sg[i]));
2450 }
2451 kfree(sg);
2452 return -ENOMEM;
2453} 2415}
2454EXPORT_SYMBOL(target_alloc_sgl); 2416EXPORT_SYMBOL(target_alloc_sgl);
2455 2417