5
5
#include <linux/slab.h>
6
6
#include <linux/parser.h>
7
7
#include <linux/errno.h>
8
- #include <linux/unicode.h>
9
8
#include <linux/stringhash.h>
10
9
11
10
#include "utf8n.h"
12
11
13
12
int utf8_validate (const struct unicode_map * um , const struct qstr * str )
14
13
{
15
- const struct utf8data * data = utf8nfdi (um -> version );
16
-
17
- if (utf8nlen (data , str -> name , str -> len ) < 0 )
14
+ if (utf8nlen (um , UTF8_NFDI , str -> name , str -> len ) < 0 )
18
15
return -1 ;
19
16
return 0 ;
20
17
}
@@ -23,14 +20,13 @@ EXPORT_SYMBOL(utf8_validate);
23
20
int utf8_strncmp (const struct unicode_map * um ,
24
21
const struct qstr * s1 , const struct qstr * s2 )
25
22
{
26
- const struct utf8data * data = utf8nfdi (um -> version );
27
23
struct utf8cursor cur1 , cur2 ;
28
24
int c1 , c2 ;
29
25
30
- if (utf8ncursor (& cur1 , data , s1 -> name , s1 -> len ) < 0 )
26
+ if (utf8ncursor (& cur1 , um , UTF8_NFDI , s1 -> name , s1 -> len ) < 0 )
31
27
return - EINVAL ;
32
28
33
- if (utf8ncursor (& cur2 , data , s2 -> name , s2 -> len ) < 0 )
29
+ if (utf8ncursor (& cur2 , um , UTF8_NFDI , s2 -> name , s2 -> len ) < 0 )
34
30
return - EINVAL ;
35
31
36
32
do {
@@ -50,14 +46,13 @@ EXPORT_SYMBOL(utf8_strncmp);
50
46
int utf8_strncasecmp (const struct unicode_map * um ,
51
47
const struct qstr * s1 , const struct qstr * s2 )
52
48
{
53
- const struct utf8data * data = utf8nfdicf (um -> version );
54
49
struct utf8cursor cur1 , cur2 ;
55
50
int c1 , c2 ;
56
51
57
- if (utf8ncursor (& cur1 , data , s1 -> name , s1 -> len ) < 0 )
52
+ if (utf8ncursor (& cur1 , um , UTF8_NFDICF , s1 -> name , s1 -> len ) < 0 )
58
53
return - EINVAL ;
59
54
60
- if (utf8ncursor (& cur2 , data , s2 -> name , s2 -> len ) < 0 )
55
+ if (utf8ncursor (& cur2 , um , UTF8_NFDICF , s2 -> name , s2 -> len ) < 0 )
61
56
return - EINVAL ;
62
57
63
58
do {
@@ -81,12 +76,11 @@ int utf8_strncasecmp_folded(const struct unicode_map *um,
81
76
const struct qstr * cf ,
82
77
const struct qstr * s1 )
83
78
{
84
- const struct utf8data * data = utf8nfdicf (um -> version );
85
79
struct utf8cursor cur1 ;
86
80
int c1 , c2 ;
87
81
int i = 0 ;
88
82
89
- if (utf8ncursor (& cur1 , data , s1 -> name , s1 -> len ) < 0 )
83
+ if (utf8ncursor (& cur1 , um , UTF8_NFDICF , s1 -> name , s1 -> len ) < 0 )
90
84
return - EINVAL ;
91
85
92
86
do {
@@ -105,11 +99,10 @@ EXPORT_SYMBOL(utf8_strncasecmp_folded);
105
99
int utf8_casefold (const struct unicode_map * um , const struct qstr * str ,
106
100
unsigned char * dest , size_t dlen )
107
101
{
108
- const struct utf8data * data = utf8nfdicf (um -> version );
109
102
struct utf8cursor cur ;
110
103
size_t nlen = 0 ;
111
104
112
- if (utf8ncursor (& cur , data , str -> name , str -> len ) < 0 )
105
+ if (utf8ncursor (& cur , um , UTF8_NFDICF , str -> name , str -> len ) < 0 )
113
106
return - EINVAL ;
114
107
115
108
for (nlen = 0 ; nlen < dlen ; nlen ++ ) {
@@ -128,12 +121,11 @@ EXPORT_SYMBOL(utf8_casefold);
128
121
int utf8_casefold_hash (const struct unicode_map * um , const void * salt ,
129
122
struct qstr * str )
130
123
{
131
- const struct utf8data * data = utf8nfdicf (um -> version );
132
124
struct utf8cursor cur ;
133
125
int c ;
134
126
unsigned long hash = init_name_hash (salt );
135
127
136
- if (utf8ncursor (& cur , data , str -> name , str -> len ) < 0 )
128
+ if (utf8ncursor (& cur , um , UTF8_NFDICF , str -> name , str -> len ) < 0 )
137
129
return - EINVAL ;
138
130
139
131
while ((c = utf8byte (& cur ))) {
@@ -149,11 +141,10 @@ EXPORT_SYMBOL(utf8_casefold_hash);
149
141
int utf8_normalize (const struct unicode_map * um , const struct qstr * str ,
150
142
unsigned char * dest , size_t dlen )
151
143
{
152
- const struct utf8data * data = utf8nfdi (um -> version );
153
144
struct utf8cursor cur ;
154
145
ssize_t nlen = 0 ;
155
146
156
- if (utf8ncursor (& cur , data , str -> name , str -> len ) < 0 )
147
+ if (utf8ncursor (& cur , um , UTF8_NFDI , str -> name , str -> len ) < 0 )
157
148
return - EINVAL ;
158
149
159
150
for (nlen = 0 ; nlen < dlen ; nlen ++ ) {
@@ -180,7 +171,17 @@ struct unicode_map *utf8_load(unsigned int version)
180
171
if (!um )
181
172
return ERR_PTR (- ENOMEM );
182
173
um -> version = version ;
174
+ um -> ntab [UTF8_NFDI ] = utf8nfdi (version );
175
+ if (!um -> ntab [UTF8_NFDI ])
176
+ goto out_free_um ;
177
+ um -> ntab [UTF8_NFDICF ] = utf8nfdicf (version );
178
+ if (!um -> ntab [UTF8_NFDICF ])
179
+ goto out_free_um ;
183
180
return um ;
181
+
182
+ out_free_um :
183
+ kfree (um );
184
+ return ERR_PTR (- EINVAL );
184
185
}
185
186
EXPORT_SYMBOL (utf8_load );
186
187
0 commit comments