ibmvfc: Improve async event handling
[linux/fpc-iii.git] / arch / frv / kernel / uaccess.c
blob9fb771a20df3cf831f4779aba7859e4c865928de
1 /* uaccess.c: userspace access functions
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/mm.h>
13 #include <linux/module.h>
14 #include <asm/uaccess.h>
16 /*****************************************************************************/
18 * copy a null terminated string from userspace
20 long strncpy_from_user(char *dst, const char __user *src, long count)
22 unsigned long max;
23 char *p, ch;
24 long err = -EFAULT;
26 if (count < 0)
27 BUG();
29 p = dst;
31 #ifndef CONFIG_MMU
32 if ((unsigned long) src < memory_start)
33 goto error;
34 #endif
36 if ((unsigned long) src >= get_addr_limit())
37 goto error;
39 max = get_addr_limit() - (unsigned long) src;
40 if ((unsigned long) count > max) {
41 memset(dst + max, 0, count - max);
42 count = max;
45 err = 0;
46 for (; count > 0; count--, p++, src++) {
47 __get_user_asm(err, ch, src, "ub", "=r");
48 if (err < 0)
49 goto error;
50 if (!ch)
51 break;
52 *p = ch;
55 err = p - dst; /* return length excluding NUL */
57 error:
58 if (count > 0)
59 memset(p, 0, count); /* clear remainder of buffer [security] */
61 return err;
63 } /* end strncpy_from_user() */
65 EXPORT_SYMBOL(strncpy_from_user);
67 /*****************************************************************************/
69 * Return the size of a string (including the ending 0)
71 * Return 0 on exception, a value greater than N if too long
73 long strnlen_user(const char __user *src, long count)
75 const char __user *p;
76 long err = 0;
77 char ch;
79 if (count < 0)
80 BUG();
82 #ifndef CONFIG_MMU
83 if ((unsigned long) src < memory_start)
84 return 0;
85 #endif
87 if ((unsigned long) src >= get_addr_limit())
88 return 0;
90 for (p = src; count > 0; count--, p++) {
91 __get_user_asm(err, ch, p, "ub", "=r");
92 if (err < 0)
93 return 0;
94 if (!ch)
95 break;
98 return p - src + 1; /* return length including NUL */
100 } /* end strnlen_user() */
102 EXPORT_SYMBOL(strnlen_user);