lkml.org 
[lkml]   [2021]   [Nov]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 1/2] erofs: add sysfs interface
From
Date
On Tue, 2021-11-09 at 10:54 +0800, Huang Jianan wrote:
> Add sysfs interface to configure erofs related parameters in the
> future.
[]
> diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
[]
> +static ssize_t erofs_attr_show(struct kobject *kobj,
> + struct attribute *attr, char *buf)
> +{
> + struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
> + s_kobj);
> + struct erofs_attr *a = container_of(attr, struct erofs_attr, attr);
> + unsigned char *ptr = __struct_ptr(sbi, a->struct_type, a->offset);
> +
> + switch (a->attr_id) {
> + case attr_feature:
> + return snprintf(buf, PAGE_SIZE, "supported\n");
> + case attr_pointer_ui:
> + if (!ptr)
> + return 0;
> + return snprintf(buf, PAGE_SIZE, "%u\n",
> + *((unsigned int *) ptr));

Prefer sysfs_emit over snprintf

case attr_feature:
return sysfs_emit(buf, "supported\n");
case attr_pointer_ui:
...
return sysfs_emit(buf, "%u\n", *(unsigned int *)ptr);

etc...


\
 
 \ /
  Last update: 2021-11-09 04:15    [W:0.110 / U:0.548 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site