All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/scatterlist: Make sg_page_count() accessible to other modules
@ 2018-02-10 18:06 Alexey Skidanov
  2018-02-13 20:14 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Skidanov @ 2018-02-10 18:06 UTC (permalink / raw)
  To: chris; +Cc: linux-kernel, Alexey Skidanov

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.

Signed-off-by: Alexey Skidanov <alexey.skidanov@intel.com>
---
 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] lib/scatterlist: Make sg_page_count() accessible to other modules
  2018-02-10 18:06 [PATCH] lib/scatterlist: Make sg_page_count() accessible to other modules Alexey Skidanov
@ 2018-02-13 20:14 ` Andy Shevchenko
  2018-02-13 20:46   ` Alexey Skidanov
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2018-02-13 20:14 UTC (permalink / raw)
  To: Alexey Skidanov; +Cc: chris, Linux Kernel Mailing List

On Sat, Feb 10, 2018 at 8:06 PM, Alexey Skidanov
<alexey.skidanov@intel.com> 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?

>
> Signed-off-by: Alexey Skidanov <alexey.skidanov@intel.com>
> ---
>  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
>



-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] lib/scatterlist: Make sg_page_count() accessible to other modules
  2018-02-13 20:14 ` Andy Shevchenko
@ 2018-02-13 20:46   ` Alexey Skidanov
  0 siblings, 0 replies; 3+ messages in thread
From: Alexey Skidanov @ 2018-02-13 20:46 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: chris, Linux Kernel Mailing List



On 02/13/2018 10:14 PM, Andy Shevchenko wrote:
> On Sat, Feb 10, 2018 at 8:06 PM, Alexey Skidanov
> <alexey.skidanov@intel.com> 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 <alexey.skidanov@intel.com>
>> ---
>>  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
>>
> 
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-13 20:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-10 18:06 [PATCH] lib/scatterlist: Make sg_page_count() accessible to other modules Alexey Skidanov
2018-02-13 20:14 ` Andy Shevchenko
2018-02-13 20:46   ` Alexey Skidanov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.