Commit 4a90cb20 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Nicholas Bellinger

usb-gadget/f_mass_storage: use per-attribute show and store methods

To simplify the configfs interface and remove boilerplate code that also
causes binary bloat.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Acked-by: default avatarFelipe Balbi <balbi@ti.com>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 208e61ac
...@@ -3144,9 +3144,6 @@ static inline struct fsg_opts *to_fsg_opts(struct config_item *item) ...@@ -3144,9 +3144,6 @@ static inline struct fsg_opts *to_fsg_opts(struct config_item *item)
func_inst.group); func_inst.group);
} }
CONFIGFS_ATTR_STRUCT(fsg_lun_opts);
CONFIGFS_ATTR_OPS(fsg_lun_opts);
static void fsg_lun_attr_release(struct config_item *item) static void fsg_lun_attr_release(struct config_item *item)
{ {
struct fsg_lun_opts *lun_opts; struct fsg_lun_opts *lun_opts;
...@@ -3157,110 +3154,93 @@ static void fsg_lun_attr_release(struct config_item *item) ...@@ -3157,110 +3154,93 @@ static void fsg_lun_attr_release(struct config_item *item)
static struct configfs_item_operations fsg_lun_item_ops = { static struct configfs_item_operations fsg_lun_item_ops = {
.release = fsg_lun_attr_release, .release = fsg_lun_attr_release,
.show_attribute = fsg_lun_opts_attr_show,
.store_attribute = fsg_lun_opts_attr_store,
}; };
static ssize_t fsg_lun_opts_file_show(struct fsg_lun_opts *opts, char *page) static ssize_t fsg_lun_opts_file_show(struct config_item *item, char *page)
{ {
struct fsg_opts *fsg_opts; struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
return fsg_show_file(opts->lun, &fsg_opts->common->filesem, page); return fsg_show_file(opts->lun, &fsg_opts->common->filesem, page);
} }
static ssize_t fsg_lun_opts_file_store(struct fsg_lun_opts *opts, static ssize_t fsg_lun_opts_file_store(struct config_item *item,
const char *page, size_t len) const char *page, size_t len)
{ {
struct fsg_opts *fsg_opts; struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
return fsg_store_file(opts->lun, &fsg_opts->common->filesem, page, len); return fsg_store_file(opts->lun, &fsg_opts->common->filesem, page, len);
} }
static struct fsg_lun_opts_attribute fsg_lun_opts_file = CONFIGFS_ATTR(fsg_lun_opts_, file);
__CONFIGFS_ATTR(file, S_IRUGO | S_IWUSR, fsg_lun_opts_file_show,
fsg_lun_opts_file_store);
static ssize_t fsg_lun_opts_ro_show(struct fsg_lun_opts *opts, char *page) static ssize_t fsg_lun_opts_ro_show(struct config_item *item, char *page)
{ {
return fsg_show_ro(opts->lun, page); return fsg_show_ro(to_fsg_lun_opts(item)->lun, page);
} }
static ssize_t fsg_lun_opts_ro_store(struct fsg_lun_opts *opts, static ssize_t fsg_lun_opts_ro_store(struct config_item *item,
const char *page, size_t len) const char *page, size_t len)
{ {
struct fsg_opts *fsg_opts; struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
return fsg_store_ro(opts->lun, &fsg_opts->common->filesem, page, len); return fsg_store_ro(opts->lun, &fsg_opts->common->filesem, page, len);
} }
static struct fsg_lun_opts_attribute fsg_lun_opts_ro = CONFIGFS_ATTR(fsg_lun_opts_, ro);
__CONFIGFS_ATTR(ro, S_IRUGO | S_IWUSR, fsg_lun_opts_ro_show,
fsg_lun_opts_ro_store);
static ssize_t fsg_lun_opts_removable_show(struct fsg_lun_opts *opts, static ssize_t fsg_lun_opts_removable_show(struct config_item *item,
char *page) char *page)
{ {
return fsg_show_removable(opts->lun, page); return fsg_show_removable(to_fsg_lun_opts(item)->lun, page);
} }
static ssize_t fsg_lun_opts_removable_store(struct fsg_lun_opts *opts, static ssize_t fsg_lun_opts_removable_store(struct config_item *item,
const char *page, size_t len) const char *page, size_t len)
{ {
return fsg_store_removable(opts->lun, page, len); return fsg_store_removable(to_fsg_lun_opts(item)->lun, page, len);
} }
static struct fsg_lun_opts_attribute fsg_lun_opts_removable = CONFIGFS_ATTR(fsg_lun_opts_, removable);
__CONFIGFS_ATTR(removable, S_IRUGO | S_IWUSR,
fsg_lun_opts_removable_show,
fsg_lun_opts_removable_store);
static ssize_t fsg_lun_opts_cdrom_show(struct fsg_lun_opts *opts, char *page) static ssize_t fsg_lun_opts_cdrom_show(struct config_item *item, char *page)
{ {
return fsg_show_cdrom(opts->lun, page); return fsg_show_cdrom(to_fsg_lun_opts(item)->lun, page);
} }
static ssize_t fsg_lun_opts_cdrom_store(struct fsg_lun_opts *opts, static ssize_t fsg_lun_opts_cdrom_store(struct config_item *item,
const char *page, size_t len) const char *page, size_t len)
{ {
struct fsg_opts *fsg_opts; struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
return fsg_store_cdrom(opts->lun, &fsg_opts->common->filesem, page, return fsg_store_cdrom(opts->lun, &fsg_opts->common->filesem, page,
len); len);
} }
static struct fsg_lun_opts_attribute fsg_lun_opts_cdrom = CONFIGFS_ATTR(fsg_lun_opts_, cdrom);
__CONFIGFS_ATTR(cdrom, S_IRUGO | S_IWUSR, fsg_lun_opts_cdrom_show,
fsg_lun_opts_cdrom_store);
static ssize_t fsg_lun_opts_nofua_show(struct fsg_lun_opts *opts, char *page) static ssize_t fsg_lun_opts_nofua_show(struct config_item *item, char *page)
{ {
return fsg_show_nofua(opts->lun, page); return fsg_show_nofua(to_fsg_lun_opts(item)->lun, page);
} }
static ssize_t fsg_lun_opts_nofua_store(struct fsg_lun_opts *opts, static ssize_t fsg_lun_opts_nofua_store(struct config_item *item,
const char *page, size_t len) const char *page, size_t len)
{ {
return fsg_store_nofua(opts->lun, page, len); return fsg_store_nofua(to_fsg_lun_opts(item)->lun, page, len);
} }
static struct fsg_lun_opts_attribute fsg_lun_opts_nofua = CONFIGFS_ATTR(fsg_lun_opts_, nofua);
__CONFIGFS_ATTR(nofua, S_IRUGO | S_IWUSR, fsg_lun_opts_nofua_show,
fsg_lun_opts_nofua_store);
static struct configfs_attribute *fsg_lun_attrs[] = { static struct configfs_attribute *fsg_lun_attrs[] = {
&fsg_lun_opts_file.attr, &fsg_lun_opts_attr_file,
&fsg_lun_opts_ro.attr, &fsg_lun_opts_attr_ro,
&fsg_lun_opts_removable.attr, &fsg_lun_opts_attr_removable,
&fsg_lun_opts_cdrom.attr, &fsg_lun_opts_attr_cdrom,
&fsg_lun_opts_nofua.attr, &fsg_lun_opts_attr_nofua,
NULL, NULL,
}; };
...@@ -3352,9 +3332,6 @@ static void fsg_lun_drop(struct config_group *group, struct config_item *item) ...@@ -3352,9 +3332,6 @@ static void fsg_lun_drop(struct config_group *group, struct config_item *item)
config_item_put(item); config_item_put(item);
} }
CONFIGFS_ATTR_STRUCT(fsg_opts);
CONFIGFS_ATTR_OPS(fsg_opts);
static void fsg_attr_release(struct config_item *item) static void fsg_attr_release(struct config_item *item)
{ {
struct fsg_opts *opts = to_fsg_opts(item); struct fsg_opts *opts = to_fsg_opts(item);
...@@ -3364,12 +3341,11 @@ static void fsg_attr_release(struct config_item *item) ...@@ -3364,12 +3341,11 @@ static void fsg_attr_release(struct config_item *item)
static struct configfs_item_operations fsg_item_ops = { static struct configfs_item_operations fsg_item_ops = {
.release = fsg_attr_release, .release = fsg_attr_release,
.show_attribute = fsg_opts_attr_show,
.store_attribute = fsg_opts_attr_store,
}; };
static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page) static ssize_t fsg_opts_stall_show(struct config_item *item, char *page)
{ {
struct fsg_opts *opts = to_fsg_opts(item);
int result; int result;
mutex_lock(&opts->lock); mutex_lock(&opts->lock);
...@@ -3379,9 +3355,10 @@ static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page) ...@@ -3379,9 +3355,10 @@ static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page)
return result; return result;
} }
static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page, static ssize_t fsg_opts_stall_store(struct config_item *item, const char *page,
size_t len) size_t len)
{ {
struct fsg_opts *opts = to_fsg_opts(item);
int ret; int ret;
bool stall; bool stall;
...@@ -3403,13 +3380,12 @@ static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page, ...@@ -3403,13 +3380,12 @@ static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page,
return ret; return ret;
} }
static struct fsg_opts_attribute fsg_opts_stall = CONFIGFS_ATTR(fsg_opts_, stall);
__CONFIGFS_ATTR(stall, S_IRUGO | S_IWUSR, fsg_opts_stall_show,
fsg_opts_stall_store);
#ifdef CONFIG_USB_GADGET_DEBUG_FILES #ifdef CONFIG_USB_GADGET_DEBUG_FILES
static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page) static ssize_t fsg_opts_num_buffers_show(struct config_item *item, char *page)
{ {
struct fsg_opts *opts = to_fsg_opts(item);
int result; int result;
mutex_lock(&opts->lock); mutex_lock(&opts->lock);
...@@ -3419,9 +3395,10 @@ static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page) ...@@ -3419,9 +3395,10 @@ static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page)
return result; return result;
} }
static ssize_t fsg_opts_num_buffers_store(struct fsg_opts *opts, static ssize_t fsg_opts_num_buffers_store(struct config_item *item,
const char *page, size_t len) const char *page, size_t len)
{ {
struct fsg_opts *opts = to_fsg_opts(item);
int ret; int ret;
u8 num; u8 num;
...@@ -3446,17 +3423,13 @@ static ssize_t fsg_opts_num_buffers_store(struct fsg_opts *opts, ...@@ -3446,17 +3423,13 @@ static ssize_t fsg_opts_num_buffers_store(struct fsg_opts *opts,
return ret; return ret;
} }
static struct fsg_opts_attribute fsg_opts_num_buffers = CONFIGFS_ATTR(fsg_opts_, num_buffers);
__CONFIGFS_ATTR(num_buffers, S_IRUGO | S_IWUSR,
fsg_opts_num_buffers_show,
fsg_opts_num_buffers_store);
#endif #endif
static struct configfs_attribute *fsg_attrs[] = { static struct configfs_attribute *fsg_attrs[] = {
&fsg_opts_stall.attr, &fsg_opts_attr_stall,
#ifdef CONFIG_USB_GADGET_DEBUG_FILES #ifdef CONFIG_USB_GADGET_DEBUG_FILES
&fsg_opts_num_buffers.attr, &fsg_opts_attr_num_buffers,
#endif #endif
NULL, NULL,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment