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 <[EMAIL PROTECTED]> http://clemens.endorphin.org
signature.asc
Description: This is a digitally signed message part