Skip to content

Commit f536808

Browse files
LiBaokun96tytso
authored andcommitted
ext4: refactor out ext4_generic_attr_store()
Refactor out the function ext4_generic_attr_store() to handle the setting of values of various common types, with no functional changes. Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20240319113325.3110393-3-libaokun1@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 9e8e819 commit f536808

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

fs/ext4/sysfs.c

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -443,24 +443,20 @@ static ssize_t ext4_attr_show(struct kobject *kobj,
443443
return 0;
444444
}
445445

446-
static ssize_t ext4_attr_store(struct kobject *kobj,
447-
struct attribute *attr,
448-
const char *buf, size_t len)
446+
static ssize_t ext4_generic_attr_store(struct ext4_attr *a,
447+
struct ext4_sb_info *sbi,
448+
const char *buf, size_t len)
449449
{
450-
struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
451-
s_kobj);
452-
struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
453-
void *ptr = calc_ptr(a, sbi);
450+
int ret;
454451
unsigned int t;
455452
unsigned long lt;
456-
int ret;
453+
void *ptr = calc_ptr(a, sbi);
454+
455+
if (!ptr)
456+
return 0;
457457

458458
switch (a->attr_id) {
459-
case attr_reserved_clusters:
460-
return reserved_clusters_store(sbi, buf, len);
461459
case attr_pointer_ui:
462-
if (!ptr)
463-
return 0;
464460
ret = kstrtouint(skip_spaces(buf), 0, &t);
465461
if (ret)
466462
return ret;
@@ -470,19 +466,33 @@ static ssize_t ext4_attr_store(struct kobject *kobj,
470466
*((unsigned int *) ptr) = t;
471467
return len;
472468
case attr_pointer_ul:
473-
if (!ptr)
474-
return 0;
475469
ret = kstrtoul(skip_spaces(buf), 0, &lt);
476470
if (ret)
477471
return ret;
478472
*((unsigned long *) ptr) = lt;
479473
return len;
474+
}
475+
return 0;
476+
}
477+
478+
static ssize_t ext4_attr_store(struct kobject *kobj,
479+
struct attribute *attr,
480+
const char *buf, size_t len)
481+
{
482+
struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
483+
s_kobj);
484+
struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
485+
486+
switch (a->attr_id) {
487+
case attr_reserved_clusters:
488+
return reserved_clusters_store(sbi, buf, len);
480489
case attr_inode_readahead:
481490
return inode_readahead_blks_store(sbi, buf, len);
482491
case attr_trigger_test_error:
483492
return trigger_test_error(sbi, buf, len);
493+
default:
494+
return ext4_generic_attr_store(a, sbi, buf, len);
484495
}
485-
return 0;
486496
}
487497

488498
static void ext4_sb_release(struct kobject *kobj)

0 commit comments

Comments
 (0)