Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <asm/current.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <kern_util.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <os.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	pgd_t *pgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	p4d_t *p4d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	pud_t *pud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	pmd_t *pmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	if (mm == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	pgd = pgd_offset(mm, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	if (!pgd_present(*pgd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	p4d = p4d_offset(pgd, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (!p4d_present(*p4d))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	pud = pud_offset(p4d, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (!pud_present(*pud))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	pmd = pmd_offset(pud, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (!pmd_present(*pmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	return pte_offset_kernel(pmd, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static pte_t *maybe_map(unsigned long virt, int is_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	pte_t *pte = virt_to_pte(current->mm, virt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	int err, dummy_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if ((pte == NULL) || !pte_present(*pte) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	    (is_write && !pte_write(*pte))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		err = handle_page_fault(virt, 0, is_write, 1, &dummy_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		pte = virt_to_pte(current->mm, virt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (!pte_present(*pte))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		pte = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static int do_op_one_page(unsigned long addr, int len, int is_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		 int (*op)(unsigned long addr, int len, void *arg), void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	pte_t *pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	pte = maybe_map(addr, is_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (pte == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	page = pte_page(*pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	pagefault_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	addr = (unsigned long) page_address(page) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		(addr & ~PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	addr = (unsigned long) kmap_atomic(page) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		(addr & ~PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	n = (*op)(addr, len, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	pagefault_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	kunmap_atomic((void *)addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static long buffer_op(unsigned long addr, int len, int is_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		      int (*op)(unsigned long, int, void *), void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	long size, remain, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	size = min(PAGE_ALIGN(addr) - addr, (unsigned long) len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	remain = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	n = do_op_one_page(addr, size, is_write, op, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (n != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		remain = (n < 0 ? remain : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	addr += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	remain -= size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (remain == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	while (addr < ((addr + remain) & PAGE_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		n = do_op_one_page(addr, PAGE_SIZE, is_write, op, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		if (n != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			remain = (n < 0 ? remain : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		addr += PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		remain -= PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (remain == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	n = do_op_one_page(addr, remain, is_write, op, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (n != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		remain = (n < 0 ? remain : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	return remain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static int copy_chunk_from_user(unsigned long from, int len, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	unsigned long *to_ptr = arg, to = *to_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	memcpy((void *) to, (void *) from, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	*to_ptr += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (uaccess_kernel()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		memcpy(to, (__force void*)from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	return buffer_op((unsigned long) from, n, 0, copy_chunk_from_user, &to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) EXPORT_SYMBOL(raw_copy_from_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int copy_chunk_to_user(unsigned long to, int len, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	unsigned long *from_ptr = arg, from = *from_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	memcpy((void *) to, (void *) from, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	*from_ptr += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (uaccess_kernel()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		memcpy((__force void *) to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	return buffer_op((unsigned long) to, n, 1, copy_chunk_to_user, &from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) EXPORT_SYMBOL(raw_copy_to_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int strncpy_chunk_from_user(unsigned long from, int len, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	char **to_ptr = arg, *to = *to_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	strncpy(to, (void *) from, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	n = strnlen(to, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	*to_ptr += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (n < len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	        return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) long __strncpy_from_user(char *dst, const char __user *src, long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	char *ptr = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (uaccess_kernel()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		strncpy(dst, (__force void *) src, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		return strnlen(dst, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	n = buffer_op((unsigned long) src, count, 0, strncpy_chunk_from_user,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		      &ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (n != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	return strnlen(dst, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) EXPORT_SYMBOL(__strncpy_from_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int clear_chunk(unsigned long addr, int len, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	memset((void *) addr, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) unsigned long __clear_user(void __user *mem, unsigned long len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (uaccess_kernel()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		memset((__force void*)mem, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return buffer_op((unsigned long) mem, len, 1, clear_chunk, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) EXPORT_SYMBOL(__clear_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static int strnlen_chunk(unsigned long str, int len, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	int *len_ptr = arg, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	n = strnlen((void *) str, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	*len_ptr += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (n < len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) long __strnlen_user(const void __user *str, long len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	int count = 0, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (uaccess_kernel())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return strnlen((__force char*)str, len) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	n = buffer_op((unsigned long) str, len, 0, strnlen_chunk, &count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		return count + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) EXPORT_SYMBOL(__strnlen_user);