aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/xattr.c
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruenba@redhat.com>2018-08-03 05:57:52 -0400
committerAndreas Gruenbacher <agruenba@redhat.com>2018-08-03 08:20:02 -0400
commit21e2156f3c4b2ad8b780a6d02342ca0e028a8acd (patch)
treeb7287ec9b1c692543139c7d61fad7dd0a77601f0 /fs/gfs2/xattr.c
parent3f30f929bb17877ebc1653c6f3ff41863f1ba524 (diff)
gfs2: Get rid of gfs2_ea_strlen
Function gfs2_ea_strlen is only called from ea_list_i, so inline it there. Remove the duplicate switch statement and the creative use of memcpy to set a null byte. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Reviewed-by: Andrew Price <anprice@redhat.com> Reviewed-by: Bob Peterson <rpeterso@redhat.com>
Diffstat (limited to 'fs/gfs2/xattr.c')
-rw-r--r--fs/gfs2/xattr.c59
1 files changed, 22 insertions, 37 deletions
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c
index f2bce1e0f6fb..38515988aaf7 100644
--- a/fs/gfs2/xattr.c
+++ b/fs/gfs2/xattr.c
@@ -343,60 +343,45 @@ struct ea_list {
343 unsigned int ei_size; 343 unsigned int ei_size;
344}; 344};
345 345
346static inline unsigned int gfs2_ea_strlen(struct gfs2_ea_header *ea)
347{
348 switch (ea->ea_type) {
349 case GFS2_EATYPE_USR:
350 return 5 + ea->ea_name_len + 1;
351 case GFS2_EATYPE_SYS:
352 return 7 + ea->ea_name_len + 1;
353 case GFS2_EATYPE_SECURITY:
354 return 9 + ea->ea_name_len + 1;
355 default:
356 return 0;
357 }
358}
359
360static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, 346static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh,
361 struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, 347 struct gfs2_ea_header *ea, struct gfs2_ea_header *prev,
362 void *private) 348 void *private)
363{ 349{
364 struct ea_list *ei = private; 350 struct ea_list *ei = private;
365 struct gfs2_ea_request *er = ei->ei_er; 351 struct gfs2_ea_request *er = ei->ei_er;
366 unsigned int ea_size = gfs2_ea_strlen(ea); 352 unsigned int ea_size;
353 char *prefix;
354 unsigned int l;
367 355
368 if (ea->ea_type == GFS2_EATYPE_UNUSED) 356 if (ea->ea_type == GFS2_EATYPE_UNUSED)
369 return 0; 357 return 0;
370 358
371 if (er->er_data_len) { 359 switch (ea->ea_type) {
372 char *prefix = NULL; 360 case GFS2_EATYPE_USR:
373 unsigned int l = 0; 361 prefix = "user.";
374 char c = 0; 362 l = 5;
363 break;
364 case GFS2_EATYPE_SYS:
365 prefix = "system.";
366 l = 7;
367 break;
368 case GFS2_EATYPE_SECURITY:
369 prefix = "security.";
370 l = 9;
371 break;
372 default:
373 BUG();
374 }
375 375
376 ea_size = l + ea->ea_name_len + 1;
377 if (er->er_data_len) {
376 if (ei->ei_size + ea_size > er->er_data_len) 378 if (ei->ei_size + ea_size > er->er_data_len)
377 return -ERANGE; 379 return -ERANGE;
378 380
379 switch (ea->ea_type) {
380 case GFS2_EATYPE_USR:
381 prefix = "user.";
382 l = 5;
383 break;
384 case GFS2_EATYPE_SYS:
385 prefix = "system.";
386 l = 7;
387 break;
388 case GFS2_EATYPE_SECURITY:
389 prefix = "security.";
390 l = 9;
391 break;
392 }
393
394 BUG_ON(l == 0);
395
396 memcpy(er->er_data + ei->ei_size, prefix, l); 381 memcpy(er->er_data + ei->ei_size, prefix, l);
397 memcpy(er->er_data + ei->ei_size + l, GFS2_EA2NAME(ea), 382 memcpy(er->er_data + ei->ei_size + l, GFS2_EA2NAME(ea),
398 ea->ea_name_len); 383 ea->ea_name_len);
399 memcpy(er->er_data + ei->ei_size + ea_size - 1, &c, 1); 384 er->er_data[ei->ei_size + ea_size - 1] = 0;
400 } 385 }
401 386
402 ei->ei_size += ea_size; 387 ei->ei_size += ea_size;