Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: scatterwalk - Use nth_page instead of doing it by hand

Curiously, the Crypto API scatterwalk incremented pages by hand
rather than using nth_page. Possibly because scatterwalk predates
nth_page (the following commit is from the history tree):

commit 3957f2b34960d85b63e814262a8be7d5ad91444d
Author: James Morris <jmorris@intercode.com.au>
Date: Sun Feb 2 07:35:32 2003 -0800

[CRYPTO]: in/out scatterlist support for ciphers.

Fix this by using nth_page.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+20 -10
+20 -10
include/crypto/scatterwalk.h
··· 100 100 static inline void scatterwalk_map(struct scatter_walk *walk) 101 101 { 102 102 struct page *base_page = sg_page(walk->sg); 103 + unsigned int offset = walk->offset; 104 + void *addr; 103 105 104 106 if (IS_ENABLED(CONFIG_HIGHMEM)) { 105 - walk->__addr = kmap_local_page(base_page + 106 - (walk->offset >> PAGE_SHIFT)) + 107 - offset_in_page(walk->offset); 107 + struct page *page; 108 + 109 + page = nth_page(base_page, offset >> PAGE_SHIFT); 110 + offset = offset_in_page(offset); 111 + addr = kmap_local_page(page) + offset; 108 112 } else { 109 113 /* 110 114 * When !HIGHMEM we allow the walker to return segments that ··· 121 117 * in the direct map, but this makes it clearer what is really 122 118 * going on. 123 119 */ 124 - walk->__addr = page_address(base_page) + walk->offset; 120 + addr = page_address(base_page) + offset; 125 121 } 122 + 123 + walk->__addr = addr; 126 124 } 127 125 128 126 /** ··· 195 189 * reliably optimized out or not. 196 190 */ 197 191 if (ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE) { 198 - struct page *base_page, *start_page, *end_page, *page; 192 + struct page *base_page; 193 + unsigned int offset; 194 + int start, end, i; 199 195 200 196 base_page = sg_page(walk->sg); 201 - start_page = base_page + (walk->offset >> PAGE_SHIFT); 202 - end_page = base_page + ((walk->offset + nbytes + 203 - PAGE_SIZE - 1) >> PAGE_SHIFT); 204 - for (page = start_page; page < end_page; page++) 205 - flush_dcache_page(page); 197 + offset = walk->offset; 198 + start = offset >> PAGE_SHIFT; 199 + end = start + (nbytes >> PAGE_SHIFT); 200 + end += (offset_in_page(offset) + offset_in_page(nbytes) + 201 + PAGE_SIZE - 1) >> PAGE_SHIFT; 202 + for (i = start; i < end; i++) 203 + flush_dcache_page(nth_page(base_page, i)); 206 204 } 207 205 scatterwalk_advance(walk, nbytes); 208 206 }