[PATCH 05/28] sunrpc: don't call flush_dcache_page() with NULL page pointer
Trond Myklebust
trond.myklebust at fys.uio.no
Mon Mar 31 17:05:49 EDT 2008
On Mon, 2008-03-31 at 16:10 -0400, J. Bruce Fields wrote:
> On Mon, Mar 31, 2008 at 10:31:18AM -0400, Kevin Coffman wrote:
> > For architectures that implement flush_dcache_page(), the struct
> > page pointer is not expected to be NULL. In _copy_to_pages(),
> > if the last bytes being copied are the exact last bytes of a
> > complete page, then the final call to flush_dcache_page() has
> > a null pointer. Skip the call in that case.
>
> A fix for this should actually go upstream now, right?
>
> >
> > Signed-off-by: Kevin Coffman <kwc at citi.umich.edu>
> > ---
> >
> > net/sunrpc/xdr.c | 3 ++-
> > 1 files changed, 2 insertions(+), 1 deletions(-)
> >
> > diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
> > index de2c986..26991c6 100644
> > --- a/net/sunrpc/xdr.c
> > +++ b/net/sunrpc/xdr.c
> > @@ -262,7 +262,8 @@ _copy_to_pages(struct page **pages, size_t pgbase, const char *p, size_t len)
> > p += copy;
> >
> > } while ((len -= copy) != 0);
> > - flush_dcache_page(*pgto);
> > + if (*pgto != NULL)
> > + flush_dcache_page(*pgto);
> > }
>
> Can you necessarily count on the next entry in the page array being NULL?
> Maybe better would be:
>
> if (pgbase != 0)
> flush_dcache_page(*pgto);
How about something like the following instead?
Cheers
Trond
------------------------------------------------
From: Trond Myklebust <Trond.Myklebust at netapp.com>
Date: Mon, 31 Mar 2008 17:02:02 -0400
SUNRPC: don't call flush_dcache_page() with an invalid pointer
Fix a problem in _copy_to_pages(), whereby it may call flush_dcache_page()
with an invalid pointer due to the fact that 'pgto' gets incremented
beyond the end of the page array. Fix is to exit the loop without this
unnecessary increment of pgto.
Signed-off-by: Trond Myklebust <Trond.Myklebust at netapp.com>
---
net/sunrpc/xdr.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index 995c3fd..79a55d5 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -244,7 +244,7 @@ _copy_to_pages(struct page **pages, size_t pgbase, const char *p, size_t len)
pgto = pages + (pgbase >> PAGE_CACHE_SHIFT);
pgbase &= ~PAGE_CACHE_MASK;
- do {
+ for (;;) {
copy = PAGE_CACHE_SIZE - pgbase;
if (copy > len)
copy = len;
@@ -253,6 +253,10 @@ _copy_to_pages(struct page **pages, size_t pgbase, const char *p, size_t len)
memcpy(vto + pgbase, p, copy);
kunmap_atomic(vto, KM_USER0);
+ len -= copy;
+ if (len == 0)
+ break;
+
pgbase += copy;
if (pgbase == PAGE_CACHE_SIZE) {
flush_dcache_page(*pgto);
@@ -260,8 +264,7 @@ _copy_to_pages(struct page **pages, size_t pgbase, const char *p, size_t len)
pgto++;
}
p += copy;
-
- } while ((len -= copy) != 0);
+ }
flush_dcache_page(*pgto);
}
More information about the NFSv4
mailing list