From: Tvrtko Ursulin <tursulin@ursulin.net>
To: linux-kernel@vger.kernel.org
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>,
Bart Van Assche <bart.vanassche@wdc.com>,
Hannes Reinecke <hare@suse.com>,
Johannes Thumshirn <jthumshirn@suse.de>,
Jens Axboe <axboe@kernel.dk>,
"Nicholas A. Bellinger" <nab@linux-iscsi.org>,
linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Subject: [PATCH 6/6] lib/scatterlist: Drop order argument from sgl_free_n_order
Date: Wed, 7 Mar 2018 12:47:12 +0000 [thread overview]
Message-ID: <20180307124712.14963-7-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20180307124712.14963-1-tvrtko.ursulin@linux.intel.com>
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
We can derive the order from sg->length and so do not need to pass it in
explicitly. Rename the function to sgl_free_n.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
Cc: linux-scsi@vger.kernel.org
Cc: target-devel@vger.kernel.org
---
drivers/target/target_core_transport.c | 2 +-
include/linux/scatterlist.h | 5 ++---
lib/scatterlist.c | 16 ++++++----------
3 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 4558f2e1fe1b..91e8f4047492 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -2303,7 +2303,7 @@ static void target_complete_ok_work(struct work_struct *work)
void target_free_sgl(struct scatterlist *sgl, int nents)
{
- sgl_free_n_order(sgl, nents, 0);
+ sgl_free_n(sgl, nents);
}
EXPORT_SYMBOL(target_free_sgl);
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index 3ffc5f3bf181..3779d1fdd5c4 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -280,8 +280,7 @@ int sg_alloc_table_from_pages(struct sg_table *sgt, struct page **pages,
struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order,
bool chainable, gfp_t gfp,
unsigned int *nent_p);
-void sgl_free_n_order(struct scatterlist *sgl, unsigned int nents,
- unsigned int order);
+void sgl_free_n(struct scatterlist *sgl, unsigned int nents);
/**
* sgl_alloc - allocate a scatterlist and its pages
@@ -303,7 +302,7 @@ sgl_alloc(unsigned long length, gfp_t gfp, unsigned int *nent_p)
*/
static inline void sgl_free(struct scatterlist *sgl)
{
- sgl_free_n_order(sgl, UINT_MAX, 0);
+ sgl_free_n(sgl, UINT_MAX);
}
#endif /* CONFIG_SGL_ALLOC */
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index c637849482d3..76111e91a038 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -493,7 +493,7 @@ struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order,
{
unsigned int chunk_len = PAGE_SIZE << order;
struct scatterlist *sgl, *sg;
- unsigned int nent, i;
+ unsigned int nent;
nent = round_up(length, chunk_len) >> (PAGE_SHIFT + order);
@@ -517,12 +517,11 @@ struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order,
sg_init_table(sgl, nent);
sg = sgl;
- i = 0;
while (length) {
struct page *page = alloc_pages(gfp, order);
if (!page) {
- sgl_free_n_order(sgl, i, order);
+ sgl_free(sgl);
return NULL;
}
@@ -530,7 +529,6 @@ struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order,
sg_set_page(sg, page, chunk_len, 0);
length -= chunk_len;
sg = sg_next(sg);
- i++;
}
WARN_ONCE(length, "length = %ld\n", length);
return sgl;
@@ -538,10 +536,9 @@ struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order,
EXPORT_SYMBOL(sgl_alloc_order);
/**
- * sgl_free_n_order - free a scatterlist and its pages
+ * sgl_free_n - free a scatterlist and its pages
* @sgl: Scatterlist with one or more elements
* @nents: Maximum number of elements to free
- * @order: Second argument for __free_pages()
*
* Notes:
* - If several scatterlists have been chained and each chain element is
@@ -550,8 +547,7 @@ EXPORT_SYMBOL(sgl_alloc_order);
* - All pages in a chained scatterlist can be freed at once by setting @nents
* to a high number.
*/
-void sgl_free_n_order(struct scatterlist *sgl, unsigned int nents,
- unsigned int order)
+void sgl_free_n(struct scatterlist *sgl, unsigned int nents)
{
struct scatterlist *sg;
struct page *page;
@@ -562,11 +558,11 @@ void sgl_free_n_order(struct scatterlist *sgl, unsigned int nents,
break;
page = sg_page(sg);
if (page)
- __free_pages(page, order);
+ __free_pages(page, get_order(sg->length));
}
kfree(sgl);
}
-EXPORT_SYMBOL(sgl_free_n_order);
+EXPORT_SYMBOL(sgl_free_n);
#endif /* CONFIG_SGL_ALLOC */
--
2.14.1
next prev parent reply other threads:[~2018-03-07 12:48 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-07 12:47 [PATCH 0/6] lib/scatterlist: Small SGL tidy Tvrtko Ursulin
2018-03-07 12:47 ` [PATCH 1/6] lib/scatterlist: Tidy types and fix overflow checking in sgl_alloc_order Tvrtko Ursulin
2018-03-07 16:10 ` Bart Van Assche
2018-03-07 17:06 ` Tvrtko Ursulin
2018-03-09 14:04 ` Tvrtko Ursulin
2018-03-07 12:47 ` [PATCH 2/6] lib/scatterlist: Skip requesting zeroed allocations " Tvrtko Ursulin
2018-03-07 15:35 ` Andy Shevchenko
2018-03-07 17:31 ` Tvrtko Ursulin
2018-03-07 12:47 ` [PATCH 3/6] lib/scatterlist: Do not leak pages when high-order allocation fails Tvrtko Ursulin
2018-03-07 16:16 ` Bart Van Assche
2018-03-07 17:06 ` Tvrtko Ursulin
2018-03-07 12:47 ` [PATCH 4/6] lib/scatterlist: Unexport some trivial wrappers Tvrtko Ursulin
2018-03-07 16:19 ` Bart Van Assche
2018-03-07 17:10 ` Tvrtko Ursulin
2018-03-07 12:47 ` [PATCH 5/6] lib/scatterlist: Drop unused sgl_free_order Tvrtko Ursulin
2018-03-07 12:47 ` Tvrtko Ursulin [this message]
2018-03-07 16:23 ` [PATCH 6/6] lib/scatterlist: Drop order argument from sgl_free_n_order Bart Van Assche
2018-03-07 17:23 ` Tvrtko Ursulin
2018-03-07 17:33 ` Bart Van Assche
2018-03-07 18:30 ` James Bottomley
2018-03-08 7:59 ` Tvrtko Ursulin
2018-03-08 15:56 ` Bart Van Assche
2018-03-08 17:06 ` Tvrtko Ursulin
2018-03-07 18:38 ` [PATCH 0/6] lib/scatterlist: Small SGL tidy Bart Van Assche
2018-03-08 8:04 ` Tvrtko Ursulin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180307124712.14963-7-tvrtko.ursulin@linux.intel.com \
--to=tursulin@ursulin.net \
--cc=axboe@kernel.dk \
--cc=bart.vanassche@wdc.com \
--cc=hare@suse.com \
--cc=jthumshirn@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=nab@linux-iscsi.org \
--cc=target-devel@vger.kernel.org \
--cc=tvrtko.ursulin@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox