Received: by 10.223.185.116 with SMTP id b49csp4100283wrg; Tue, 13 Feb 2018 12:46:45 -0800 (PST) X-Google-Smtp-Source: AH8x225MgeBdDnj89FKAFokScYeuwquq3RzeiZ62h7V0vZTDnvLi+mM0WDhO8cYESsiRjRZp9m+q X-Received: by 2002:a17:902:529:: with SMTP id 38-v6mr2177147plf.327.1518554805213; Tue, 13 Feb 2018 12:46:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518554805; cv=none; d=google.com; s=arc-20160816; b=W+0033lzEjfhpD+PFJaYp/PAphtJY7JyJ7S87fCWpbNJI+DFqpXl7wnBJD7S2IoiqY D3fOWunO9nJLlq4lrJFKuzG4fI72R1vVwYsKvwIE63VTxaI1gJfHRm6ghyqDjBlGJWls PXrF8A/3ru+7oRl1Zex/YBQffDVtn5ZjZlVR6Yt6fb78XNuBDFY1ev/QKL29VGGDNOxx AZOfK0jb8Wktm2/n1kmVSWLxVcXo/iQNmPgNUAYczWYLTwWCzx+gHHGh8lDFIL24su8z YlJn4Xyf9etZh6Es707x9UawYKK+5ahH849nrwJ+ONC0Is5iVCJsWEUC3I9Ul6wX3YTi Wbsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=zFMfbBF8SZEL1PEk7sqgrH1pG4IuvPuzxYURMpTvddA=; b=ksZY0oPFI6yKXf9YBvUJcPtfUei0yW6LOHsCr55BbBblQ7mJHM0psNLMpx+8XsgQCB CLRRoW7rVh4iE2Fqs0Nu41ec4fRW+ddrq8jo7lRj6TJdTPCAbsReStQPRXvDy3lfYodT hzu/vc7Qj5Wna0Mr6SFk/xW6YDuW/EAZvUs1o2N0sNA3qOYw7J0RfWmjqEtEQHiNzZOb IW4327hlhjodbJ+HIhv75MITnALZusbik8fMIyqJXeMlqufgvyrLHZz4Zto8BGYjCZUa MUcRu+wXr2g8kM2hztfeOXXScCttTaSrs2MiyrSqjSQHe6N7xXeseIyQx+4FRF8kGtgB CrYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v1si1539477pge.759.2018.02.13.12.46.30; Tue, 13 Feb 2018 12:46:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965771AbeBMUpv (ORCPT + 99 others); Tue, 13 Feb 2018 15:45:51 -0500 Received: from mga11.intel.com ([192.55.52.93]:42960 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965719AbeBMUpv (ORCPT ); Tue, 13 Feb 2018 15:45:51 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2018 12:45:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,509,1511856000"; d="scan'208";a="203851891" Received: from alexey-system-product-name.iil.intel.com (HELO [10.236.193.131]) ([10.236.193.131]) by fmsmga005.fm.intel.com with ESMTP; 13 Feb 2018 12:45:44 -0800 Subject: Re: [PATCH] lib/scatterlist: Make sg_page_count() accessible to other modules To: Andy Shevchenko Cc: chris@chris-wilson.co.uk, Linux Kernel Mailing List References: <1518285964-31657-1-git-send-email-alexey.skidanov@intel.com> From: Alexey Skidanov Message-ID: Date: Tue, 13 Feb 2018 22:46:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/13/2018 10:14 PM, Andy Shevchenko wrote: > On Sat, Feb 10, 2018 at 8:06 PM, Alexey Skidanov > wrote: >> Currently, sg_page_count() may be used only inside the scatterlist.c file. >> >> However, the same calculation is done outside of scatterlist.c file >> causing to code duplication. >> >> To fix this, we move the sg_page_count() to the scatterlist.h file, making it >> accessible to other modules. > > Can you provide an example of potential (or existing?) use case? > This one, for example - drivers/staging/android/ion/ion_heap.c: for_each_sg(table->sgl, sg, table->nents, i) { int npages_this_entry = PAGE_ALIGN(sg->length) / PAGE_SIZE; struct page *page = sg_page(sg); BUG_ON(i >= npages); for (j = 0; j < npages_this_entry; j++) *(tmp++) = page++; } One more is in the patch I have submitted for review. >> >> Signed-off-by: Alexey Skidanov >> --- >> include/linux/scatterlist.h | 5 +++++ >> lib/scatterlist.c | 5 ----- >> 2 files changed, 5 insertions(+), 5 deletions(-) >> >> diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h >> index b7c8325..fe28148 100644 >> --- a/include/linux/scatterlist.h >> +++ b/include/linux/scatterlist.h >> @@ -248,6 +248,11 @@ static inline void *sg_virt(struct scatterlist *sg) >> return page_address(sg_page(sg)) + sg->offset; >> } >> >> +static inline int sg_page_count(struct scatterlist *sg) >> +{ >> + return PAGE_ALIGN(sg->offset + sg->length) >> PAGE_SHIFT; >> +} >> + >> int sg_nents(struct scatterlist *sg); >> int sg_nents_for_len(struct scatterlist *sg, u64 len); >> struct scatterlist *sg_next(struct scatterlist *); >> diff --git a/lib/scatterlist.c b/lib/scatterlist.c >> index 7c1c55f..4a59131 100644 >> --- a/lib/scatterlist.c >> +++ b/lib/scatterlist.c >> @@ -486,11 +486,6 @@ void __sg_page_iter_start(struct sg_page_iter *piter, >> } >> EXPORT_SYMBOL(__sg_page_iter_start); >> >> -static int sg_page_count(struct scatterlist *sg) >> -{ >> - return PAGE_ALIGN(sg->offset + sg->length) >> PAGE_SHIFT; >> -} >> - >> bool __sg_page_iter_next(struct sg_page_iter *piter) >> { >> if (!piter->__nents || !piter->sg) >> -- >> 2.7.4 >> > > >