@@ -48,7 +48,7 @@ EXPORT_SYMBOL(lookup_constant);
48
48
49
49
static inline bool is_flag (const struct fs_parameter_spec * p )
50
50
{
51
- return p -> type == fs_param_is_flag ;
51
+ return p -> type == NULL ;
52
52
}
53
53
54
54
static const struct fs_parameter_spec * fs_lookup_key (
@@ -106,8 +106,6 @@ int __fs_parse(struct p_log *log,
106
106
struct fs_parse_result * result )
107
107
{
108
108
const struct fs_parameter_spec * p ;
109
- const struct constant_table * e ;
110
- int ret = - ENOPARAM , b ;
111
109
112
110
result -> uint_64 = 0 ;
113
111
@@ -121,96 +119,17 @@ int __fs_parse(struct p_log *log,
121
119
/* Try to turn the type we were given into the type desired by the
122
120
* parameter and give an error if we can't.
123
121
*/
124
- switch (p -> type ) {
125
- case __fs_param_wasnt_defined :
126
- return - EINVAL ;
127
- case fs_param_is_flag :
122
+ if (is_flag (p )) {
128
123
if (param -> type != fs_value_is_flag )
129
124
return inval_plog (log , "Unexpected value for '%s'" ,
130
125
param -> key );
131
126
result -> boolean = !result -> negated ;
132
- goto okay ;
133
- case fs_param_is_bool :
134
- if (param -> type != fs_value_is_string )
135
- goto bad_value ;
136
- b = lookup_constant (bool_names , param -> string , -1 );
137
- if (b == -1 )
138
- goto bad_value ;
139
- result -> boolean = b ;
140
- goto okay ;
141
- case fs_param_is_u32 :
142
- if (param -> type != fs_value_is_string )
143
- goto bad_value ;
144
- ret = kstrtouint (param -> string , 0 , & result -> uint_32 );
145
- goto maybe_okay ;
146
- case fs_param_is_u32_octal :
147
- if (param -> type != fs_value_is_string )
148
- goto bad_value ;
149
- ret = kstrtouint (param -> string , 8 , & result -> uint_32 );
150
- goto maybe_okay ;
151
- case fs_param_is_u32_hex :
152
- if (param -> type != fs_value_is_string )
153
- goto bad_value ;
154
- ret = kstrtouint (param -> string , 16 , & result -> uint_32 );
155
- goto maybe_okay ;
156
- case fs_param_is_s32 :
157
- if (param -> type != fs_value_is_string )
158
- goto bad_value ;
159
- ret = kstrtoint (param -> string , 0 , & result -> int_32 );
160
- goto maybe_okay ;
161
- case fs_param_is_u64 :
162
- if (param -> type != fs_value_is_string )
163
- goto bad_value ;
164
- ret = kstrtoull (param -> string , 0 , & result -> uint_64 );
165
- goto maybe_okay ;
166
- case fs_param_is_enum :
167
- if (param -> type != fs_value_is_string )
168
- goto bad_value ;
169
- e = __lookup_constant (p -> data , param -> string );
170
- if (e ) {
171
- result -> uint_32 = e -> value ;
172
- goto okay ;
173
- }
174
- goto bad_value ;
175
- case fs_param_is_string :
176
- if (param -> type != fs_value_is_string || !* param -> string )
177
- goto bad_value ;
178
- goto okay ;
179
- case fs_param_is_blob :
180
- if (param -> type != fs_value_is_blob )
181
- goto bad_value ;
182
- goto okay ;
183
- case fs_param_is_fd : {
184
- switch (param -> type ) {
185
- case fs_value_is_string :
186
- ret = kstrtouint (param -> string , 0 , & result -> uint_32 );
187
- break ;
188
- case fs_value_is_file :
189
- result -> uint_32 = param -> dirfd ;
190
- ret = 0 ;
191
- default :
192
- goto bad_value ;
193
- }
194
-
195
- if (result -> uint_32 > INT_MAX )
196
- goto bad_value ;
197
- goto maybe_okay ;
127
+ } else {
128
+ int ret = p -> type (log , p , param , result );
129
+ if (ret )
130
+ return ret ;
198
131
}
199
- case fs_param_is_blockdev :
200
- case fs_param_is_path :
201
- goto okay ;
202
- default :
203
- BUG ();
204
- }
205
-
206
- maybe_okay :
207
- if (ret < 0 )
208
- goto bad_value ;
209
- okay :
210
132
return p -> opt ;
211
-
212
- bad_value :
213
- return inval_plog (log , "Bad value for '%s'" , param -> key );
214
133
}
215
134
EXPORT_SYMBOL (__fs_parse );
216
135
@@ -270,6 +189,124 @@ int fs_lookup_param(struct fs_context *fc,
270
189
}
271
190
EXPORT_SYMBOL (fs_lookup_param );
272
191
192
+ int fs_param_bad_value (struct p_log * log , struct fs_parameter * param )
193
+ {
194
+ return inval_plog (log , "Bad value for '%s'" , param -> key );
195
+ }
196
+
197
+ int fs_param_is_bool (struct p_log * log , const struct fs_parameter_spec * p ,
198
+ struct fs_parameter * param , struct fs_parse_result * result )
199
+ {
200
+ int b ;
201
+ if (param -> type != fs_value_is_string )
202
+ return fs_param_bad_value (log , param );
203
+ b = lookup_constant (bool_names , param -> string , -1 );
204
+ if (b == -1 )
205
+ return fs_param_bad_value (log , param );
206
+ result -> boolean = b ;
207
+ return 0 ;
208
+ }
209
+ EXPORT_SYMBOL (fs_param_is_bool );
210
+
211
+ int fs_param_is_u32 (struct p_log * log , const struct fs_parameter_spec * p ,
212
+ struct fs_parameter * param , struct fs_parse_result * result )
213
+ {
214
+ int base = (unsigned long )p -> data ;
215
+ if (param -> type != fs_value_is_string ||
216
+ kstrtouint (param -> string , base , & result -> uint_32 ) < 0 )
217
+ return fs_param_bad_value (log , param );
218
+ return 0 ;
219
+ }
220
+ EXPORT_SYMBOL (fs_param_is_u32 );
221
+
222
+ int fs_param_is_s32 (struct p_log * log , const struct fs_parameter_spec * p ,
223
+ struct fs_parameter * param , struct fs_parse_result * result )
224
+ {
225
+ if (param -> type != fs_value_is_string ||
226
+ kstrtoint (param -> string , 0 , & result -> int_32 ) < 0 )
227
+ return fs_param_bad_value (log , param );
228
+ return 0 ;
229
+ }
230
+ EXPORT_SYMBOL (fs_param_is_s32 );
231
+
232
+ int fs_param_is_u64 (struct p_log * log , const struct fs_parameter_spec * p ,
233
+ struct fs_parameter * param , struct fs_parse_result * result )
234
+ {
235
+ if (param -> type != fs_value_is_string ||
236
+ kstrtoull (param -> string , 0 , & result -> uint_64 ) < 0 )
237
+ return fs_param_bad_value (log , param );
238
+ return 0 ;
239
+ }
240
+ EXPORT_SYMBOL (fs_param_is_u64 );
241
+
242
+ int fs_param_is_enum (struct p_log * log , const struct fs_parameter_spec * p ,
243
+ struct fs_parameter * param , struct fs_parse_result * result )
244
+ {
245
+ const struct constant_table * c ;
246
+ if (param -> type != fs_value_is_string )
247
+ return fs_param_bad_value (log , param );
248
+ c = __lookup_constant (p -> data , param -> string );
249
+ if (!c )
250
+ return fs_param_bad_value (log , param );
251
+ result -> uint_32 = c -> value ;
252
+ return 0 ;
253
+ }
254
+ EXPORT_SYMBOL (fs_param_is_enum );
255
+
256
+ int fs_param_is_string (struct p_log * log , const struct fs_parameter_spec * p ,
257
+ struct fs_parameter * param , struct fs_parse_result * result )
258
+ {
259
+ if (param -> type != fs_value_is_string || !* param -> string )
260
+ return fs_param_bad_value (log , param );
261
+ return 0 ;
262
+ }
263
+ EXPORT_SYMBOL (fs_param_is_string );
264
+
265
+ int fs_param_is_blob (struct p_log * log , const struct fs_parameter_spec * p ,
266
+ struct fs_parameter * param , struct fs_parse_result * result )
267
+ {
268
+ if (param -> type != fs_value_is_blob )
269
+ return fs_param_bad_value (log , param );
270
+ return 0 ;
271
+ }
272
+ EXPORT_SYMBOL (fs_param_is_blob );
273
+
274
+ int fs_param_is_fd (struct p_log * log , const struct fs_parameter_spec * p ,
275
+ struct fs_parameter * param , struct fs_parse_result * result )
276
+ {
277
+ switch (param -> type ) {
278
+ case fs_value_is_string :
279
+ if (kstrtouint (param -> string , 0 , & result -> uint_32 ) < 0 )
280
+ break ;
281
+ if (result -> uint_32 <= INT_MAX )
282
+ return 0 ;
283
+ break ;
284
+ case fs_value_is_file :
285
+ result -> uint_32 = param -> dirfd ;
286
+ if (result -> uint_32 <= INT_MAX )
287
+ return 0 ;
288
+ break ;
289
+ default :
290
+ break ;
291
+ }
292
+ return fs_param_bad_value (log , param );
293
+ }
294
+ EXPORT_SYMBOL (fs_param_is_fd );
295
+
296
+ int fs_param_is_blockdev (struct p_log * log , const struct fs_parameter_spec * p ,
297
+ struct fs_parameter * param , struct fs_parse_result * result )
298
+ {
299
+ return 0 ;
300
+ }
301
+ EXPORT_SYMBOL (fs_param_is_blockdev );
302
+
303
+ int fs_param_is_path (struct p_log * log , const struct fs_parameter_spec * p ,
304
+ struct fs_parameter * param , struct fs_parse_result * result )
305
+ {
306
+ return 0 ;
307
+ }
308
+ EXPORT_SYMBOL (fs_param_is_path );
309
+
273
310
#ifdef CONFIG_VALIDATE_FS_PARSER
274
311
/**
275
312
* validate_constant_table - Validate a constant table
@@ -334,23 +371,6 @@ bool fs_validate_description(const char *name,
334
371
pr_notice ("*** VALIDATE %s ***\n" , name );
335
372
336
373
for (param = desc ; param -> name ; param ++ ) {
337
- enum fs_parameter_type t = param -> type ;
338
-
339
- /* Check that the type is in range */
340
- if (t == __fs_param_wasnt_defined ||
341
- t >= nr__fs_parameter_type ) {
342
- pr_err ("VALIDATE %s: PARAM[%s] Bad type %u\n" ,
343
- name , param -> name , t );
344
- good = false;
345
- } else if (t == fs_param_is_enum ) {
346
- const struct constant_table * e = param -> data ;
347
- if (!e || !e -> name ) {
348
- pr_err ("VALIDATE %s: PARAM[%s] enum with no values\n" ,
349
- name , param -> name );
350
- good = false;
351
- }
352
- }
353
-
354
374
/* Check for duplicate parameter names */
355
375
for (p2 = desc ; p2 < param ; p2 ++ ) {
356
376
if (strcmp (param -> name , p2 -> name ) == 0 ) {
0 commit comments