From patchwork Wed Mar 7 12:47:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10263957 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1DDC7602BD for ; Wed, 7 Mar 2018 12:48:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E3A9294A1 for ; Wed, 7 Mar 2018 12:48:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 028D4294F8; Wed, 7 Mar 2018 12:48:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CA40294A1 for ; Wed, 7 Mar 2018 12:48:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754460AbeCGMsN (ORCPT ); Wed, 7 Mar 2018 07:48:13 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:52097 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754233AbeCGMrd (ORCPT ); Wed, 7 Mar 2018 07:47:33 -0500 Received: by mail-wm0-f65.google.com with SMTP id h21so4554548wmd.1 for ; Wed, 07 Mar 2018 04:47:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Cwi9XqoR0pantJu3qAH3oZb95d4ZVP5hWa1tyskGiJ0=; b=1P4zfEIbUun23ROMeZCuG7G6rXcgSR7HVG5yifuhimPH8zP5q1R2kuMyNSEAG5AG3K Puf5dERv7s0OtLuVTlwkRqYAoJffbbYy/SE2lH57tAWUpmRYe066Gw6CS8alLGaqy5C7 xo4fe7jzY3WyKJQu9FhzYb8G1+LcTMS+uSYJc8AlIg9rYLU+9WOeyZj4QzzEdsOltcDG BzE018N8qWHZAOtqYpmIOIYE5C3ULSEvzQMU9Xss4vHBHE+ICTphXvrBDc7B+dKrDDcM oseUe50jusBUhXDWwj+52Rcg0+sgm+JZPjPJJGS/DsQdYAhJbuJf7FhSjhm2lIqP7seC J48A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Cwi9XqoR0pantJu3qAH3oZb95d4ZVP5hWa1tyskGiJ0=; b=Cn/dsIQm02Syx7LgpCBioZ390VGezA1b6W6aYZzU1FrA7XhPEaZhRRuHA85kuj3zSX XdPPxHVV2TWegbU+X0IsBUPvuIMw725vTrbS8vIHlk/e65ctd/a3xQ0zPIBUZz4QOj2m lAhYeQ/HJcO8EWEAJslaHtrXbtQQ2x89WOV4biSMfrD3Jd+iulLMRq3b7dFFAndyfoat CXqBg8Ys8SqqkKaBI6QzKt8IJlnZ+hM/jDJbjVY/ymFskjZ1J/tKiHEvOHtwLHd+KJ0A TrAHDm2OiKeXgef7kK6uSXP04Lgqlga6sCYiI/MZREMujQ0RuQPbcJ/hr23fPb/09vi9 6paw== X-Gm-Message-State: AElRT7ED7CY09PyEYAfE/ebuI5CaSRGtjDTKxRxFOFAtCqk2k8NphgbS xLovy+dnTP4tDZRM0R4rydQ6vU4L X-Google-Smtp-Source: AG47ELsSlqE3YPPfaVrf3E7oQ30j+c0wrexoFZi3qTJdvEZxCyXu5WTipSm+kbKM3REgXuL/1dCbvg== X-Received: by 10.28.159.68 with SMTP id i65mr15296487wme.27.1520426851735; Wed, 07 Mar 2018 04:47:31 -0800 (PST) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id x78sm24325756wmd.2.2018.03.07.04.47.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Mar 2018 04:47:31 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: linux-kernel@vger.kernel.org Cc: Tvrtko Ursulin , Bart Van Assche , Hannes Reinecke , Johannes Thumshirn , Jens Axboe , "Nicholas A. Bellinger" , 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 Message-Id: <20180307124712.14963-7-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180307124712.14963-1-tvrtko.ursulin@linux.intel.com> References: <20180307124712.14963-1-tvrtko.ursulin@linux.intel.com> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin 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 Cc: Bart Van Assche Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Jens Axboe Cc: "Nicholas A. Bellinger" 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 */