lkml.org 
[lkml]   [2005]   [Feb]   [3]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 01/04] Adding cipher mode context information to crypto_tfm
FromFruhwirth Clemens <>
DateThu, 03 Feb 2005 12:47:41 +0100
On Wed, 2005-02-02 at 17:46 -0500, James Morris wrote:
> On Sun, 30 Jan 2005, Fruhwirth Clemens wrote:

> > +#define scatterwalk_needscratch(walk, nbytes) 						\
> > +	((nbytes) <= (walk)->len_this_page &&						\
> > +	    (((unsigned long)(walk)->data) & (PAGE_CACHE_SIZE - 1)) + (nbytes) <=	\
> > +	    PAGE_CACHE_SIZE)								\
> 
> This should be a static inline.

First attempt:

static inline int scatterwalk_needscratch(struct scatter_walk *walk, int
nbytes) {
       return ((nbytes) <= (walk)->len_this_page &&
               (((unsigned long)(walk)->data) & (PAGE_CACHE_SIZE - 1)) +
(nbytes) <= PAGE_CACHE_SIZE);
}
While trying to improve this unreadable monster I noticed, that 
(((unsigned long)(walk)->data) & (PAGE_CACHE_SIZE - 1)) is always equal
to walk->offset. walk->data and walk->offset always grows together (see
scatterwalk_copychunks), and when the bitwise AND-ing of walk->data with
PAGE_CACHE_SIZE-1 would result walk->offset to be zero, in just that
moment, walk->offset is set zero (see scatterwalk_pagedone). So, better:

static inline int scatterwalk_needscratch(struct scatter_walk *walk, int
nbytes) 
{
	return (nbytes <= walk->len_this_page &&
		(nbytes + walk->offset) <= PAGE_CACHE_SIZE);
}
Looks nicer, right? But in fact, it's redundant. walk->offset is never
intended to grow bigger than PAGE_CACHE_SIZE, and further it's illegal
to hand cryptoapi a scatterlist, where sg->offset is greater than
PAGE_CACHE_SIZE (I presume this from the calculations in
scatterwalk_start). Are these two conclusions correct, James? 

If so, I can drop the redundant expression, and probably drop the entire
function, as it becomes trivial then. Dropping the check shows no
regressions btw.
-- 
Fruhwirth Clemens <clemens@endorphin.org>  http://clemens.endorphin.org
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2005-03-22 14:10    [from the cache]
©2003-2008