Skip to content

Commit 35fb9ae

Browse files
Matthew Wilcox (Oracle)kees
authored andcommitted
usercopy: Cast pointer to an integer once
Get rid of a lot of annoying casts by setting 'addr' once at the top of the function. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Uladzislau Rezki (Sony) <[email protected]> Tested-by: Zorro Lang <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 993d0b2 commit 35fb9ae

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

mm/usercopy.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,27 @@ static inline void check_bogus_address(const unsigned long ptr, unsigned long n,
161161
static inline void check_heap_object(const void *ptr, unsigned long n,
162162
bool to_user)
163163
{
164+
uintptr_t addr = (uintptr_t)ptr;
164165
struct folio *folio;
165166

166167
if (is_kmap_addr(ptr)) {
167-
unsigned long page_end = (unsigned long)ptr | (PAGE_SIZE - 1);
168+
unsigned long page_end = addr | (PAGE_SIZE - 1);
168169

169-
if ((unsigned long)ptr + n - 1 > page_end)
170+
if (addr + n - 1 > page_end)
170171
usercopy_abort("kmap", NULL, to_user,
171172
offset_in_page(ptr), n);
172173
return;
173174
}
174175

175176
if (is_vmalloc_addr(ptr)) {
176-
struct vmap_area *area = find_vmap_area((unsigned long)ptr);
177+
struct vmap_area *area = find_vmap_area(addr);
177178
unsigned long offset;
178179

179180
if (!area)
180181
usercopy_abort("vmalloc", "no area", to_user, 0, n);
181182

182-
offset = (unsigned long)ptr - area->va_start;
183-
if ((unsigned long)ptr + n > area->va_end)
183+
offset = addr - area->va_start;
184+
if (addr + n > area->va_end)
184185
usercopy_abort("vmalloc", NULL, to_user, offset, n);
185186
return;
186187
}

0 commit comments

Comments
 (0)