simplify configfs attributes
Subsystems (20)
This series consolidates the code to implement configfs attributes by providing the ->show and ->store method in common code and using container_of in the methods to access the containing structure.
This reduces source and binary size of configfs consumers a lot.
PATCH 1/23 configfs: add show and store methods to struct configfs_attribute
Add methods to struct configfs_attribute to directly show and store attributes without adding boilerplate code to every user. In addition to the methods this also adds 3 helper macros to define read/write, read-only and write-only attributes with a single line of code.
--- fs/configfs/file.c | 17 ++++++++++++----- include/linux/configfs.h | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-)
fs/configfs/file.c +12 -5
@@ -74,7 +74,11 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * bufif (!buffer->page)return -ENOMEM ; - count = ops->show_attribute (item,attr,buffer->page); +if (ops->show_attribute) + count = ops->show_attribute (item, attr, buffer->page); +else + count = attr->show (item, buffer->page); + buffer->needs_read_fill =0 ;BUG_ON (count > (ssize_t )SIMPLE_ATTR_SIZE );if (count >=0 )
@@ -173,7 +177,9 @@ flush_write_buffer(struct dentry * dentry, struct configfs_buffer * buffer, sizestruct config_item * item =to_item (dentry->d_parent);struct configfs_item_operations * ops = buffer->ops; -return ops->store_attribute (item,attr,buffer->page,count); +if (ops->store_attribute) +return ops->store_attribute (item, attr, buffer->page, count); +return attr->store (item, buffer->page, count); }
@@ -237,8 +243,8 @@ static int check_perm(struct inode * inode, struct file * file)* and we must have a store method. */ if (file->f_mode &FMODE_WRITE ) { - -if (!(inode->i_mode &S_IWUGO ) || !ops->store_attribute) +if (!(inode->i_mode &S_IWUGO ) || + (!ops->store_attribute && !attr->store)) goto Eaccess; }
@@ -248,7 +254,8 @@ static int check_perm(struct inode * inode, struct file * file)* must be a show method for it. */ if (file->f_mode &FMODE_READ ) { -if (!(inode->i_mode &S_IRUGO ) || !ops->show_attribute) +if (!(inode->i_mode &S_IRUGO ) || + (!ops->show_attribute && !attr->show)) goto Eaccess; }
include/linux/configfs.h +27 -0
@@ -125,8 +125,35 @@ struct configfs_attribute {const char *ca_name;struct module *ca_owner;umode_t ca_mode; +ssize_t (*show)(struct config_item *,char *); +ssize_t (*store)(struct config_item *,const char *,size_t ); }; +#define CONFIGFS_ATTR (_pfx, _name) \ +static struct configfs_attribute _pfx##attr_##_name = { \ + .ca_name = __stringify(_name), \ + .ca_mode = S_IRUGO | S_IWUSR, \ + .ca_owner = THIS_MODULE, \ + .show = _pfx##_name##_show, \ + .store = _pfx##_name##_store, \ +} + +#define CONFIGFS_ATTR_RO (_pfx, _name) \ +static struct configfs_attribute _pfx##attr_##_name = { \ + .ca_name = __stringify(_name), \ + .ca_mode = S_IRUGO, \ + .ca_owner = THIS_MODULE, \ + .show = _pfx##_name##_show, \ +} + +#define CONFIGFS_ATTR_WO (_pfx, _name) \ +static struct configfs_attribute _pfx##attr_##_name = { \ + .ca_name = __stringify(_name), \ + .ca_mode = S_IWUSR, \ + .ca_owner = THIS_MODULE, \ + .store = _pfx##_name##_store, \ +} +/* * Users often need to create attribute structures for their configurable * attributes, containing a configfs_attribute member and function pointers
Signature · 1 line
1.9.1
Re: [PATCH 01/23] configfs: add show and store methods to struct configfs_attribute
Hello, Christoph.
Quoted 4 lines · Christoph Hellwig
Add methods to struct
configfs_attributeto directly show and store attributes without adding boilerplate code to every user. In addition to the methods this also adds 3 helper macros to define read/write, read-only and write-only attributes with a single line of code.
This looks great to me. It doesn't look like the whole attribute thing played out as hoped. It'd be great if we can move away from it.
Thanks a lot for the work!
Signature · 1 line
tejun
Re: [PATCH 01/23] configfs: add show and store methods to struct configfs_attribute
Quoted 8 lines · Tejun Heo
Hello, Christoph.
Quoted 4 lines · Christoph Hellwig
Add methods to struct
configfs_attributeto directly show and store attributes without adding boilerplate code to every user. In addition to the methods this also adds 3 helper macros to define read/write, read-only and write-only attributes with a single line of code.
Quoted 4 lines
This looks great to me. It doesn't look like the whole attribute thing played out as hoped. It'd be great if we can move away from it.
Thanks a lot for the work!
Looks good to me as well, no objection from my side for the USB or core configfs stuff:
Re: [PATCH 01/23] configfs: add show and store methods to struct configfs_attribute
In reply to Christoph HellwigQuoted 11 lines · Christoph Hellwig
Add methods to struct
configfs_attributeto directly show and store attributes without adding boilerplate code to every user. In addition to the methods this also adds 3 helper macros to define read/write, read-only and write-only attributes with a single line of code.Signed-off-by Christoph Hellwig <[email protected]>--- fs/configfs/file.c | 17 ++++++++++++----- include/linux/configfs.h | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-)
PATCH 2/23 usb-gadget: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/configfs.c | 295 ++++++++++++++---------------------- include/linux/usb/gadget_configfs.h | 19 +-- 2 files changed, 118 insertions(+), 196 deletions(-)
drivers/usb/gadget/configfs.c +113 -182
@@ -64,6 +64,11 @@ struct gadget_info {char qw_sign[OS_STRING_QW_SIGN_LEN ]; }; +static inline struct gadget_info *to_gadget_info (struct config_item *item) +{ + return container_of(to_config_group(item), struct gadget_info, group); +} +struct config_usb_cfg {struct config_group group;struct config_group strings_group;
@@ -74,6 +79,12 @@ struct config_usb_cfg {struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS +1 ]; }; +static inline struct config_usb_cfg *to_config_usb_cfg (struct config_item *item) +{ + return container_of(to_config_group(item), struct config_usb_cfg, + group); +} +struct gadget_strings {struct usb_gadget_strings stringtab_dev;struct usb_string strings[USB_GADGET_FIRST_AVAIL_IDX ];
@@ -117,32 +128,25 @@ static int usb_string_copy(const char *s, char **s_copy)return 0 ; } -CONFIGFS_ATTR_STRUCT (gadget_info); -CONFIGFS_ATTR_STRUCT (config_usb_cfg); - -#define GI_DEVICE_DESC_ITEM_ATTR (name) \ - static struct gadget_info_attribute gadget_cdev_desc_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - gadget_dev_desc_##name##_show, \ - gadget_dev_desc_##name##_store) -#define GI_DEVICE_DESC_SIMPLE_R_u8 (__name) \ - static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \ +static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \ char *page) \ { \ - return sprintf(page, "0x%02x\n", gi->cdev.desc.__name); \ + return sprintf(page, "0x%02x\n", \ + to_gadget_info(item)->cdev.desc.__name); \ }#define GI_DEVICE_DESC_SIMPLE_R_u16 (__name) \ - static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \ +static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \ char *page) \ { \ - return sprintf(page, "0x%04x\n", le16_to_cpup(&gi->cdev.desc.__name)); \ + return sprintf(page, "0x%04x\n", \ + le16_to_cpup(&to_gadget_info(item)->cdev.desc.__name)); \ }#define GI_DEVICE_DESC_SIMPLE_W_u8 (_name) \ - static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \ +static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ u8 val; \
@@ -150,12 +154,12 @@ CONFIGFS_ATTR_STRUCT(config_usb_cfg); ret =kstrtou8 (page,0 , &val); \if (ret) \return ret; \ - gi->cdev.desc._name = val; \ +to_gadget_info (item)->cdev.desc._name = val; \return len; \ }#define GI_DEVICE_DESC_SIMPLE_W_u16 (_name) \ - static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \ +static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ u16 val; \
@@ -163,7 +167,7 @@ CONFIGFS_ATTR_STRUCT(config_usb_cfg); ret =kstrtou16 (page,0 , &val); \if (ret) \return ret; \ - gi->cdev.desc._name =cpu_to_le16p (&val); \ +to_gadget_info (item)->cdev.desc._name =cpu_to_le16p (&val); \return len; \ }
@@ -193,7 +197,7 @@ static ssize_t is_valid_bcd(u16 bcd_val)return 0 ; } -static ssize_t gadget_dev_desc_bcdDevice_store (struct gadget_info *gi, +static ssize_t gadget_dev_desc_bcdDevice_store (struct config_item *item,const char *page,size_t len) {u16 bcdDevice;
@@ -206,11 +210,11 @@ static ssize_t gadget_dev_desc_bcdDevice_store(struct gadget_info *gi,if (ret)return ret; - gi->cdev.desc.bcdDevice =cpu_to_le16 (bcdDevice); +to_gadget_info (item)->cdev.desc.bcdDevice =cpu_to_le16 (bcdDevice);return len; } -static ssize_t gadget_dev_desc_bcdUSB_store (struct gadget_info *gi, +static ssize_t gadget_dev_desc_bcdUSB_store (struct config_item *item,const char *page,size_t len) {u16 bcdUSB;
@@ -223,13 +227,13 @@ static ssize_t gadget_dev_desc_bcdUSB_store(struct gadget_info *gi,if (ret)return ret; - gi->cdev.desc.bcdUSB =cpu_to_le16 (bcdUSB); +to_gadget_info (item)->cdev.desc.bcdUSB =cpu_to_le16 (bcdUSB);return len; } -static ssize_t gadget_dev_desc_UDC_show (struct gadget_info *gi,char *page) +static ssize_t gadget_dev_desc_UDC_show (struct config_item *item,char *page) { -return sprintf (page,"%s\n" , gi->udc_name ?:"" ); +return sprintf (page,"%s\n" ,to_gadget_info (item)->udc_name ?:"" ); }static int unregister_gadget (struct gadget_info *gi)
@@ -247,9 +251,10 @@ static int unregister_gadget(struct gadget_info *gi)return 0 ; } -static ssize_t gadget_dev_desc_UDC_store (struct gadget_info *gi, +static ssize_t gadget_dev_desc_UDC_store (struct config_item *item,const char *page,size_t len) { +struct gadget_info *gi =to_gadget_info (item);char *name;int ret;
@@ -283,34 +288,29 @@ err:return ret; } -GI_DEVICE_DESC_ITEM_ATTR (bDeviceClass); -GI_DEVICE_DESC_ITEM_ATTR (bDeviceSubClass); -GI_DEVICE_DESC_ITEM_ATTR (bDeviceProtocol); -GI_DEVICE_DESC_ITEM_ATTR (bMaxPacketSize0); -GI_DEVICE_DESC_ITEM_ATTR (idVendor); -GI_DEVICE_DESC_ITEM_ATTR (idProduct); -GI_DEVICE_DESC_ITEM_ATTR (bcdDevice); -GI_DEVICE_DESC_ITEM_ATTR (bcdUSB); -GI_DEVICE_DESC_ITEM_ATTR (UDC ); +CONFIGFS_ATTR (gadget_dev_desc_, bDeviceClass); +CONFIGFS_ATTR (gadget_dev_desc_, bDeviceSubClass); +CONFIGFS_ATTR (gadget_dev_desc_, bDeviceProtocol); +CONFIGFS_ATTR (gadget_dev_desc_, bMaxPacketSize0); +CONFIGFS_ATTR (gadget_dev_desc_, idVendor); +CONFIGFS_ATTR (gadget_dev_desc_, idProduct); +CONFIGFS_ATTR (gadget_dev_desc_, bcdDevice); +CONFIGFS_ATTR (gadget_dev_desc_, bcdUSB); +CONFIGFS_ATTR (gadget_dev_desc_,UDC );static struct configfs_attribute *gadget_root_attrs[] = { - &gadget_cdev_desc_bDeviceClass.attr, - &gadget_cdev_desc_bDeviceSubClass.attr, - &gadget_cdev_desc_bDeviceProtocol.attr, - &gadget_cdev_desc_bMaxPacketSize0.attr, - &gadget_cdev_desc_idVendor.attr, - &gadget_cdev_desc_idProduct.attr, - &gadget_cdev_desc_bcdDevice.attr, - &gadget_cdev_desc_bcdUSB.attr, - &gadget_cdev_desc_UDC.attr, + &gadget_dev_desc_attr_bDeviceClass, + &gadget_dev_desc_attr_bDeviceSubClass, + &gadget_dev_desc_attr_bDeviceProtocol, + &gadget_dev_desc_attr_bMaxPacketSize0, + &gadget_dev_desc_attr_idVendor, + &gadget_dev_desc_attr_idProduct, + &gadget_dev_desc_attr_bcdDevice, + &gadget_dev_desc_attr_bcdUSB, + &gadget_dev_desc_attr_UDC,NULL , }; -static inline struct gadget_info *to_gadget_info (struct config_item *item) -{ - return container_of(to_config_group(item), struct gadget_info, group); -} -static inline struct gadget_strings *to_gadget_strings (struct config_item *item) { return container_of(to_config_group(item), struct gadget_strings,
@@ -324,12 +324,6 @@ static inline struct gadget_config_name *to_gadget_config_name( group); } -static inline struct config_usb_cfg *to_config_usb_cfg (struct config_item *item) -{ - return container_of(to_config_group(item), struct config_usb_cfg, - group); -} -static inline struct usb_function_instance *to_usb_function_instance (struct config_item *item) {
@@ -348,12 +342,8 @@ static void gadget_info_attr_release(struct config_item *item)kfree (gi); } -CONFIGFS_ATTR_OPS (gadget_info); -static struct configfs_item_operations gadget_root_item_ops = { .release = gadget_info_attr_release, - .show_attribute = gadget_info_attr_show, - .store_attribute = gadget_info_attr_store, };static void gadget_config_attr_release (struct config_item *item)
@@ -454,24 +444,20 @@ static int config_usb_cfg_unlink(return 0 ; } -CONFIGFS_ATTR_OPS (config_usb_cfg); -static struct configfs_item_operations gadget_config_item_ops = { .release = gadget_config_attr_release, - .show_attribute = config_usb_cfg_attr_show, - .store_attribute = config_usb_cfg_attr_store, .allow_link = config_usb_cfg_link, .drop_link = config_usb_cfg_unlink, }; -static ssize_t gadget_config_desc_MaxPower_show (struct config_usb_cfg *cfg, +static ssize_t gadget_config_desc_MaxPower_show (struct config_item *item,char *page) { -return sprintf (page,"%u\n" , cfg->c.MaxPower); +return sprintf (page,"%u\n" ,to_config_usb_cfg (item)->c.MaxPower); } -static ssize_t gadget_config_desc_MaxPower_store (struct config_usb_cfg *cfg, +static ssize_t gadget_config_desc_MaxPower_store (struct config_item *item,const char *page,size_t len) {u16 val;
@@ -481,17 +467,18 @@ static ssize_t gadget_config_desc_MaxPower_store(struct config_usb_cfg *cfg,return ret;if (DIV_ROUND_UP (val,8 ) >0xff )return -ERANGE ; - cfg->c.MaxPower = val; +to_config_usb_cfg (item)->c.MaxPower = val;return len; } -static ssize_t gadget_config_desc_bmAttributes_show (struct config_usb_cfg *cfg, +static ssize_t gadget_config_desc_bmAttributes_show (struct config_item *item,char *page) { -return sprintf (page,"0x%02x\n" , cfg->c.bmAttributes); +return sprintf (page,"0x%02x\n" , +to_config_usb_cfg (item)->c.bmAttributes); } -static ssize_t gadget_config_desc_bmAttributes_store (struct config_usb_cfg *cfg, +static ssize_t gadget_config_desc_bmAttributes_store (struct config_item *item,const char *page,size_t len) {u8 val;
@@ -504,22 +491,16 @@ static ssize_t gadget_config_desc_bmAttributes_store(struct config_usb_cfg *cfg,if (val & ~(USB_CONFIG_ATT_ONE |USB_CONFIG_ATT_SELFPOWER |USB_CONFIG_ATT_WAKEUP ))return -EINVAL ; - cfg->c.bmAttributes = val; +to_config_usb_cfg (item)->c.bmAttributes = val;return len; } -#define CFG_CONFIG_DESC_ITEM_ATTR (name) \ - static struct config_usb_cfg_attribute gadget_usb_cfg_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - gadget_config_desc_##name##_show, \ - gadget_config_desc_##name##_store) - -CFG_CONFIG_DESC_ITEM_ATTR (MaxPower); -CFG_CONFIG_DESC_ITEM_ATTR (bmAttributes); +CONFIGFS_ATTR (gadget_config_desc_, MaxPower); +CONFIGFS_ATTR (gadget_config_desc_, bmAttributes);static struct configfs_attribute *gadget_config_attrs[] = { - &gadget_usb_cfg_MaxPower.attr, - &gadget_usb_cfg_bmAttributes.attr, + &gadget_config_desc_attr_MaxPower, + &gadget_config_desc_attr_bmAttributes,NULL , };
@@ -616,11 +597,10 @@ static struct config_item_type functions_type = { .ct_owner = THIS_MODULE, }; -CONFIGFS_ATTR_STRUCT (gadget_config_name);GS_STRINGS_RW (gadget_config_name, configuration);static struct configfs_attribute *gadget_config_name_langid_attrs[] = { - &gadget_config_name_configuration.attr, + &gadget_config_name_attr_configuration,NULL , };
@@ -719,15 +699,14 @@ static struct config_item_type config_desc_type = { .ct_owner = THIS_MODULE, }; -CONFIGFS_ATTR_STRUCT (gadget_strings);GS_STRINGS_RW (gadget_strings, manufacturer);GS_STRINGS_RW (gadget_strings, product);GS_STRINGS_RW (gadget_strings, serialnumber);static struct configfs_attribute *gadget_strings_langid_attrs[] = { - &gadget_strings_manufacturer.attr, - &gadget_strings_product.attr, - &gadget_strings_serialnumber.attr, + &gadget_strings_attr_manufacturer, + &gadget_strings_attr_product, + &gadget_strings_attr_serialnumber,NULL , };
@@ -751,27 +730,25 @@ static inline struct os_desc *to_os_desc(struct config_item *item) return container_of(to_config_group(item), struct os_desc, group); } -CONFIGFS_ATTR_STRUCT (os_desc); -CONFIGFS_ATTR_OPS (os_desc); - -static ssize_t os_desc_use_show (struct os_desc *os_desc,char *page) +static inline struct gadget_info *os_desc_item_to_gadget_info ( +struct config_item *item) { -struct gadget_info *gi; - - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); +return to_gadget_info (to_os_desc (item)->group.cg_item.ci_parent); +} -return sprintf (page,"%d" , gi->use_os_desc); +static ssize_t os_desc_use_show (struct config_item *item,char *page) +{ +return sprintf (page,"%d" , +os_desc_item_to_gadget_info (item)->use_os_desc); } -static ssize_t os_desc_use_store (struct os_desc *os_desc,const char *page, +static ssize_t os_desc_use_store (struct config_item *item,const char *page,size_t len) { -struct gadget_info *gi; +struct gadget_info *gi =os_desc_item_to_gadget_info (item);int ret;bool use; - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); -mutex_lock (&gi->lock); ret =strtobool (page, &use);if (!ret) {
@@ -783,29 +760,19 @@ static ssize_t os_desc_use_store(struct os_desc *os_desc, const char *page,return ret; } -static struct os_desc_attribute os_desc_use = -__CONFIGFS_ATTR (use,S_IRUGO |S_IWUSR , - os_desc_use_show, - os_desc_use_store); - -static ssize_t os_desc_b_vendor_code_show (struct os_desc *os_desc,char *page) +static ssize_t os_desc_b_vendor_code_show (struct config_item *item,char *page) { -struct gadget_info *gi; - - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); - -return sprintf (page,"%d" , gi->b_vendor_code); +return sprintf (page,"%d" , +os_desc_item_to_gadget_info (item)->b_vendor_code); } -static ssize_t os_desc_b_vendor_code_store (struct os_desc *os_desc, +static ssize_t os_desc_b_vendor_code_store (struct config_item *item,const char *page,size_t len) { -struct gadget_info *gi; +struct gadget_info *gi =os_desc_item_to_gadget_info (item);int ret;u8 b_vendor_code; - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); -mutex_lock (&gi->lock); ret =kstrtou8 (page,0 , &b_vendor_code);if (!ret) {
@@ -817,29 +784,20 @@ static ssize_t os_desc_b_vendor_code_store(struct os_desc *os_desc,return ret; } -static struct os_desc_attribute os_desc_b_vendor_code = -__CONFIGFS_ATTR (b_vendor_code,S_IRUGO |S_IWUSR , - os_desc_b_vendor_code_show, - os_desc_b_vendor_code_store); - -static ssize_t os_desc_qw_sign_show (struct os_desc *os_desc,char *page) +static ssize_t os_desc_qw_sign_show (struct config_item *item,char *page) { -struct gadget_info *gi; - - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); +struct gadget_info *gi =os_desc_item_to_gadget_info (item);memcpy (page, gi->qw_sign,OS_STRING_QW_SIGN_LEN ); -return OS_STRING_QW_SIGN_LEN ; } -static ssize_t os_desc_qw_sign_store (struct os_desc *os_desc,const char *page, +static ssize_t os_desc_qw_sign_store (struct config_item *item,const char *page,size_t len) { -struct gadget_info *gi; +struct gadget_info *gi =os_desc_item_to_gadget_info (item);int res, l; - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); l =min ((int )len,OS_STRING_QW_SIGN_LEN >>1 );if (page[l -1 ] =='\n' ) --l;
@@ -855,15 +813,14 @@ static ssize_t os_desc_qw_sign_store(struct os_desc *os_desc, const char *page,return res; } -static struct os_desc_attribute os_desc_qw_sign = -__CONFIGFS_ATTR (qw_sign,S_IRUGO |S_IWUSR , - os_desc_qw_sign_show, - os_desc_qw_sign_store); +CONFIGFS_ATTR (os_desc_, use); +CONFIGFS_ATTR (os_desc_, b_vendor_code); +CONFIGFS_ATTR (os_desc_, qw_sign);static struct configfs_attribute *os_desc_attrs[] = { - &os_desc_use.attr, - &os_desc_b_vendor_code.attr, - &os_desc_qw_sign.attr, + &os_desc_attr_use, + &os_desc_attr_b_vendor_code, + &os_desc_attr_qw_sign,NULL , };
@@ -926,8 +883,6 @@ static int os_desc_unlink(struct config_item *os_desc_ci,static struct configfs_item_operations os_desc_ops = { .release = os_desc_attr_release, - .show_attribute = os_desc_attr_show, - .store_attribute = os_desc_attr_store, .allow_link = os_desc_link, .drop_link = os_desc_unlink, };
@@ -938,28 +893,21 @@ static struct config_item_type os_desc_type = { .ct_owner = THIS_MODULE, }; -CONFIGFS_ATTR_STRUCT (usb_os_desc); -CONFIGFS_ATTR_OPS (usb_os_desc); - -static inline struct usb_os_desc_ext_prop *to_usb_os_desc_ext_prop (struct config_item *item) { return container_of(item, struct usb_os_desc_ext_prop, item); } -CONFIGFS_ATTR_STRUCT (usb_os_desc_ext_prop); -CONFIGFS_ATTR_OPS (usb_os_desc_ext_prop); - -static ssize_t ext_prop_type_show (struct usb_os_desc_ext_prop *ext_prop, -char *page) +static ssize_t ext_prop_type_show (struct config_item *item,char *page) { -return sprintf (page,"%d" , ext_prop->type); +return sprintf (page,"%d" ,to_usb_os_desc_ext_prop (item)->type); } -static ssize_t ext_prop_type_store (struct usb_os_desc_ext_prop *ext_prop, +static ssize_t ext_prop_type_store (struct config_item *item,const char *page,size_t len) { +struct usb_os_desc_ext_prop *ext_prop =to_usb_os_desc_ext_prop (item);struct usb_os_desc *desc =to_usb_os_desc (ext_prop->item.ci_parent);u8 type;int ret;
@@ -997,9 +945,9 @@ end:return ret; } -static ssize_t ext_prop_data_show (struct usb_os_desc_ext_prop *ext_prop, -char *page) +static ssize_t ext_prop_data_show (struct config_item *item,char *page) { +struct usb_os_desc_ext_prop *ext_prop =to_usb_os_desc_ext_prop (item);int len = ext_prop->data_len; if (ext_prop->type == USB_EXT_PROP_UNICODE ||
@@ -1011,9 +959,10 @@ static ssize_t ext_prop_data_show(struct usb_os_desc_ext_prop *ext_prop,return len; } -static ssize_t ext_prop_data_store (struct usb_os_desc_ext_prop *ext_prop, +static ssize_t ext_prop_data_store (struct config_item *item,const char *page,size_t len) { +struct usb_os_desc_ext_prop *ext_prop =to_usb_os_desc_ext_prop (item);struct usb_os_desc *desc =to_usb_os_desc (ext_prop->item.ci_parent);char *new_data;size_t ret_len = len;
@@ -1044,17 +993,12 @@ static ssize_t ext_prop_data_store(struct usb_os_desc_ext_prop *ext_prop,return ret_len; } -static struct usb_os_desc_ext_prop_attribute ext_prop_type = -__CONFIGFS_ATTR (type,S_IRUGO |S_IWUSR , - ext_prop_type_show, ext_prop_type_store); - -static struct usb_os_desc_ext_prop_attribute ext_prop_data = -__CONFIGFS_ATTR (data,S_IRUGO |S_IWUSR , - ext_prop_data_show, ext_prop_data_store); +CONFIGFS_ATTR (ext_prop_, type); +CONFIGFS_ATTR (ext_prop_, data);static struct configfs_attribute *ext_prop_attrs[] = { - &ext_prop_type.attr, - &ext_prop_data.attr, + &ext_prop_attr_type, + &ext_prop_attr_data,NULL , };
@@ -1067,8 +1011,6 @@ static void usb_os_desc_ext_prop_release(struct config_item *item)static struct configfs_item_operations ext_prop_ops = { .release = usb_os_desc_ext_prop_release, - .show_attribute = usb_os_desc_ext_prop_attr_show, - .store_attribute = usb_os_desc_ext_prop_attr_store, }; static struct config_item *ext_prop_make(
@@ -1137,21 +1079,17 @@ static struct configfs_group_operations interf_grp_ops = { .drop_item = &ext_prop_drop, }; -static struct configfs_item_operations interf_item_ops = { - .show_attribute = usb_os_desc_attr_show, - .store_attribute = usb_os_desc_attr_store, -}; - -static ssize_t interf_grp_compatible_id_show (struct usb_os_desc *desc, +static ssize_t interf_grp_compatible_id_show (struct config_item *item,char *page) { -memcpy (page, desc->ext_compat_id,8 ); +memcpy (page,to_usb_os_desc (item)->ext_compat_id,8 );return 8 ; } -static ssize_t interf_grp_compatible_id_store (struct usb_os_desc *desc, +static ssize_t interf_grp_compatible_id_store (struct config_item *item,const char *page,size_t len) { +struct usb_os_desc *desc =to_usb_os_desc (item);int l; l =min_t (int,8 , len);
@@ -1167,21 +1105,17 @@ static ssize_t interf_grp_compatible_id_store(struct usb_os_desc *desc,return len; } -static struct usb_os_desc_attribute interf_grp_attr_compatible_id = -__CONFIGFS_ATTR (compatible_id,S_IRUGO |S_IWUSR , - interf_grp_compatible_id_show, - interf_grp_compatible_id_store); - -static ssize_t interf_grp_sub_compatible_id_show (struct usb_os_desc *desc, +static ssize_t interf_grp_sub_compatible_id_show (struct config_item *item,char *page) { -memcpy (page, desc->ext_compat_id +8 ,8 ); +memcpy (page,to_usb_os_desc (item)->ext_compat_id +8 ,8 );return 8 ; } -static ssize_t interf_grp_sub_compatible_id_store (struct usb_os_desc *desc, +static ssize_t interf_grp_sub_compatible_id_store (struct config_item *item,const char *page,size_t len) { +struct usb_os_desc *desc =to_usb_os_desc (item);int l; l =min_t (int,8 , len);
@@ -1197,14 +1131,12 @@ static ssize_t interf_grp_sub_compatible_id_store(struct usb_os_desc *desc,return len; } -static struct usb_os_desc_attribute interf_grp_attr_sub_compatible_id = -__CONFIGFS_ATTR (sub_compatible_id,S_IRUGO |S_IWUSR , - interf_grp_sub_compatible_id_show, - interf_grp_sub_compatible_id_store); +CONFIGFS_ATTR (interf_grp_, compatible_id); +CONFIGFS_ATTR (interf_grp_, sub_compatible_id);static struct configfs_attribute *interf_grp_attrs[] = { - &interf_grp_attr_compatible_id.attr, - &interf_grp_attr_sub_compatible_id.attr, + &interf_grp_attr_compatible_id, + &interf_grp_attr_sub_compatible_id,NULL };
@@ -1242,7 +1174,6 @@ int usb_os_desc_prepare_interf_dir(struct config_group *parent, f_default_groups[0 ] = os_desc_group; os_desc_group->default_groups = interface_groups; - interface_type->ct_item_ops = &interf_item_ops; interface_type->ct_group_ops = &interf_grp_ops; interface_type->ct_attrs = interf_grp_attrs; interface_type->ct_owner = owner;
include/linux/usb/gadget_configfs.h +5 -14
@@ -7,9 +7,10 @@ int check_user_usb_string(const char *name, struct usb_gadget_strings *stringtab_dev);#define GS_STRINGS_W (__struct, __name) \ - static ssize_t __struct##_##__name##_store(struct __struct *gs, \ +static ssize_t __struct##_##__name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ + struct __struct *gs = to_##__struct(item); \ int ret; \ \ ret = usb_string_copy(page, &gs->__name); \
@@ -19,30 +20,20 @@ int check_user_usb_string(const char *name, }#define GS_STRINGS_R (__struct, __name) \ - static ssize_t __struct##_##__name##_show(struct __struct *gs, \ - char *page) \ +static ssize_t __struct##_##__name##_show(struct config_item *item, char *page) \ { \ + struct __struct *gs = to_##__struct(item); \ return sprintf(page, "%s\n", gs->__name ?: ""); \ } -#define GS_STRING_ITEM_ATTR (struct_name, name) \ - static struct struct_name##_attribute struct_name##_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - struct_name##_##name##_show, \ - struct_name##_##name##_store) -#define GS_STRINGS_RW (struct_name, _name) \ GS_STRINGS_R(struct_name, _name) \ GS_STRINGS_W(struct_name, _name) \ - GS_STRING_ITEM_ATTR(struct_name, _name) + CONFIGFS_ATTR(struct_name##_, _name)#define USB_CONFIG_STRING_RW_OPS (struct_in) \ - CONFIGFS_ATTR_OPS(struct_in); \ - \ static struct configfs_item_operations struct_in##_langid_item_ops = { \ .release = struct_in##_attr_release, \ - .show_attribute = struct_in##_attr_show, \ - .store_attribute = struct_in##_attr_store, \ }; \ \ static struct config_item_type struct_in##_langid_type = { \
Signature · 1 line
1.9.1
Re: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
Quoted 1 line · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>
I need commit logs for everything. Without commit logs, I can't apply your patches.
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20150927/cf80fac9/attachment.sig>
A message that is not in the archive (sent off-list or not yet received): 20150927154752.GC16364-HgARHv6XitJaoMGHk7MhZQC/[email protected]
Re: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
The Subject line is part of the commit log. If you have a useful suggestion for improving the logs please feel free to suggest it.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
Hi,
Quoted 1 line · Christoph Hellwig
The Subject line is part of the commit log. If you have a useful
heh
Quoted 1 line
suggestion for improving the logs please feel free to suggest it.
how about explaining why you want per-attribute show/store methods ?
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20151001/ec88bf66/attachment.sig>
Re: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
In reply to Christoph HellwigQuoted 11 lines · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/usb/gadget/configfs.c | 295 ++++++++++++++---------------------- include/linux/usb/gadget_configfs.h | 19 +-- 2 files changed, 118 insertions(+), 196 deletions(-)drivers/usb/gadget/configfs.c +0
-0
drivers/usb/gadget/configfs.c struct gadget_info { · line 70
Quoted 7 lines
drivers/usb/gadget/configfs.c +4
-0@@ -64,6 +64,11 @@ struct gadget_info {char qw_sign[OS_STRING_QW_SIGN_LEN ]; }; +static inline struct gadget_info *to_gadget_info (struct config_item *item) +{ + return container_of(to_config_group(item), struct gadget_info, group); +}
this (and the other helper below) could be macros just fine. Are you 100% compiler will *always* inline these helpers. The likelyhood of not inlining is minimal, sure, but what do we get for writing these as functions instead of macros ?
also, lacking commit log
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20150927/d622ed78/attachment.sig>
Re: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
Quoted 1 line · Felipe Balbi
this (and the other helper below) could be macros just fine.
They could, but they shouldn't. Inlines are always preferable over function-like macros.
Quoted 2 lines
Are you 100% compiler
will *always* inline these helpers.
With gcc you can't ever be sure - but if it doesn't inline a trivial pointer arithmetic we'll see breakage in various other places, including the file system fast path which uses this pattern all over.
Re: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Felipe Balbi
this (and the other helper below) could be macros just fine.
They could, but they shouldn't. Inlines are always preferable over function-like macros.
says who ? And why ?
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20150930/47683c42/attachment.sig>
Re: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
Quoted 8 lines · Felipe Balbi
Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Felipe Balbi
this (and the other helper below) could be macros just fine.
They could, but they shouldn't. Inlines are always preferable over function-like macros.
says who ? And why ?
Documentation/CodingStyle
Signature · 1 line
tejun
Re: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
Quoted 11 lines · Tejun Heo
Quoted 8 lines · Felipe Balbi
Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Felipe Balbi
this (and the other helper below) could be macros just fine.
They could, but they shouldn't. Inlines are always preferable over function-like macros.
says who ? And why ?
Documentation/CodingStyle
container_of() is type-safe, what is an inline function bringing as benefit ?
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20150930/f7a71fd8/attachment.sig>
Re: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
Quoted 6 lines · Felipe Balbi
Quoted 5 lines · Tejun Heo
Quoted 4 lines · Felipe Balbi
Quoted 3 lines · Christoph Hellwig
Quoted 1 line · Felipe Balbi
this (and the other helper below) could be macros just fine.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
They could, but they shouldn't. Inlines are always preferable over function-like macros.
says who ? And why ?
Documentation/CodingStyle
container_of()is type-safe, what is an inline function bringing as benefit ?
It's a general preference. Because there's enough benefit to going with inline functions and there's extra benefit to be gained from having consistent style of code and documentation, as a general rule, we prefer inline functions over macros. If you have specific technical arguments why macro is better, sure; otherwise, follow the conventions for consistency if for nothing else.
Signature · 1 line
tejun
Re: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
Quoted 14 lines · Tejun Heo
Quoted 13 lines · Felipe Balbi
Quoted 11 lines · Tejun Heo
Quoted 8 lines · Felipe Balbi
Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Felipe Balbi
this (and the other helper below) could be macros just fine.
They could, but they shouldn't. Inlines are always preferable over function-like macros.
says who ? And why ?
Documentation/CodingStyle
Quoted 8 lines
Quoted 1 line
container_of()is type-safe, what is an inline function bringing as benefit ?It's a general preference. Because there's enough benefit to going with inline functions and there's extra benefit to be gained from having consistent style of code and documentation, as a general rule, we prefer inline functions over macros. If you have specific technical arguments why macro is better, sure; otherwise, follow the conventions for consistency if for nothing else.
$ git grep -e "define.*container_of" | wc -l 1003
Seems like there are *ton* of uses of container_of() wrapped within a simple macro. What convention are you talking about, again ?
And again, what benefit is an inline function bringing in this specific case ? As for a technical reason, we know the macro definition will be copied Verbatim into the caller body. GCC might decide to not inline those helpers (unlikely, but could).
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20150930/934bd60a/attachment.sig>
Re: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
Quoted 2 lines · Felipe Balbi
Seems like there are *ton* of uses of
container_of()wrapped within a simple macro. What convention are you talking about, again ?
The convention of using inline functions over macros when possible. We don't do that all the time but that's where we wanna be in general.
Quoted 4 lines
And again, what benefit is an inline function bringing in this specific case ? As for a technical reason, we know the macro definition will be copied Verbatim into the caller body. GCC might decide to not inline those helpers (unlikely, but could).
That's really grasping at straws. Let's not go there.
For simple stuff like container_of(), a more valid reason would be "it's shorter and sweeter and AFAICS doesn't have any known downsides of using macros" but this ultimately is a bike-shedding problem.
You asked where and why we said we prefer inline functions so that's the answer (aside from individual technical advantages). It's not an absolute rule but we're better off if we try to keep things consistent if possible. As for this specific case, I don't know. I might do the macro too just because it's less typing and I don't really care but at the same time I'd just switch to inline if somebody points it out.
Signature · 1 line
tejun
A message that is not in the archive (sent off-list or not yet received): 1443189000-13398-3-git-send-email-hch-jcswGhMUV9g@public.gmane.org
Andrzej Pietrasiewicz
Reviewed-byRe: [PATCH 02/23] usb-gadget: use per-attribute show and store methods
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 696 lines
--- drivers/usb/gadget/configfs.c | 295 ++++++++++++++---------------------- include/linux/usb/gadget_configfs.h | 19 +-- 2 files changed, 118 insertions(+), 196 deletions(-)drivers/usb/gadget/configfs.c +113
-182@@ -64,6 +64,11 @@ struct gadget_info {char qw_sign[OS_STRING_QW_SIGN_LEN ]; }; +static inline struct gadget_info *to_gadget_info (struct config_item *item) +{ + return container_of(to_config_group(item), struct gadget_info, group); +} +struct config_usb_cfg {struct config_group group;struct config_group strings_group;@@ -74,6 +79,12 @@ struct config_usb_cfg {struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS +1 ]; }; +static inline struct config_usb_cfg *to_config_usb_cfg (struct config_item *item) +{ + return container_of(to_config_group(item), struct config_usb_cfg, + group); +} +struct gadget_strings {struct usb_gadget_strings stringtab_dev;struct usb_string strings[USB_GADGET_FIRST_AVAIL_IDX ];@@ -117,32 +128,25 @@ static int usb_string_copy(const char *s, char **s_copy)return 0 ; } -CONFIGFS_ATTR_STRUCT (gadget_info); -CONFIGFS_ATTR_STRUCT (config_usb_cfg); - -#define GI_DEVICE_DESC_ITEM_ATTR (name) \ - static struct gadget_info_attribute gadget_cdev_desc_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - gadget_dev_desc_##name##_show, \ - gadget_dev_desc_##name##_store) -#define GI_DEVICE_DESC_SIMPLE_R_u8 (__name) \ - static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \ +static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \ char *page) \ { \ - return sprintf(page, "0x%02x\n", gi->cdev.desc.__name); \ + return sprintf(page, "0x%02x\n", \ + to_gadget_info(item)->cdev.desc.__name); \ }#define GI_DEVICE_DESC_SIMPLE_R_u16 (__name) \ - static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \ +static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \ char *page) \ { \ - return sprintf(page, "0x%04x\n", le16_to_cpup(&gi->cdev.desc.__name)); \ + return sprintf(page, "0x%04x\n", \ + le16_to_cpup(&to_gadget_info(item)->cdev.desc.__name)); \ }#define GI_DEVICE_DESC_SIMPLE_W_u8 (_name) \ - static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \ +static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ u8 val; \@@ -150,12 +154,12 @@ CONFIGFS_ATTR_STRUCT(config_usb_cfg); ret =kstrtou8 (page,0 , &val); \if (ret) \return ret; \ - gi->cdev.desc._name = val; \ +to_gadget_info (item)->cdev.desc._name = val; \return len; \ }#define GI_DEVICE_DESC_SIMPLE_W_u16 (_name) \ - static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \ +static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ u16 val; \@@ -163,7 +167,7 @@ CONFIGFS_ATTR_STRUCT(config_usb_cfg); ret =kstrtou16 (page,0 , &val); \if (ret) \return ret; \ - gi->cdev.desc._name =cpu_to_le16p (&val); \ +to_gadget_info (item)->cdev.desc._name =cpu_to_le16p (&val); \return len; \ }@@ -193,7 +197,7 @@ static ssize_t is_valid_bcd(u16 bcd_val)return 0 ; } -static ssize_t gadget_dev_desc_bcdDevice_store (struct gadget_info *gi, +static ssize_t gadget_dev_desc_bcdDevice_store (struct config_item *item,const char *page,size_t len) {u16 bcdDevice;@@ -206,11 +210,11 @@ static ssize_t gadget_dev_desc_bcdDevice_store(struct gadget_info *gi,if (ret)return ret; - gi->cdev.desc.bcdDevice =cpu_to_le16 (bcdDevice); +to_gadget_info (item)->cdev.desc.bcdDevice =cpu_to_le16 (bcdDevice);return len; } -static ssize_t gadget_dev_desc_bcdUSB_store (struct gadget_info *gi, +static ssize_t gadget_dev_desc_bcdUSB_store (struct config_item *item,const char *page,size_t len) {u16 bcdUSB;@@ -223,13 +227,13 @@ static ssize_t gadget_dev_desc_bcdUSB_store(struct gadget_info *gi,if (ret)return ret; - gi->cdev.desc.bcdUSB =cpu_to_le16 (bcdUSB); +to_gadget_info (item)->cdev.desc.bcdUSB =cpu_to_le16 (bcdUSB);return len; } -static ssize_t gadget_dev_desc_UDC_show (struct gadget_info *gi,char *page) +static ssize_t gadget_dev_desc_UDC_show (struct config_item *item,char *page) { -return sprintf (page,"%s\n" , gi->udc_name ?:"" ); +return sprintf (page,"%s\n" ,to_gadget_info (item)->udc_name ?:"" ); }static int unregister_gadget (struct gadget_info *gi)@@ -247,9 +251,10 @@ static int unregister_gadget(struct gadget_info *gi)return 0 ; } -static ssize_t gadget_dev_desc_UDC_store (struct gadget_info *gi, +static ssize_t gadget_dev_desc_UDC_store (struct config_item *item,const char *page,size_t len) { +struct gadget_info *gi =to_gadget_info (item);char *name;int ret;@@ -283,34 +288,29 @@ err:return ret; } -GI_DEVICE_DESC_ITEM_ATTR (bDeviceClass); -GI_DEVICE_DESC_ITEM_ATTR (bDeviceSubClass); -GI_DEVICE_DESC_ITEM_ATTR (bDeviceProtocol); -GI_DEVICE_DESC_ITEM_ATTR (bMaxPacketSize0); -GI_DEVICE_DESC_ITEM_ATTR (idVendor); -GI_DEVICE_DESC_ITEM_ATTR (idProduct); -GI_DEVICE_DESC_ITEM_ATTR (bcdDevice); -GI_DEVICE_DESC_ITEM_ATTR (bcdUSB); -GI_DEVICE_DESC_ITEM_ATTR (UDC ); +CONFIGFS_ATTR (gadget_dev_desc_, bDeviceClass); +CONFIGFS_ATTR (gadget_dev_desc_, bDeviceSubClass); +CONFIGFS_ATTR (gadget_dev_desc_, bDeviceProtocol); +CONFIGFS_ATTR (gadget_dev_desc_, bMaxPacketSize0); +CONFIGFS_ATTR (gadget_dev_desc_, idVendor); +CONFIGFS_ATTR (gadget_dev_desc_, idProduct); +CONFIGFS_ATTR (gadget_dev_desc_, bcdDevice); +CONFIGFS_ATTR (gadget_dev_desc_, bcdUSB); +CONFIGFS_ATTR (gadget_dev_desc_,UDC );static struct configfs_attribute *gadget_root_attrs[] = { - &gadget_cdev_desc_bDeviceClass.attr, - &gadget_cdev_desc_bDeviceSubClass.attr, - &gadget_cdev_desc_bDeviceProtocol.attr, - &gadget_cdev_desc_bMaxPacketSize0.attr, - &gadget_cdev_desc_idVendor.attr, - &gadget_cdev_desc_idProduct.attr, - &gadget_cdev_desc_bcdDevice.attr, - &gadget_cdev_desc_bcdUSB.attr, - &gadget_cdev_desc_UDC.attr, + &gadget_dev_desc_attr_bDeviceClass, + &gadget_dev_desc_attr_bDeviceSubClass, + &gadget_dev_desc_attr_bDeviceProtocol, + &gadget_dev_desc_attr_bMaxPacketSize0, + &gadget_dev_desc_attr_idVendor, + &gadget_dev_desc_attr_idProduct, + &gadget_dev_desc_attr_bcdDevice, + &gadget_dev_desc_attr_bcdUSB, + &gadget_dev_desc_attr_UDC,NULL , }; -static inline struct gadget_info *to_gadget_info (struct config_item *item) -{ - return container_of(to_config_group(item), struct gadget_info, group); -} -static inline struct gadget_strings *to_gadget_strings (struct config_item *item) { return container_of(to_config_group(item), struct gadget_strings,@@ -324,12 +324,6 @@ static inline struct gadget_config_name *to_gadget_config_name( group); } -static inline struct config_usb_cfg *to_config_usb_cfg (struct config_item *item) -{ - return container_of(to_config_group(item), struct config_usb_cfg, - group); -} -static inline struct usb_function_instance *to_usb_function_instance (struct config_item *item) {@@ -348,12 +342,8 @@ static void gadget_info_attr_release(struct config_item *item)kfree (gi); } -CONFIGFS_ATTR_OPS (gadget_info); -static struct configfs_item_operations gadget_root_item_ops = { .release = gadget_info_attr_release, - .show_attribute = gadget_info_attr_show, - .store_attribute = gadget_info_attr_store, };static void gadget_config_attr_release (struct config_item *item)@@ -454,24 +444,20 @@ static int config_usb_cfg_unlink(return 0 ; } -CONFIGFS_ATTR_OPS (config_usb_cfg); -static struct configfs_item_operations gadget_config_item_ops = { .release = gadget_config_attr_release, - .show_attribute = config_usb_cfg_attr_show, - .store_attribute = config_usb_cfg_attr_store, .allow_link = config_usb_cfg_link, .drop_link = config_usb_cfg_unlink, }; -static ssize_t gadget_config_desc_MaxPower_show (struct config_usb_cfg *cfg, +static ssize_t gadget_config_desc_MaxPower_show (struct config_item *item,char *page) { -return sprintf (page,"%u\n" , cfg->c.MaxPower); +return sprintf (page,"%u\n" ,to_config_usb_cfg (item)->c.MaxPower); } -static ssize_t gadget_config_desc_MaxPower_store (struct config_usb_cfg *cfg, +static ssize_t gadget_config_desc_MaxPower_store (struct config_item *item,const char *page,size_t len) {u16 val;@@ -481,17 +467,18 @@ static ssize_t gadget_config_desc_MaxPower_store(struct config_usb_cfg *cfg,return ret;if (DIV_ROUND_UP (val,8 ) >0xff )return -ERANGE ; - cfg->c.MaxPower = val; +to_config_usb_cfg (item)->c.MaxPower = val;return len; } -static ssize_t gadget_config_desc_bmAttributes_show (struct config_usb_cfg *cfg, +static ssize_t gadget_config_desc_bmAttributes_show (struct config_item *item,char *page) { -return sprintf (page,"0x%02x\n" , cfg->c.bmAttributes); +return sprintf (page,"0x%02x\n" , +to_config_usb_cfg (item)->c.bmAttributes); } -static ssize_t gadget_config_desc_bmAttributes_store (struct config_usb_cfg *cfg, +static ssize_t gadget_config_desc_bmAttributes_store (struct config_item *item,const char *page,size_t len) {u8 val;@@ -504,22 +491,16 @@ static ssize_t gadget_config_desc_bmAttributes_store(struct config_usb_cfg *cfg,if (val & ~(USB_CONFIG_ATT_ONE |USB_CONFIG_ATT_SELFPOWER |USB_CONFIG_ATT_WAKEUP ))return -EINVAL ; - cfg->c.bmAttributes = val; +to_config_usb_cfg (item)->c.bmAttributes = val;return len; } -#define CFG_CONFIG_DESC_ITEM_ATTR (name) \ - static struct config_usb_cfg_attribute gadget_usb_cfg_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - gadget_config_desc_##name##_show, \ - gadget_config_desc_##name##_store) - -CFG_CONFIG_DESC_ITEM_ATTR (MaxPower); -CFG_CONFIG_DESC_ITEM_ATTR (bmAttributes); +CONFIGFS_ATTR (gadget_config_desc_, MaxPower); +CONFIGFS_ATTR (gadget_config_desc_, bmAttributes);static struct configfs_attribute *gadget_config_attrs[] = { - &gadget_usb_cfg_MaxPower.attr, - &gadget_usb_cfg_bmAttributes.attr, + &gadget_config_desc_attr_MaxPower, + &gadget_config_desc_attr_bmAttributes,NULL , };@@ -616,11 +597,10 @@ static struct config_item_type functions_type = { .ct_owner = THIS_MODULE, }; -CONFIGFS_ATTR_STRUCT (gadget_config_name);GS_STRINGS_RW (gadget_config_name, configuration);static struct configfs_attribute *gadget_config_name_langid_attrs[] = { - &gadget_config_name_configuration.attr, + &gadget_config_name_attr_configuration,NULL , };@@ -719,15 +699,14 @@ static struct config_item_type config_desc_type = { .ct_owner = THIS_MODULE, }; -CONFIGFS_ATTR_STRUCT (gadget_strings);GS_STRINGS_RW (gadget_strings, manufacturer);GS_STRINGS_RW (gadget_strings, product);GS_STRINGS_RW (gadget_strings, serialnumber);static struct configfs_attribute *gadget_strings_langid_attrs[] = { - &gadget_strings_manufacturer.attr, - &gadget_strings_product.attr, - &gadget_strings_serialnumber.attr, + &gadget_strings_attr_manufacturer, + &gadget_strings_attr_product, + &gadget_strings_attr_serialnumber,NULL , };@@ -751,27 +730,25 @@ static inline struct os_desc *to_os_desc(struct config_item *item) return container_of(to_config_group(item), struct os_desc, group); } -CONFIGFS_ATTR_STRUCT (os_desc); -CONFIGFS_ATTR_OPS (os_desc); - -static ssize_t os_desc_use_show (struct os_desc *os_desc,char *page) +static inline struct gadget_info *os_desc_item_to_gadget_info ( +struct config_item *item) { -struct gadget_info *gi; - - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); +return to_gadget_info (to_os_desc (item)->group.cg_item.ci_parent); +} -return sprintf (page,"%d" , gi->use_os_desc); +static ssize_t os_desc_use_show (struct config_item *item,char *page) +{ +return sprintf (page,"%d" , +os_desc_item_to_gadget_info (item)->use_os_desc); } -static ssize_t os_desc_use_store (struct os_desc *os_desc,const char *page, +static ssize_t os_desc_use_store (struct config_item *item,const char *page,size_t len) { -struct gadget_info *gi; +struct gadget_info *gi =os_desc_item_to_gadget_info (item);int ret;bool use; - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); -mutex_lock (&gi->lock); ret =strtobool (page, &use);if (!ret) {@@ -783,29 +760,19 @@ static ssize_t os_desc_use_store(struct os_desc *os_desc, const char *page,return ret; } -static struct os_desc_attribute os_desc_use = -__CONFIGFS_ATTR (use,S_IRUGO |S_IWUSR , - os_desc_use_show, - os_desc_use_store); - -static ssize_t os_desc_b_vendor_code_show (struct os_desc *os_desc,char *page) +static ssize_t os_desc_b_vendor_code_show (struct config_item *item,char *page) { -struct gadget_info *gi; - - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); - -return sprintf (page,"%d" , gi->b_vendor_code); +return sprintf (page,"%d" , +os_desc_item_to_gadget_info (item)->b_vendor_code); } -static ssize_t os_desc_b_vendor_code_store (struct os_desc *os_desc, +static ssize_t os_desc_b_vendor_code_store (struct config_item *item,const char *page,size_t len) { -struct gadget_info *gi; +struct gadget_info *gi =os_desc_item_to_gadget_info (item);int ret;u8 b_vendor_code; - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); -mutex_lock (&gi->lock); ret =kstrtou8 (page,0 , &b_vendor_code);if (!ret) {@@ -817,29 +784,20 @@ static ssize_t os_desc_b_vendor_code_store(struct os_desc *os_desc,return ret; } -static struct os_desc_attribute os_desc_b_vendor_code = -__CONFIGFS_ATTR (b_vendor_code,S_IRUGO |S_IWUSR , - os_desc_b_vendor_code_show, - os_desc_b_vendor_code_store); - -static ssize_t os_desc_qw_sign_show (struct os_desc *os_desc,char *page) +static ssize_t os_desc_qw_sign_show (struct config_item *item,char *page) { -struct gadget_info *gi; - - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); +struct gadget_info *gi =os_desc_item_to_gadget_info (item);memcpy (page, gi->qw_sign,OS_STRING_QW_SIGN_LEN ); -return OS_STRING_QW_SIGN_LEN ; } -static ssize_t os_desc_qw_sign_store (struct os_desc *os_desc,const char *page, +static ssize_t os_desc_qw_sign_store (struct config_item *item,const char *page,size_t len) { -struct gadget_info *gi; +struct gadget_info *gi =os_desc_item_to_gadget_info (item);int res, l; - gi =to_gadget_info (os_desc->group.cg_item.ci_parent); l =min ((int )len,OS_STRING_QW_SIGN_LEN >>1 );if (page[l -1 ] =='\n' ) --l;@@ -855,15 +813,14 @@ static ssize_t os_desc_qw_sign_store(struct os_desc *os_desc, const char *page,return res; } -static struct os_desc_attribute os_desc_qw_sign = -__CONFIGFS_ATTR (qw_sign,S_IRUGO |S_IWUSR , - os_desc_qw_sign_show, - os_desc_qw_sign_store); +CONFIGFS_ATTR (os_desc_, use); +CONFIGFS_ATTR (os_desc_, b_vendor_code); +CONFIGFS_ATTR (os_desc_, qw_sign);static struct configfs_attribute *os_desc_attrs[] = { - &os_desc_use.attr, - &os_desc_b_vendor_code.attr, - &os_desc_qw_sign.attr, + &os_desc_attr_use, + &os_desc_attr_b_vendor_code, + &os_desc_attr_qw_sign,NULL , };@@ -926,8 +883,6 @@ static int os_desc_unlink(struct config_item *os_desc_ci,static struct configfs_item_operations os_desc_ops = { .release = os_desc_attr_release, - .show_attribute = os_desc_attr_show, - .store_attribute = os_desc_attr_store, .allow_link = os_desc_link, .drop_link = os_desc_unlink, };@@ -938,28 +893,21 @@ static struct config_item_type os_desc_type = { .ct_owner = THIS_MODULE, }; -CONFIGFS_ATTR_STRUCT (usb_os_desc); -CONFIGFS_ATTR_OPS (usb_os_desc); - -static inline struct usb_os_desc_ext_prop *to_usb_os_desc_ext_prop (struct config_item *item) { return container_of(item, struct usb_os_desc_ext_prop, item); } -CONFIGFS_ATTR_STRUCT (usb_os_desc_ext_prop); -CONFIGFS_ATTR_OPS (usb_os_desc_ext_prop); - -static ssize_t ext_prop_type_show (struct usb_os_desc_ext_prop *ext_prop, -char *page) +static ssize_t ext_prop_type_show (struct config_item *item,char *page) { -return sprintf (page,"%d" , ext_prop->type); +return sprintf (page,"%d" ,to_usb_os_desc_ext_prop (item)->type); } -static ssize_t ext_prop_type_store (struct usb_os_desc_ext_prop *ext_prop, +static ssize_t ext_prop_type_store (struct config_item *item,const char *page,size_t len) { +struct usb_os_desc_ext_prop *ext_prop =to_usb_os_desc_ext_prop (item);struct usb_os_desc *desc =to_usb_os_desc (ext_prop->item.ci_parent);u8 type;int ret;@@ -997,9 +945,9 @@ end:return ret; } -static ssize_t ext_prop_data_show (struct usb_os_desc_ext_prop *ext_prop, -char *page) +static ssize_t ext_prop_data_show (struct config_item *item,char *page) { +struct usb_os_desc_ext_prop *ext_prop =to_usb_os_desc_ext_prop (item);int len = ext_prop->data_len; if (ext_prop->type == USB_EXT_PROP_UNICODE ||@@ -1011,9 +959,10 @@ static ssize_t ext_prop_data_show(struct usb_os_desc_ext_prop *ext_prop,return len; } -static ssize_t ext_prop_data_store (struct usb_os_desc_ext_prop *ext_prop, +static ssize_t ext_prop_data_store (struct config_item *item,const char *page,size_t len) { +struct usb_os_desc_ext_prop *ext_prop =to_usb_os_desc_ext_prop (item);struct usb_os_desc *desc =to_usb_os_desc (ext_prop->item.ci_parent);char *new_data;size_t ret_len = len;@@ -1044,17 +993,12 @@ static ssize_t ext_prop_data_store(struct usb_os_desc_ext_prop *ext_prop,return ret_len; } -static struct usb_os_desc_ext_prop_attribute ext_prop_type = -__CONFIGFS_ATTR (type,S_IRUGO |S_IWUSR , - ext_prop_type_show, ext_prop_type_store); - -static struct usb_os_desc_ext_prop_attribute ext_prop_data = -__CONFIGFS_ATTR (data,S_IRUGO |S_IWUSR , - ext_prop_data_show, ext_prop_data_store); +CONFIGFS_ATTR (ext_prop_, type); +CONFIGFS_ATTR (ext_prop_, data);static struct configfs_attribute *ext_prop_attrs[] = { - &ext_prop_type.attr, - &ext_prop_data.attr, + &ext_prop_attr_type, + &ext_prop_attr_data,NULL , };@@ -1067,8 +1011,6 @@ static void usb_os_desc_ext_prop_release(struct config_item *item)static struct configfs_item_operations ext_prop_ops = { .release = usb_os_desc_ext_prop_release, - .show_attribute = usb_os_desc_ext_prop_attr_show, - .store_attribute = usb_os_desc_ext_prop_attr_store, }; static struct config_item *ext_prop_make(@@ -1137,21 +1079,17 @@ static struct configfs_group_operations interf_grp_ops = { .drop_item = &ext_prop_drop, }; -static struct configfs_item_operations interf_item_ops = { - .show_attribute = usb_os_desc_attr_show, - .store_attribute = usb_os_desc_attr_store, -}; - -static ssize_t interf_grp_compatible_id_show (struct usb_os_desc *desc, +static ssize_t interf_grp_compatible_id_show (struct config_item *item,char *page) { -memcpy (page, desc->ext_compat_id,8 ); +memcpy (page,to_usb_os_desc (item)->ext_compat_id,8 );return 8 ; } -static ssize_t interf_grp_compatible_id_store (struct usb_os_desc *desc, +static ssize_t interf_grp_compatible_id_store (struct config_item *item,const char *page,size_t len) { +struct usb_os_desc *desc =to_usb_os_desc (item);int l; l =min_t (int,8 , len);@@ -1167,21 +1105,17 @@ static ssize_t interf_grp_compatible_id_store(struct usb_os_desc *desc,return len; } -static struct usb_os_desc_attribute interf_grp_attr_compatible_id = -__CONFIGFS_ATTR (compatible_id,S_IRUGO |S_IWUSR , - interf_grp_compatible_id_show, - interf_grp_compatible_id_store); - -static ssize_t interf_grp_sub_compatible_id_show (struct usb_os_desc *desc, +static ssize_t interf_grp_sub_compatible_id_show (struct config_item *item,char *page) { -memcpy (page, desc->ext_compat_id +8 ,8 ); +memcpy (page,to_usb_os_desc (item)->ext_compat_id +8 ,8 );return 8 ; } -static ssize_t interf_grp_sub_compatible_id_store (struct usb_os_desc *desc, +static ssize_t interf_grp_sub_compatible_id_store (struct config_item *item,const char *page,size_t len) { +struct usb_os_desc *desc =to_usb_os_desc (item);int l; l =min_t (int,8 , len);@@ -1197,14 +1131,12 @@ static ssize_t interf_grp_sub_compatible_id_store(struct usb_os_desc *desc,return len; } -static struct usb_os_desc_attribute interf_grp_attr_sub_compatible_id = -__CONFIGFS_ATTR (sub_compatible_id,S_IRUGO |S_IWUSR , - interf_grp_sub_compatible_id_show, - interf_grp_sub_compatible_id_store); +CONFIGFS_ATTR (interf_grp_, compatible_id); +CONFIGFS_ATTR (interf_grp_, sub_compatible_id);static struct configfs_attribute *interf_grp_attrs[] = { - &interf_grp_attr_compatible_id.attr, - &interf_grp_attr_sub_compatible_id.attr, + &interf_grp_attr_compatible_id, + &interf_grp_attr_sub_compatible_id,NULL };@@ -1242,7 +1174,6 @@ int usb_os_desc_prepare_interf_dir(struct config_group *parent, f_default_groups[0 ] = os_desc_group; os_desc_group->default_groups = interface_groups; - interface_type->ct_item_ops = &interf_item_ops; interface_type->ct_group_ops = &interf_grp_ops; interface_type->ct_attrs = interf_grp_attrs; interface_type->ct_owner = owner;include/linux/usb/gadget_configfs.h +5
-14@@ -7,9 +7,10 @@ int check_user_usb_string(const char *name, struct usb_gadget_strings *stringtab_dev);#define GS_STRINGS_W (__struct, __name) \ - static ssize_t __struct##_##__name##_store(struct __struct *gs, \ +static ssize_t __struct##_##__name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ + struct __struct *gs = to_##__struct(item); \ int ret; \ \ ret = usb_string_copy(page, &gs->__name); \@@ -19,30 +20,20 @@ int check_user_usb_string(const char *name, }#define GS_STRINGS_R (__struct, __name) \ - static ssize_t __struct##_##__name##_show(struct __struct *gs, \ - char *page) \ +static ssize_t __struct##_##__name##_show(struct config_item *item, char *page) \ { \ + struct __struct *gs = to_##__struct(item); \ return sprintf(page, "%s\n", gs->__name ?: ""); \ } -#define GS_STRING_ITEM_ATTR (struct_name, name) \ - static struct struct_name##_attribute struct_name##_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - struct_name##_##name##_show, \ - struct_name##_##name##_store) -#define GS_STRINGS_RW (struct_name, _name) \ GS_STRINGS_R(struct_name, _name) \ GS_STRINGS_W(struct_name, _name) \ - GS_STRING_ITEM_ATTR(struct_name, _name) + CONFIGFS_ATTR(struct_name##_, _name)#define USB_CONFIG_STRING_RW_OPS (struct_in) \ - CONFIGFS_ATTR_OPS(struct_in); \ - \ static struct configfs_item_operations struct_in##_langid_item_ops = { \ .release = struct_in##_attr_release, \ - .show_attribute = struct_in##_attr_show, \ - .store_attribute = struct_in##_attr_store, \ }; \ \ static struct config_item_type struct_in##_langid_type = { \
PATCH 3/23 usb-gadget/uvc: use per-attribute show and store methods
In reply to Christoph HellwigUVC is a little different from other configfs consumers in that it wants different function and field names from the exposed attribute name, so it keeps it's local macros to define attributes instead of using the common ones.
--- drivers/usb/gadget/function/uvc_configfs.c | 391 +++++++++++------------------ 1 file changed, 146 insertions(+), 245 deletions(-)
drivers/usb/gadget/function/uvc_configfs.c +146 -245
@@ -15,23 +15,27 @@#include "u_uvc.h" #include "uvc_configfs.h" -#define UVCG_STREAMING_CONTROL_SIZE 1 +#define UVC_ATTR (prefix, cname, aname) \ +static struct configfs_attribute prefix##attr_##cname = { \ + .ca_name = __stringify(aname), \ + .ca_mode = S_IRUGO, \ + .ca_owner = THIS_MODULE, \ + .show = prefix##cname##_show, \ + .store = prefix##cname##_store, \ +} -#define CONFIGFS_ATTR_OPS_RO (_item) \ -static ssize_t _item##_attr_show(struct config_item *item, \ - struct configfs_attribute *attr, \ - char *page) \ -{ \ - struct _item *_item = to_##_item(item); \ - struct _item##_attribute *_item##_attr = \ - container_of(attr, struct _item##_attribute, attr); \ - ssize_t ret = 0; \ - \ - if (_item##_attr->show) \ - ret = _item##_attr->show(_item, page); \ - return ret; \ +#define UVC_ATTR_RO (prefix, cname, aname) \ +static struct configfs_attribute prefix##attr_##cname = { \ + .ca_name = __stringify(aname), \ + .ca_mode = S_IRUGO, \ + .ca_owner = THIS_MODULE, \ + .show = prefix##cname##_show, \ } +#define identity_conv (x) (x) + +#define UVCG_STREAMING_CONTROL_SIZE 1 +static inline struct f_uvc_opts *to_f_uvc_opts (struct config_item *item);/* control/header/<NAME> */
@@ -48,18 +52,11 @@ static struct uvcg_control_header *to_uvcg_control_header(struct config_item *it return container_of(item, struct uvcg_control_header, item); } -CONFIGFS_ATTR_STRUCT (uvcg_control_header); -CONFIGFS_ATTR_OPS (uvcg_control_header); - -static struct configfs_item_operations uvcg_control_header_item_ops = { - .show_attribute = uvcg_control_header_attr_show, - .store_attribute = uvcg_control_header_attr_store, -}; -#define UVCG_CTRL_HDR_ATTR (cname, aname, conv, str2u, uxx, vnoc, limit) \ static ssize_t uvcg_control_header_##cname##_show( \ - struct uvcg_control_header *ch, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_control_header *ch = to_uvcg_control_header(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &ch->item.ci_group->cg_subsys->su_mutex;\
@@ -79,9 +76,10 @@ static ssize_t uvcg_control_header_##cname##_show( \ } \ \static ssize_t \ -uvcg_control_header_##cname##_store(struct uvcg_control_header *ch, \ +uvcg_control_header_##cname##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct uvcg_control_header *ch =to_uvcg_control_header (item); \struct f_uvc_opts *opts; \struct config_item *opts_item; \struct mutex *su_mutex = &ch->item.ci_group->cg_subsys->su_mutex;\
@@ -115,11 +113,7 @@ end: \return ret; \ } \ \ -static struct uvcg_control_header_attribute \ - uvcg_control_header_##cname = \ - __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \ - uvcg_control_header_##cname##_show, \ - uvcg_control_header_##cname##_store) +UVC_ATTR(uvcg_control_header_, cname, aname)UVCG_CTRL_HDR_ATTR (bcd_uvc, bcdUVC, le16_to_cpu, kstrtou16, u16, cpu_to_le16,0xffff );
@@ -130,13 +124,12 @@ UVCG_CTRL_HDR_ATTR(dw_clock_frequency, dwClockFrequency, le32_to_cpu, kstrtou32,#undef UVCG_CTRL_HDR_ATTRstatic struct configfs_attribute *uvcg_control_header_attrs[] = { - &uvcg_control_header_bcd_uvc.attr, - &uvcg_control_header_dw_clock_frequency.attr, + &uvcg_control_header_attr_bcd_uvc, + &uvcg_control_header_attr_dw_clock_frequency,NULL , };static struct config_item_type uvcg_control_header_type = { - .ct_item_ops = &uvcg_control_header_item_ops, .ct_attrs = uvcg_control_header_attrs, .ct_owner =THIS_MODULE , };
@@ -196,17 +189,11 @@ static inline struct uvcg_default_processing struct uvcg_default_processing, group); } -CONFIGFS_ATTR_STRUCT (uvcg_default_processing); -CONFIGFS_ATTR_OPS_RO (uvcg_default_processing); - -static struct configfs_item_operations uvcg_default_processing_item_ops = { - .show_attribute = uvcg_default_processing_attr_show, -}; -#define UVCG_DEFAULT_PROCESSING_ATTR (cname, aname, conv) \ static ssize_t uvcg_default_processing_##cname##_show( \ - struct uvcg_default_processing *dp, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_default_processing *dp = to_uvcg_default_processing(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &dp->group.cg_subsys->su_mutex; \
@@ -227,9 +214,7 @@ static ssize_t uvcg_default_processing_##cname##_show( \return result; \ } \ \ -static struct uvcg_default_processing_attribute \ - uvcg_default_processing_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_default_processing_##cname##_show) +UVC_ATTR_RO(uvcg_default_processing_, cname, aname)#define identity_conv (x) (x)
@@ -243,8 +228,9 @@ UVCG_DEFAULT_PROCESSING_ATTR(i_processing, iProcessing, identity_conv);#undef UVCG_DEFAULT_PROCESSING_ATTRstatic ssize_t uvcg_default_processing_bm_controls_show ( -struct uvcg_default_processing *dp,char *page) +struct config_item *item,char *page) { +struct uvcg_default_processing *dp =to_uvcg_default_processing (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct mutex *su_mutex = &dp->group.cg_subsys->su_mutex;
@@ -270,22 +256,18 @@ static ssize_t uvcg_default_processing_bm_controls_show(return result; } -static struct uvcg_default_processing_attribute - uvcg_default_processing_bm_controls = -__CONFIGFS_ATTR_RO (bmControls, - uvcg_default_processing_bm_controls_show); +UVC_ATTR_RO (uvcg_default_processing_, bm_controls, bmControls);static struct configfs_attribute *uvcg_default_processing_attrs[] = { - &uvcg_default_processing_b_unit_id.attr, - &uvcg_default_processing_b_source_id.attr, - &uvcg_default_processing_w_max_multiplier.attr, - &uvcg_default_processing_bm_controls.attr, - &uvcg_default_processing_i_processing.attr, + &uvcg_default_processing_attr_b_unit_id, + &uvcg_default_processing_attr_b_source_id, + &uvcg_default_processing_attr_w_max_multiplier, + &uvcg_default_processing_attr_bm_controls, + &uvcg_default_processing_attr_i_processing,NULL , };static struct config_item_type uvcg_default_processing_type = { - .ct_item_ops = &uvcg_default_processing_item_ops, .ct_attrs = uvcg_default_processing_attrs, .ct_owner =THIS_MODULE , };
@@ -318,17 +300,11 @@ static inline struct uvcg_default_camera struct uvcg_default_camera, group); } -CONFIGFS_ATTR_STRUCT (uvcg_default_camera); -CONFIGFS_ATTR_OPS_RO (uvcg_default_camera); - -static struct configfs_item_operations uvcg_default_camera_item_ops = { - .show_attribute = uvcg_default_camera_attr_show, -}; -#define UVCG_DEFAULT_CAMERA_ATTR (cname, aname, conv) \ static ssize_t uvcg_default_camera_##cname##_show( \ - struct uvcg_default_camera *dc, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_default_camera *dc = to_uvcg_default_camera(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; \
@@ -351,9 +327,7 @@ static ssize_t uvcg_default_camera_##cname##_show( \return result; \ } \ \ -static struct uvcg_default_camera_attribute \ - uvcg_default_camera_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_default_camera_##cname##_show) +UVC_ATTR_RO(uvcg_default_camera_, cname, aname)#define identity_conv (x) (x)
@@ -373,8 +347,9 @@ UVCG_DEFAULT_CAMERA_ATTR(w_ocular_focal_length, wOcularFocalLength,#undef UVCG_DEFAULT_CAMERA_ATTRstatic ssize_t uvcg_default_camera_bm_controls_show ( -struct uvcg_default_camera *dc,char *page) +struct config_item *item,char *page) { +struct uvcg_default_camera *dc =to_uvcg_default_camera (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex;
@@ -400,24 +375,21 @@ static ssize_t uvcg_default_camera_bm_controls_show(return result; } -static struct uvcg_default_camera_attribute - uvcg_default_camera_bm_controls = -__CONFIGFS_ATTR_RO (bmControls, uvcg_default_camera_bm_controls_show); +UVC_ATTR_RO (uvcg_default_camera_, bm_controls, bmControls);static struct configfs_attribute *uvcg_default_camera_attrs[] = { - &uvcg_default_camera_b_terminal_id.attr, - &uvcg_default_camera_w_terminal_type.attr, - &uvcg_default_camera_b_assoc_terminal.attr, - &uvcg_default_camera_i_terminal.attr, - &uvcg_default_camera_w_objective_focal_length_min.attr, - &uvcg_default_camera_w_objective_focal_length_max.attr, - &uvcg_default_camera_w_ocular_focal_length.attr, - &uvcg_default_camera_bm_controls.attr, + &uvcg_default_camera_attr_b_terminal_id, + &uvcg_default_camera_attr_w_terminal_type, + &uvcg_default_camera_attr_b_assoc_terminal, + &uvcg_default_camera_attr_i_terminal, + &uvcg_default_camera_attr_w_objective_focal_length_min, + &uvcg_default_camera_attr_w_objective_focal_length_max, + &uvcg_default_camera_attr_w_ocular_focal_length, + &uvcg_default_camera_attr_bm_controls,NULL , };static struct config_item_type uvcg_default_camera_type = { - .ct_item_ops = &uvcg_default_camera_item_ops, .ct_attrs = uvcg_default_camera_attrs, .ct_owner =THIS_MODULE , };
@@ -450,17 +422,11 @@ static inline struct uvcg_default_output struct uvcg_default_output, group); } -CONFIGFS_ATTR_STRUCT (uvcg_default_output); -CONFIGFS_ATTR_OPS_RO (uvcg_default_output); - -static struct configfs_item_operations uvcg_default_output_item_ops = { - .show_attribute = uvcg_default_output_attr_show, -}; -#define UVCG_DEFAULT_OUTPUT_ATTR (cname, aname, conv) \ static ssize_t uvcg_default_output_##cname##_show( \ - struct uvcg_default_output *dout, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_default_output *dout = to_uvcg_default_output(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &dout->group.cg_subsys->su_mutex; \
@@ -483,9 +449,7 @@ static ssize_t uvcg_default_output_##cname##_show( \return result; \ } \ \ -static struct uvcg_default_output_attribute \ - uvcg_default_output_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_default_output_##cname##_show) +UVC_ATTR_RO(uvcg_default_output_, cname, aname)#define identity_conv (x) (x)
@@ -500,16 +464,15 @@ UVCG_DEFAULT_OUTPUT_ATTR(i_terminal, iTerminal, identity_conv);#undef UVCG_DEFAULT_OUTPUT_ATTRstatic struct configfs_attribute *uvcg_default_output_attrs[] = { - &uvcg_default_output_b_terminal_id.attr, - &uvcg_default_output_w_terminal_type.attr, - &uvcg_default_output_b_assoc_terminal.attr, - &uvcg_default_output_b_source_id.attr, - &uvcg_default_output_i_terminal.attr, + &uvcg_default_output_attr_b_terminal_id, + &uvcg_default_output_attr_w_terminal_type, + &uvcg_default_output_attr_b_assoc_terminal, + &uvcg_default_output_attr_b_source_id, + &uvcg_default_output_attr_i_terminal,NULL , };static struct config_item_type uvcg_default_output_type = { - .ct_item_ops = &uvcg_default_output_item_ops, .ct_attrs = uvcg_default_output_attrs, .ct_owner =THIS_MODULE , };
@@ -800,9 +763,6 @@ static struct uvcg_streaming_header *to_uvcg_streaming_header(struct config_item return container_of(item, struct uvcg_streaming_header, item); } -CONFIGFS_ATTR_STRUCT (uvcg_streaming_header); -CONFIGFS_ATTR_OPS (uvcg_streaming_header); -static int uvcg_streaming_header_allow_link (struct config_item *src,struct config_item *target) {
@@ -893,16 +853,15 @@ out: }static struct configfs_item_operations uvcg_streaming_header_item_ops = { - .show_attribute = uvcg_streaming_header_attr_show, - .store_attribute = uvcg_streaming_header_attr_store, .allow_link = uvcg_streaming_header_allow_link, .drop_link = uvcg_streaming_header_drop_link, };#define UVCG_STREAMING_HEADER_ATTR (cname, aname, conv) \ static ssize_t uvcg_streaming_header_##cname##_show( \ - struct uvcg_streaming_header *sh, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_streaming_header *sh = to_uvcg_streaming_header(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &sh->item.ci_group->cg_subsys->su_mutex;\
@@ -921,9 +880,7 @@ static ssize_t uvcg_streaming_header_##cname##_show( \return result; \ } \ \ -static struct uvcg_streaming_header_attribute \ - uvcg_streaming_header_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_streaming_header_##cname##_show) +UVC_ATTR_RO(uvcg_streaming_header_, cname, aname)#define identity_conv (x) (x)
@@ -939,11 +896,11 @@ UVCG_STREAMING_HEADER_ATTR(b_trigger_usage, bTriggerUsage, identity_conv);#undef UVCG_STREAMING_HEADER_ATTRstatic struct configfs_attribute *uvcg_streaming_header_attrs[] = { - &uvcg_streaming_header_bm_info.attr, - &uvcg_streaming_header_b_terminal_link.attr, - &uvcg_streaming_header_b_still_capture_method.attr, - &uvcg_streaming_header_b_trigger_support.attr, - &uvcg_streaming_header_b_trigger_usage.attr, + &uvcg_streaming_header_attr_bm_info, + &uvcg_streaming_header_attr_b_terminal_link, + &uvcg_streaming_header_attr_b_still_capture_method, + &uvcg_streaming_header_attr_b_trigger_support, + &uvcg_streaming_header_attr_b_trigger_usage,NULL , };
@@ -1022,17 +979,10 @@ static struct uvcg_frame *to_uvcg_frame(struct config_item *item) return container_of(item, struct uvcg_frame, item); } -CONFIGFS_ATTR_STRUCT (uvcg_frame); -CONFIGFS_ATTR_OPS (uvcg_frame); - -static struct configfs_item_operations uvcg_frame_item_ops = { - .show_attribute = uvcg_frame_attr_show, - .store_attribute = uvcg_frame_attr_store, -}; -#define UVCG_FRAME_ATTR (cname, aname, to_cpu_endian, to_little_endian, bits) \ -static ssize_t uvcg_frame_##cname##_show(struct uvcg_frame *f, char *page)\ +static ssize_t uvcg_frame_##cname##_show(struct config_item *item, char *page)\ { \ + struct uvcg_frame *f = to_uvcg_frame(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &f->item.ci_group->cg_subsys->su_mutex;\
@@ -1051,9 +1001,10 @@ static ssize_t uvcg_frame_##cname##_show(struct uvcg_frame *f, char *page)\return result; \ } \ \ -static ssize_t uvcg_frame_##cname##_store(struct uvcg_frame *f, \ +static ssize_t uvcg_frame_##cname##_store(struct config_item *item, \const char *page,size_t len)\ { \ +struct uvcg_frame *f =to_uvcg_frame (item); \struct f_uvc_opts *opts; \struct config_item *opts_item; \struct uvcg_format *fmt; \
@@ -1085,11 +1036,7 @@ end: \return ret; \ } \ \ -static struct uvcg_frame_attribute \ - uvcg_frame_##cname = \ - __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \ - uvcg_frame_##cname##_show, \ - uvcg_frame_##cname##_store) +UVC_ATTR (uvcg_frame_, cname, aname);#define noop_conversion (x) (x)
@@ -1108,9 +1055,10 @@ UVCG_FRAME_ATTR(dw_default_frame_interval, dwDefaultFrameInterval,#undef UVCG_FRAME_ATTR -static ssize_t uvcg_frame_dw_frame_interval_show (struct uvcg_frame *frm, +static ssize_t uvcg_frame_dw_frame_interval_show (struct config_item *item,char *page) { +struct uvcg_frame *frm =to_uvcg_frame (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct mutex *su_mutex = &frm->item.ci_group->cg_subsys->su_mutex;
@@ -1185,9 +1133,10 @@ static int __uvcg_iter_frm_intrv(const char *page, size_t len,return 0 ; } -static ssize_t uvcg_frame_dw_frame_interval_store (struct uvcg_frame *ch, +static ssize_t uvcg_frame_dw_frame_interval_store (struct config_item *item,const char *page,size_t len) { +struct uvcg_frame *ch =to_uvcg_frame (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct uvcg_format *fmt;
@@ -1234,26 +1183,21 @@ end:return ret; } -static struct uvcg_frame_attribute - uvcg_frame_dw_frame_interval = -__CONFIGFS_ATTR (dwFrameInterval,S_IRUGO |S_IWUSR , - uvcg_frame_dw_frame_interval_show, - uvcg_frame_dw_frame_interval_store); +UVC_ATTR (uvcg_frame_, dw_frame_interval, dwFrameInterval);static struct configfs_attribute *uvcg_frame_attrs[] = { - &uvcg_frame_bm_capabilities.attr, - &uvcg_frame_w_width.attr, - &uvcg_frame_w_height.attr, - &uvcg_frame_dw_min_bit_rate.attr, - &uvcg_frame_dw_max_bit_rate.attr, - &uvcg_frame_dw_max_video_frame_buffer_size.attr, - &uvcg_frame_dw_default_frame_interval.attr, - &uvcg_frame_dw_frame_interval.attr, + &uvcg_frame_attr_bm_capabilities, + &uvcg_frame_attr_w_width, + &uvcg_frame_attr_w_height, + &uvcg_frame_attr_dw_min_bit_rate, + &uvcg_frame_attr_dw_max_bit_rate, + &uvcg_frame_attr_dw_max_video_frame_buffer_size, + &uvcg_frame_attr_dw_default_frame_interval, + &uvcg_frame_attr_dw_frame_interval,NULL , };static struct config_item_type uvcg_frame_type = { - .ct_item_ops = &uvcg_frame_item_ops, .ct_attrs = uvcg_frame_attrs, .ct_owner =THIS_MODULE , };
@@ -1333,22 +1277,15 @@ static struct uvcg_uncompressed *to_uvcg_uncompressed(struct config_item *item) struct uvcg_uncompressed, fmt); } -CONFIGFS_ATTR_STRUCT (uvcg_uncompressed); -CONFIGFS_ATTR_OPS (uvcg_uncompressed); - -static struct configfs_item_operations uvcg_uncompressed_item_ops = { - .show_attribute = uvcg_uncompressed_attr_show, - .store_attribute = uvcg_uncompressed_attr_store, -}; -static struct configfs_group_operations uvcg_uncompressed_group_ops = { .make_item = uvcg_frame_make, .drop_item = uvcg_frame_drop, }; -static ssize_t uvcg_uncompressed_guid_format_show (struct uvcg_uncompressed *ch, +static ssize_t uvcg_uncompressed_guid_format_show (struct config_item *item,char *page) { +struct uvcg_uncompressed *ch =to_uvcg_uncompressed (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct mutex *su_mutex = &ch->fmt.group.cg_subsys->su_mutex;
@@ -1367,9 +1304,10 @@ static ssize_t uvcg_uncompressed_guid_format_show(struct uvcg_uncompressed *ch,return sizeof (ch->desc.guidFormat); } -static ssize_t uvcg_uncompressed_guid_format_store (struct uvcg_uncompressed *ch, +static ssize_t uvcg_uncompressed_guid_format_store (struct config_item *item,const char *page,size_t len) { +struct uvcg_uncompressed *ch =to_uvcg_uncompressed (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct mutex *su_mutex = &ch->fmt.group.cg_subsys->su_mutex;
@@ -1396,16 +1334,13 @@ end:return ret; } -static struct uvcg_uncompressed_attribute uvcg_uncompressed_guid_format = -__CONFIGFS_ATTR (guidFormat,S_IRUGO |S_IWUSR , - uvcg_uncompressed_guid_format_show, - uvcg_uncompressed_guid_format_store); - +UVC_ATTR (uvcg_uncompressed_, guid_format, guidFormat);#define UVCG_UNCOMPRESSED_ATTR_RO (cname, aname, conv) \ static ssize_t uvcg_uncompressed_##cname##_show( \ - struct uvcg_uncompressed *u, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_uncompressed *u = to_uvcg_uncompressed(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1424,14 +1359,13 @@ static ssize_t uvcg_uncompressed_##cname##_show( \return result; \ } \ \ -static struct uvcg_uncompressed_attribute \ - uvcg_uncompressed_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_uncompressed_##cname##_show) +UVC_ATTR_RO (uvcg_uncompressed_, cname, aname);#define UVCG_UNCOMPRESSED_ATTR (cname, aname, conv) \ static ssize_t uvcg_uncompressed_##cname##_show( \ - struct uvcg_uncompressed *u, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_uncompressed *u = to_uvcg_uncompressed(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1451,9 +1385,10 @@ static ssize_t uvcg_uncompressed_##cname##_show( \ } \ \static ssize_t \ -uvcg_uncompressed_##cname##_store(struct uvcg_uncompressed *u, \ +uvcg_uncompressed_##cname##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct uvcg_uncompressed *u =to_uvcg_uncompressed (item); \struct f_uvc_opts *opts; \struct config_item *opts_item; \struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1487,11 +1422,7 @@ end: \return ret; \ } \ \ -static struct uvcg_uncompressed_attribute \ - uvcg_uncompressed_##cname = \ - __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \ - uvcg_uncompressed_##cname##_show, \ - uvcg_uncompressed_##cname##_store) +UVC_ATTR (uvcg_uncompressed_, cname, aname);#define identity_conv (x) (x)
@@ -1508,36 +1439,34 @@ UVCG_UNCOMPRESSED_ATTR_RO(bm_interface_flags, bmInterfaceFlags, identity_conv);#undef UVCG_UNCOMPRESSED_ATTR_ROstatic inline ssize_t -uvcg_uncompressed_bma_controls_show (struct uvcg_uncompressed *unc,char *page) +uvcg_uncompressed_bma_controls_show (struct config_item *item,char *page) { +struct uvcg_uncompressed *unc =to_uvcg_uncompressed (item);return uvcg_format_bma_controls_show (&unc->fmt, page); }static inline ssize_t -uvcg_uncompressed_bma_controls_store (struct uvcg_uncompressed *ch, +uvcg_uncompressed_bma_controls_store (struct config_item *item,const char *page,size_t len) { -return uvcg_format_bma_controls_store (&ch->fmt, page, len); +struct uvcg_uncompressed *unc =to_uvcg_uncompressed (item); +return uvcg_format_bma_controls_store (&unc->fmt, page, len); } -static struct uvcg_uncompressed_attribute uvcg_uncompressed_bma_controls = -__CONFIGFS_ATTR (bmaControls,S_IRUGO |S_IWUSR , - uvcg_uncompressed_bma_controls_show, - uvcg_uncompressed_bma_controls_store); +UVC_ATTR (uvcg_uncompressed_, bma_controls, bmaControls);static struct configfs_attribute *uvcg_uncompressed_attrs[] = { - &uvcg_uncompressed_guid_format.attr, - &uvcg_uncompressed_b_bits_per_pixel.attr, - &uvcg_uncompressed_b_default_frame_index.attr, - &uvcg_uncompressed_b_aspect_ratio_x.attr, - &uvcg_uncompressed_b_aspect_ratio_y.attr, - &uvcg_uncompressed_bm_interface_flags.attr, - &uvcg_uncompressed_bma_controls.attr, + &uvcg_uncompressed_attr_guid_format, + &uvcg_uncompressed_attr_b_bits_per_pixel, + &uvcg_uncompressed_attr_b_default_frame_index, + &uvcg_uncompressed_attr_b_aspect_ratio_x, + &uvcg_uncompressed_attr_b_aspect_ratio_y, + &uvcg_uncompressed_attr_bm_interface_flags, + &uvcg_uncompressed_attr_bma_controls,NULL , };static struct config_item_type uvcg_uncompressed_type = { - .ct_item_ops = &uvcg_uncompressed_item_ops, .ct_group_ops = &uvcg_uncompressed_group_ops, .ct_attrs = uvcg_uncompressed_attrs, .ct_owner =THIS_MODULE ,
@@ -1605,22 +1534,15 @@ static struct uvcg_mjpeg *to_uvcg_mjpeg(struct config_item *item) struct uvcg_mjpeg, fmt); } -CONFIGFS_ATTR_STRUCT (uvcg_mjpeg); -CONFIGFS_ATTR_OPS (uvcg_mjpeg); - -static struct configfs_item_operations uvcg_mjpeg_item_ops = { - .show_attribute = uvcg_mjpeg_attr_show, - .store_attribute = uvcg_mjpeg_attr_store, -}; -static struct configfs_group_operations uvcg_mjpeg_group_ops = { .make_item = uvcg_frame_make, .drop_item = uvcg_frame_drop, };#define UVCG_MJPEG_ATTR_RO (cname, aname, conv) \ -static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\ +static ssize_t uvcg_mjpeg_##cname##_show(struct config_item *item, char *page)\ { \ + struct uvcg_mjpeg *u = to_uvcg_mjpeg(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1639,13 +1561,12 @@ static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\return result; \ } \ \ -static struct uvcg_mjpeg_attribute \ - uvcg_mjpeg_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_mjpeg_##cname##_show) +UVC_ATTR_RO(uvcg_mjpeg_, cname, aname)#define UVCG_MJPEG_ATTR (cname, aname, conv) \ -static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\ +static ssize_t uvcg_mjpeg_##cname##_show(struct config_item *item, char *page)\ { \ + struct uvcg_mjpeg *u = to_uvcg_mjpeg(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1665,9 +1586,10 @@ static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\ } \ \static ssize_t \ -uvcg_mjpeg_##cname##_store(struct uvcg_mjpeg *u, \ +uvcg_mjpeg_##cname##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct uvcg_mjpeg *u =to_uvcg_mjpeg (item); \struct f_uvc_opts *opts; \struct config_item *opts_item; \struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1701,11 +1623,7 @@ end: \return ret; \ } \ \ -static struct uvcg_mjpeg_attribute \ - uvcg_mjpeg_##cname = \ - __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \ - uvcg_mjpeg_##cname##_show, \ - uvcg_mjpeg_##cname##_store) +UVC_ATTR(uvcg_mjpeg_, cname, aname)#define identity_conv (x) (x)
@@ -1722,35 +1640,33 @@ UVCG_MJPEG_ATTR_RO(bm_interface_flags, bmInterfaceFlags, identity_conv);#undef UVCG_MJPEG_ATTR_ROstatic inline ssize_t -uvcg_mjpeg_bma_controls_show (struct uvcg_mjpeg *unc,char *page) +uvcg_mjpeg_bma_controls_show (struct config_item *item,char *page) { -return uvcg_format_bma_controls_show (&unc->fmt, page); +struct uvcg_mjpeg *u =to_uvcg_mjpeg (item); +return uvcg_format_bma_controls_show (&u->fmt, page); }static inline ssize_t -uvcg_mjpeg_bma_controls_store (struct uvcg_mjpeg *ch, +uvcg_mjpeg_bma_controls_store (struct config_item *item,const char *page,size_t len) { -return uvcg_format_bma_controls_store (&ch->fmt, page, len); +struct uvcg_mjpeg *u =to_uvcg_mjpeg (item); +return uvcg_format_bma_controls_store (&u->fmt, page, len); } -static struct uvcg_mjpeg_attribute uvcg_mjpeg_bma_controls = -__CONFIGFS_ATTR (bmaControls,S_IRUGO |S_IWUSR , - uvcg_mjpeg_bma_controls_show, - uvcg_mjpeg_bma_controls_store); +UVC_ATTR (uvcg_mjpeg_, bma_controls, bmaControls);static struct configfs_attribute *uvcg_mjpeg_attrs[] = { - &uvcg_mjpeg_b_default_frame_index.attr, - &uvcg_mjpeg_bm_flags.attr, - &uvcg_mjpeg_b_aspect_ratio_x.attr, - &uvcg_mjpeg_b_aspect_ratio_y.attr, - &uvcg_mjpeg_bm_interface_flags.attr, - &uvcg_mjpeg_bma_controls.attr, + &uvcg_mjpeg_attr_b_default_frame_index, + &uvcg_mjpeg_attr_bm_flags, + &uvcg_mjpeg_attr_b_aspect_ratio_x, + &uvcg_mjpeg_attr_b_aspect_ratio_y, + &uvcg_mjpeg_attr_bm_interface_flags, + &uvcg_mjpeg_attr_bma_controls,NULL , };static struct config_item_type uvcg_mjpeg_type = { - .ct_item_ops = &uvcg_mjpeg_item_ops, .ct_group_ops = &uvcg_mjpeg_group_ops, .ct_attrs = uvcg_mjpeg_attrs, .ct_owner =THIS_MODULE ,
@@ -1811,17 +1727,12 @@ static inline struct uvcg_default_color_matching struct uvcg_default_color_matching, group); } -CONFIGFS_ATTR_STRUCT (uvcg_default_color_matching); -CONFIGFS_ATTR_OPS_RO (uvcg_default_color_matching); - -static struct configfs_item_operations uvcg_default_color_matching_item_ops = { - .show_attribute = uvcg_default_color_matching_attr_show, -}; -#define UVCG_DEFAULT_COLOR_MATCHING_ATTR (cname, aname, conv) \ static ssize_t uvcg_default_color_matching_##cname##_show( \ - struct uvcg_default_color_matching *dc, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_default_color_matching *dc = \ + to_uvcg_default_color_matching(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; \
@@ -1842,9 +1753,7 @@ static ssize_t uvcg_default_color_matching_##cname##_show( \return result; \ } \ \ -static struct uvcg_default_color_matching_attribute \ - uvcg_default_color_matching_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_default_color_matching_##cname##_show) +UVC_ATTR_RO(uvcg_default_color_matching_, cname, aname)#define identity_conv (x) (x)
@@ -1860,14 +1769,13 @@ UVCG_DEFAULT_COLOR_MATCHING_ATTR(b_matrix_coefficients, bMatrixCoefficients,#undef UVCG_DEFAULT_COLOR_MATCHING_ATTRstatic struct configfs_attribute *uvcg_default_color_matching_attrs[] = { - &uvcg_default_color_matching_b_color_primaries.attr, - &uvcg_default_color_matching_b_transfer_characteristics.attr, - &uvcg_default_color_matching_b_matrix_coefficients.attr, + &uvcg_default_color_matching_attr_b_color_primaries, + &uvcg_default_color_matching_attr_b_transfer_characteristics, + &uvcg_default_color_matching_attr_b_matrix_coefficients,NULL , };static struct config_item_type uvcg_default_color_matching_type = { - .ct_item_ops = &uvcg_default_color_matching_item_ops, .ct_attrs = uvcg_default_color_matching_attrs, .ct_owner =THIS_MODULE , };
@@ -2285,9 +2193,6 @@ static inline struct f_uvc_opts *to_f_uvc_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_uvc_opts); -CONFIGFS_ATTR_OPS (f_uvc_opts); -static void uvc_attr_release (struct config_item *item) {struct f_uvc_opts *opts =to_f_uvc_opts (item);
@@ -2297,14 +2202,13 @@ static void uvc_attr_release(struct config_item *item)static struct configfs_item_operations uvc_item_ops = { .release = uvc_attr_release, - .show_attribute = f_uvc_opts_attr_show, - .store_attribute = f_uvc_opts_attr_store, };#define UVCG_OPTS_ATTR (cname, conv, str2u, uxx, vnoc, limit) \ static ssize_t f_uvc_opts_##cname##_show( \ - struct f_uvc_opts *opts, char *page) \ + struct config_item *item, char *page) \ { \ + struct f_uvc_opts *opts = to_f_uvc_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \
@@ -2315,9 +2219,10 @@ static ssize_t f_uvc_opts_##cname##_show( \ } \ \static ssize_t \ -f_uvc_opts_##cname##_store(struct f_uvc_opts *opts, \ +f_uvc_opts_##cname##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct f_uvc_opts *opts =to_f_uvc_opts (item); \int ret; \uxx num; \ \
@@ -2342,11 +2247,7 @@ end: \return ret; \ } \ \ -static struct f_uvc_opts_attribute \ - f_uvc_opts_attribute_##cname = \ - __CONFIGFS_ATTR(cname, S_IRUGO | S_IWUSR, \ - f_uvc_opts_##cname##_show, \ - f_uvc_opts_##cname##_store) +UVC_ATTR(f_uvc_opts_, cname, aname)#define identity_conv (x) (x)
@@ -2362,9 +2263,9 @@ UVCG_OPTS_ATTR(streaming_maxburst, identity_conv, kstrtou8, u8, identity_conv,#undef UVCG_OPTS_ATTRstatic struct configfs_attribute *uvc_attrs[] = { - &f_uvc_opts_attribute_streaming_interval.attr, - &f_uvc_opts_attribute_streaming_maxpacket.attr, - &f_uvc_opts_attribute_streaming_maxburst.attr, + &f_uvc_opts_attr_streaming_interval, + &f_uvc_opts_attr_streaming_maxpacket, + &f_uvc_opts_attr_streaming_maxburst,NULL , };
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 1443189000-13398-4-git-send-email-hch-jcswGhMUV9g@public.gmane.org
Andrzej Pietrasiewicz
Reviewed-byRe: [PATCH 03/23] usb-gadget/uvc: use per-attribute show and store methods
Hi Christoph,
please see my comments inline.
With the issues addressed you can add
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 15 lines
UVC is a little different from other configfs consumers in that it wants different function and field names from the exposed attribute name, so it keeps it's local macros to define attributes instead of using the common ones.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/usb/gadget/function/uvc_configfs.c | 391 +++++++++++------------------ 1 file changed, 146 insertions(+), 245 deletions(-)drivers/usb/gadget/function/uvc_configfs.c +0
-0
drivers/usb/gadget/function/uvc_configfs.c line 18
Quoted 4 lines
drivers/usb/gadget/function/uvc_configfs.c +0
-1@@ -15,23 +15,27 @@#include "u_uvc.h" #include "uvc_configfs.h" -#define UVCG_STREAMING_CONTROL_SIZE 1
Moving this define seems an unrelated change to me.
Quoted 21 lines
drivers/usb/gadget/function/uvc_configfs.c +8
-12+#define UVC_ATTR (prefix, cname, aname) \ +static struct configfs_attribute prefix##attr_##cname = { \ + .ca_name = __stringify(aname), \ + .ca_mode = S_IRUGO, \ + .ca_owner = THIS_MODULE, \ + .show = prefix##cname##_show, \ + .store = prefix##cname##_store, \ +} -#define CONFIGFS_ATTR_OPS_RO (_item) \ -static ssize_t _item##_attr_show(struct config_item *item, \ - struct configfs_attribute *attr, \ - char *page) \ -{ \ - struct _item *_item = to_##_item(item); \ - struct _item##_attribute *_item##_attr = \ - container_of(attr, struct _item##_attribute, attr); \ - ssize_t ret = 0; \ - \ - if (_item##_attr->show) \ - ret = _item##_attr->show(_item, page); \
drivers/usb/gadget/function/uvc_configfs.c line 35
Quoted 10 lines
drivers/usb/gadget/function/uvc_configfs.c +7
-1-return ret; \ +#define UVC_ATTR_RO (prefix, cname, aname) \ +static struct configfs_attribute prefix##attr_##cname = { \ + .ca_name = __stringify(aname), \ + .ca_mode = S_IRUGO, \ + .ca_owner = THIS_MODULE, \ + .show = prefix##cname##_show, \ } +#define identity_conv (x) (x)
What is this needed for here?
This #define is not used near the place it is defined. Throughout the file the identity_conv is being defined multiple times, each time near the place it is used and then undefined.
Without this line the code still compiles.
Quoted 812 lines
drivers/usb/gadget/function/uvc_configfs.c +131
-231+ +#define UVCG_STREAMING_CONTROL_SIZE 1 +static inline struct f_uvc_opts *to_f_uvc_opts (struct config_item *item);/* control/header/<NAME> */ @@ -48,18 +52,11 @@ static struct uvcg_control_header *to_uvcg_control_header(struct config_item *it return container_of(item, struct uvcg_control_header, item); } -CONFIGFS_ATTR_STRUCT (uvcg_control_header); -CONFIGFS_ATTR_OPS (uvcg_control_header); - -static struct configfs_item_operations uvcg_control_header_item_ops = { - .show_attribute = uvcg_control_header_attr_show, - .store_attribute = uvcg_control_header_attr_store, -}; -#define UVCG_CTRL_HDR_ATTR (cname, aname, conv, str2u, uxx, vnoc, limit) \ static ssize_t uvcg_control_header_##cname##_show( \ - struct uvcg_control_header *ch, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_control_header *ch = to_uvcg_control_header(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &ch->item.ci_group->cg_subsys->su_mutex;\@@ -79,9 +76,10 @@ static ssize_t uvcg_control_header_##cname##_show( \ } \ \static ssize_t \ -uvcg_control_header_##cname##_store(struct uvcg_control_header *ch, \ +uvcg_control_header_##cname##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct uvcg_control_header *ch =to_uvcg_control_header (item); \struct f_uvc_opts *opts; \struct config_item *opts_item; \struct mutex *su_mutex = &ch->item.ci_group->cg_subsys->su_mutex;\@@ -115,11 +113,7 @@ end: \return ret; \ } \ \ -static struct uvcg_control_header_attribute \ - uvcg_control_header_##cname = \ - __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \ - uvcg_control_header_##cname##_show, \ - uvcg_control_header_##cname##_store) +UVC_ATTR(uvcg_control_header_, cname, aname)UVCG_CTRL_HDR_ATTR (bcd_uvc, bcdUVC, le16_to_cpu, kstrtou16, u16, cpu_to_le16,0xffff );@@ -130,13 +124,12 @@ UVCG_CTRL_HDR_ATTR(dw_clock_frequency, dwClockFrequency, le32_to_cpu, kstrtou32,#undef UVCG_CTRL_HDR_ATTRstatic struct configfs_attribute *uvcg_control_header_attrs[] = { - &uvcg_control_header_bcd_uvc.attr, - &uvcg_control_header_dw_clock_frequency.attr, + &uvcg_control_header_attr_bcd_uvc, + &uvcg_control_header_attr_dw_clock_frequency,NULL , };static struct config_item_type uvcg_control_header_type = { - .ct_item_ops = &uvcg_control_header_item_ops, .ct_attrs = uvcg_control_header_attrs, .ct_owner =THIS_MODULE , };@@ -196,17 +189,11 @@ static inline struct uvcg_default_processing struct uvcg_default_processing, group); } -CONFIGFS_ATTR_STRUCT (uvcg_default_processing); -CONFIGFS_ATTR_OPS_RO (uvcg_default_processing); - -static struct configfs_item_operations uvcg_default_processing_item_ops = { - .show_attribute = uvcg_default_processing_attr_show, -}; -#define UVCG_DEFAULT_PROCESSING_ATTR (cname, aname, conv) \ static ssize_t uvcg_default_processing_##cname##_show( \ - struct uvcg_default_processing *dp, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_default_processing *dp = to_uvcg_default_processing(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &dp->group.cg_subsys->su_mutex; \@@ -227,9 +214,7 @@ static ssize_t uvcg_default_processing_##cname##_show( \return result; \ } \ \ -static struct uvcg_default_processing_attribute \ - uvcg_default_processing_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_default_processing_##cname##_show) +UVC_ATTR_RO(uvcg_default_processing_, cname, aname)#define identity_conv (x) (x)@@ -243,8 +228,9 @@ UVCG_DEFAULT_PROCESSING_ATTR(i_processing, iProcessing, identity_conv);#undef UVCG_DEFAULT_PROCESSING_ATTRstatic ssize_t uvcg_default_processing_bm_controls_show ( -struct uvcg_default_processing *dp,char *page) +struct config_item *item,char *page) { +struct uvcg_default_processing *dp =to_uvcg_default_processing (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct mutex *su_mutex = &dp->group.cg_subsys->su_mutex;@@ -270,22 +256,18 @@ static ssize_t uvcg_default_processing_bm_controls_show(return result; } -static struct uvcg_default_processing_attribute - uvcg_default_processing_bm_controls = -__CONFIGFS_ATTR_RO (bmControls, - uvcg_default_processing_bm_controls_show); +UVC_ATTR_RO (uvcg_default_processing_, bm_controls, bmControls);static struct configfs_attribute *uvcg_default_processing_attrs[] = { - &uvcg_default_processing_b_unit_id.attr, - &uvcg_default_processing_b_source_id.attr, - &uvcg_default_processing_w_max_multiplier.attr, - &uvcg_default_processing_bm_controls.attr, - &uvcg_default_processing_i_processing.attr, + &uvcg_default_processing_attr_b_unit_id, + &uvcg_default_processing_attr_b_source_id, + &uvcg_default_processing_attr_w_max_multiplier, + &uvcg_default_processing_attr_bm_controls, + &uvcg_default_processing_attr_i_processing,NULL , };static struct config_item_type uvcg_default_processing_type = { - .ct_item_ops = &uvcg_default_processing_item_ops, .ct_attrs = uvcg_default_processing_attrs, .ct_owner =THIS_MODULE , };@@ -318,17 +300,11 @@ static inline struct uvcg_default_camera struct uvcg_default_camera, group); } -CONFIGFS_ATTR_STRUCT (uvcg_default_camera); -CONFIGFS_ATTR_OPS_RO (uvcg_default_camera); - -static struct configfs_item_operations uvcg_default_camera_item_ops = { - .show_attribute = uvcg_default_camera_attr_show, -}; -#define UVCG_DEFAULT_CAMERA_ATTR (cname, aname, conv) \ static ssize_t uvcg_default_camera_##cname##_show( \ - struct uvcg_default_camera *dc, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_default_camera *dc = to_uvcg_default_camera(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; \@@ -351,9 +327,7 @@ static ssize_t uvcg_default_camera_##cname##_show( \return result; \ } \ \ -static struct uvcg_default_camera_attribute \ - uvcg_default_camera_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_default_camera_##cname##_show) +UVC_ATTR_RO(uvcg_default_camera_, cname, aname)#define identity_conv (x) (x)@@ -373,8 +347,9 @@ UVCG_DEFAULT_CAMERA_ATTR(w_ocular_focal_length, wOcularFocalLength,#undef UVCG_DEFAULT_CAMERA_ATTRstatic ssize_t uvcg_default_camera_bm_controls_show ( -struct uvcg_default_camera *dc,char *page) +struct config_item *item,char *page) { +struct uvcg_default_camera *dc =to_uvcg_default_camera (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex;@@ -400,24 +375,21 @@ static ssize_t uvcg_default_camera_bm_controls_show(return result; } -static struct uvcg_default_camera_attribute - uvcg_default_camera_bm_controls = -__CONFIGFS_ATTR_RO (bmControls, uvcg_default_camera_bm_controls_show); +UVC_ATTR_RO (uvcg_default_camera_, bm_controls, bmControls);static struct configfs_attribute *uvcg_default_camera_attrs[] = { - &uvcg_default_camera_b_terminal_id.attr, - &uvcg_default_camera_w_terminal_type.attr, - &uvcg_default_camera_b_assoc_terminal.attr, - &uvcg_default_camera_i_terminal.attr, - &uvcg_default_camera_w_objective_focal_length_min.attr, - &uvcg_default_camera_w_objective_focal_length_max.attr, - &uvcg_default_camera_w_ocular_focal_length.attr, - &uvcg_default_camera_bm_controls.attr, + &uvcg_default_camera_attr_b_terminal_id, + &uvcg_default_camera_attr_w_terminal_type, + &uvcg_default_camera_attr_b_assoc_terminal, + &uvcg_default_camera_attr_i_terminal, + &uvcg_default_camera_attr_w_objective_focal_length_min, + &uvcg_default_camera_attr_w_objective_focal_length_max, + &uvcg_default_camera_attr_w_ocular_focal_length, + &uvcg_default_camera_attr_bm_controls,NULL , };static struct config_item_type uvcg_default_camera_type = { - .ct_item_ops = &uvcg_default_camera_item_ops, .ct_attrs = uvcg_default_camera_attrs, .ct_owner =THIS_MODULE , };@@ -450,17 +422,11 @@ static inline struct uvcg_default_output struct uvcg_default_output, group); } -CONFIGFS_ATTR_STRUCT (uvcg_default_output); -CONFIGFS_ATTR_OPS_RO (uvcg_default_output); - -static struct configfs_item_operations uvcg_default_output_item_ops = { - .show_attribute = uvcg_default_output_attr_show, -}; -#define UVCG_DEFAULT_OUTPUT_ATTR (cname, aname, conv) \ static ssize_t uvcg_default_output_##cname##_show( \ - struct uvcg_default_output *dout, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_default_output *dout = to_uvcg_default_output(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &dout->group.cg_subsys->su_mutex; \@@ -483,9 +449,7 @@ static ssize_t uvcg_default_output_##cname##_show( \return result; \ } \ \ -static struct uvcg_default_output_attribute \ - uvcg_default_output_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_default_output_##cname##_show) +UVC_ATTR_RO(uvcg_default_output_, cname, aname)#define identity_conv (x) (x)@@ -500,16 +464,15 @@ UVCG_DEFAULT_OUTPUT_ATTR(i_terminal, iTerminal, identity_conv);#undef UVCG_DEFAULT_OUTPUT_ATTRstatic struct configfs_attribute *uvcg_default_output_attrs[] = { - &uvcg_default_output_b_terminal_id.attr, - &uvcg_default_output_w_terminal_type.attr, - &uvcg_default_output_b_assoc_terminal.attr, - &uvcg_default_output_b_source_id.attr, - &uvcg_default_output_i_terminal.attr, + &uvcg_default_output_attr_b_terminal_id, + &uvcg_default_output_attr_w_terminal_type, + &uvcg_default_output_attr_b_assoc_terminal, + &uvcg_default_output_attr_b_source_id, + &uvcg_default_output_attr_i_terminal,NULL , };static struct config_item_type uvcg_default_output_type = { - .ct_item_ops = &uvcg_default_output_item_ops, .ct_attrs = uvcg_default_output_attrs, .ct_owner =THIS_MODULE , };@@ -800,9 +763,6 @@ static struct uvcg_streaming_header *to_uvcg_streaming_header(struct config_item return container_of(item, struct uvcg_streaming_header, item); } -CONFIGFS_ATTR_STRUCT (uvcg_streaming_header); -CONFIGFS_ATTR_OPS (uvcg_streaming_header); -static int uvcg_streaming_header_allow_link (struct config_item *src,struct config_item *target) {@@ -893,16 +853,15 @@ out: }static struct configfs_item_operations uvcg_streaming_header_item_ops = { - .show_attribute = uvcg_streaming_header_attr_show, - .store_attribute = uvcg_streaming_header_attr_store, .allow_link = uvcg_streaming_header_allow_link, .drop_link = uvcg_streaming_header_drop_link, };#define UVCG_STREAMING_HEADER_ATTR (cname, aname, conv) \ static ssize_t uvcg_streaming_header_##cname##_show( \ - struct uvcg_streaming_header *sh, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_streaming_header *sh = to_uvcg_streaming_header(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &sh->item.ci_group->cg_subsys->su_mutex;\@@ -921,9 +880,7 @@ static ssize_t uvcg_streaming_header_##cname##_show( \return result; \ } \ \ -static struct uvcg_streaming_header_attribute \ - uvcg_streaming_header_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_streaming_header_##cname##_show) +UVC_ATTR_RO(uvcg_streaming_header_, cname, aname)#define identity_conv (x) (x)@@ -939,11 +896,11 @@ UVCG_STREAMING_HEADER_ATTR(b_trigger_usage, bTriggerUsage, identity_conv);#undef UVCG_STREAMING_HEADER_ATTRstatic struct configfs_attribute *uvcg_streaming_header_attrs[] = { - &uvcg_streaming_header_bm_info.attr, - &uvcg_streaming_header_b_terminal_link.attr, - &uvcg_streaming_header_b_still_capture_method.attr, - &uvcg_streaming_header_b_trigger_support.attr, - &uvcg_streaming_header_b_trigger_usage.attr, + &uvcg_streaming_header_attr_bm_info, + &uvcg_streaming_header_attr_b_terminal_link, + &uvcg_streaming_header_attr_b_still_capture_method, + &uvcg_streaming_header_attr_b_trigger_support, + &uvcg_streaming_header_attr_b_trigger_usage,NULL , };@@ -1022,17 +979,10 @@ static struct uvcg_frame *to_uvcg_frame(struct config_item *item) return container_of(item, struct uvcg_frame, item); } -CONFIGFS_ATTR_STRUCT (uvcg_frame); -CONFIGFS_ATTR_OPS (uvcg_frame); - -static struct configfs_item_operations uvcg_frame_item_ops = { - .show_attribute = uvcg_frame_attr_show, - .store_attribute = uvcg_frame_attr_store, -}; -#define UVCG_FRAME_ATTR (cname, aname, to_cpu_endian, to_little_endian, bits) \ -static ssize_t uvcg_frame_##cname##_show(struct uvcg_frame *f, char *page)\ +static ssize_t uvcg_frame_##cname##_show(struct config_item *item, char *page)\ { \ + struct uvcg_frame *f = to_uvcg_frame(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &f->item.ci_group->cg_subsys->su_mutex;\@@ -1051,9 +1001,10 @@ static ssize_t uvcg_frame_##cname##_show(struct uvcg_frame *f, char *page)\return result; \ } \ \ -static ssize_t uvcg_frame_##cname##_store(struct uvcg_frame *f, \ +static ssize_t uvcg_frame_##cname##_store(struct config_item *item, \const char *page,size_t len)\ { \ +struct uvcg_frame *f =to_uvcg_frame (item); \struct f_uvc_opts *opts; \struct config_item *opts_item; \struct uvcg_format *fmt; \@@ -1085,11 +1036,7 @@ end: \return ret; \ } \ \ -static struct uvcg_frame_attribute \ - uvcg_frame_##cname = \ - __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \ - uvcg_frame_##cname##_show, \ - uvcg_frame_##cname##_store) +UVC_ATTR (uvcg_frame_, cname, aname);#define noop_conversion (x) (x)@@ -1108,9 +1055,10 @@ UVCG_FRAME_ATTR(dw_default_frame_interval, dwDefaultFrameInterval,#undef UVCG_FRAME_ATTR -static ssize_t uvcg_frame_dw_frame_interval_show (struct uvcg_frame *frm, +static ssize_t uvcg_frame_dw_frame_interval_show (struct config_item *item,char *page) { +struct uvcg_frame *frm =to_uvcg_frame (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct mutex *su_mutex = &frm->item.ci_group->cg_subsys->su_mutex;@@ -1185,9 +1133,10 @@ static int __uvcg_iter_frm_intrv(const char *page, size_t len,return 0 ; } -static ssize_t uvcg_frame_dw_frame_interval_store (struct uvcg_frame *ch, +static ssize_t uvcg_frame_dw_frame_interval_store (struct config_item *item,const char *page,size_t len) { +struct uvcg_frame *ch =to_uvcg_frame (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct uvcg_format *fmt;@@ -1234,26 +1183,21 @@ end:return ret; } -static struct uvcg_frame_attribute - uvcg_frame_dw_frame_interval = -__CONFIGFS_ATTR (dwFrameInterval,S_IRUGO |S_IWUSR , - uvcg_frame_dw_frame_interval_show, - uvcg_frame_dw_frame_interval_store); +UVC_ATTR (uvcg_frame_, dw_frame_interval, dwFrameInterval);static struct configfs_attribute *uvcg_frame_attrs[] = { - &uvcg_frame_bm_capabilities.attr, - &uvcg_frame_w_width.attr, - &uvcg_frame_w_height.attr, - &uvcg_frame_dw_min_bit_rate.attr, - &uvcg_frame_dw_max_bit_rate.attr, - &uvcg_frame_dw_max_video_frame_buffer_size.attr, - &uvcg_frame_dw_default_frame_interval.attr, - &uvcg_frame_dw_frame_interval.attr, + &uvcg_frame_attr_bm_capabilities, + &uvcg_frame_attr_w_width, + &uvcg_frame_attr_w_height, + &uvcg_frame_attr_dw_min_bit_rate, + &uvcg_frame_attr_dw_max_bit_rate, + &uvcg_frame_attr_dw_max_video_frame_buffer_size, + &uvcg_frame_attr_dw_default_frame_interval, + &uvcg_frame_attr_dw_frame_interval,NULL , };static struct config_item_type uvcg_frame_type = { - .ct_item_ops = &uvcg_frame_item_ops, .ct_attrs = uvcg_frame_attrs, .ct_owner =THIS_MODULE , };@@ -1333,22 +1277,15 @@ static struct uvcg_uncompressed *to_uvcg_uncompressed(struct config_item *item) struct uvcg_uncompressed, fmt); } -CONFIGFS_ATTR_STRUCT (uvcg_uncompressed); -CONFIGFS_ATTR_OPS (uvcg_uncompressed); - -static struct configfs_item_operations uvcg_uncompressed_item_ops = { - .show_attribute = uvcg_uncompressed_attr_show, - .store_attribute = uvcg_uncompressed_attr_store, -}; -static struct configfs_group_operations uvcg_uncompressed_group_ops = { .make_item = uvcg_frame_make, .drop_item = uvcg_frame_drop, }; -static ssize_t uvcg_uncompressed_guid_format_show (struct uvcg_uncompressed *ch, +static ssize_t uvcg_uncompressed_guid_format_show (struct config_item *item,char *page) { +struct uvcg_uncompressed *ch =to_uvcg_uncompressed (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct mutex *su_mutex = &ch->fmt.group.cg_subsys->su_mutex;@@ -1367,9 +1304,10 @@ static ssize_t uvcg_uncompressed_guid_format_show(struct uvcg_uncompressed *ch,return sizeof (ch->desc.guidFormat); } -static ssize_t uvcg_uncompressed_guid_format_store (struct uvcg_uncompressed *ch, +static ssize_t uvcg_uncompressed_guid_format_store (struct config_item *item,const char *page,size_t len) { +struct uvcg_uncompressed *ch =to_uvcg_uncompressed (item);struct f_uvc_opts *opts;struct config_item *opts_item;struct mutex *su_mutex = &ch->fmt.group.cg_subsys->su_mutex;@@ -1396,16 +1334,13 @@ end:return ret; } -static struct uvcg_uncompressed_attribute uvcg_uncompressed_guid_format = -__CONFIGFS_ATTR (guidFormat,S_IRUGO |S_IWUSR , - uvcg_uncompressed_guid_format_show, - uvcg_uncompressed_guid_format_store); - +UVC_ATTR (uvcg_uncompressed_, guid_format, guidFormat);#define UVCG_UNCOMPRESSED_ATTR_RO (cname, aname, conv) \ static ssize_t uvcg_uncompressed_##cname##_show( \ - struct uvcg_uncompressed *u, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_uncompressed *u = to_uvcg_uncompressed(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \@@ -1424,14 +1359,13 @@ static ssize_t uvcg_uncompressed_##cname##_show( \return result; \ } \ \ -static struct uvcg_uncompressed_attribute \ - uvcg_uncompressed_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_uncompressed_##cname##_show) +UVC_ATTR_RO (uvcg_uncompressed_, cname, aname);#define UVCG_UNCOMPRESSED_ATTR (cname, aname, conv) \ static ssize_t uvcg_uncompressed_##cname##_show( \ - struct uvcg_uncompressed *u, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_uncompressed *u = to_uvcg_uncompressed(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \@@ -1451,9 +1385,10 @@ static ssize_t uvcg_uncompressed_##cname##_show( \ } \ \static ssize_t \ -uvcg_uncompressed_##cname##_store(struct uvcg_uncompressed *u, \ +uvcg_uncompressed_##cname##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct uvcg_uncompressed *u =to_uvcg_uncompressed (item); \struct f_uvc_opts *opts; \struct config_item *opts_item; \struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \@@ -1487,11 +1422,7 @@ end: \return ret; \ } \ \ -static struct uvcg_uncompressed_attribute \ - uvcg_uncompressed_##cname = \ - __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \ - uvcg_uncompressed_##cname##_show, \ - uvcg_uncompressed_##cname##_store) +UVC_ATTR (uvcg_uncompressed_, cname, aname);#define identity_conv (x) (x)@@ -1508,36 +1439,34 @@ UVCG_UNCOMPRESSED_ATTR_RO(bm_interface_flags, bmInterfaceFlags, identity_conv);#undef UVCG_UNCOMPRESSED_ATTR_ROstatic inline ssize_t -uvcg_uncompressed_bma_controls_show (struct uvcg_uncompressed *unc,char *page) +uvcg_uncompressed_bma_controls_show (struct config_item *item,char *page) { +struct uvcg_uncompressed *unc =to_uvcg_uncompressed (item);return uvcg_format_bma_controls_show (&unc->fmt, page); }static inline ssize_t -uvcg_uncompressed_bma_controls_store (struct uvcg_uncompressed *ch, +uvcg_uncompressed_bma_controls_store (struct config_item *item,const char *page,size_t len) { -return uvcg_format_bma_controls_store (&ch->fmt, page, len); +struct uvcg_uncompressed *unc =to_uvcg_uncompressed (item); +return uvcg_format_bma_controls_store (&unc->fmt, page, len); } -static struct uvcg_uncompressed_attribute uvcg_uncompressed_bma_controls = -__CONFIGFS_ATTR (bmaControls,S_IRUGO |S_IWUSR , - uvcg_uncompressed_bma_controls_show, - uvcg_uncompressed_bma_controls_store); +UVC_ATTR (uvcg_uncompressed_, bma_controls, bmaControls);static struct configfs_attribute *uvcg_uncompressed_attrs[] = { - &uvcg_uncompressed_guid_format.attr, - &uvcg_uncompressed_b_bits_per_pixel.attr, - &uvcg_uncompressed_b_default_frame_index.attr, - &uvcg_uncompressed_b_aspect_ratio_x.attr, - &uvcg_uncompressed_b_aspect_ratio_y.attr, - &uvcg_uncompressed_bm_interface_flags.attr, - &uvcg_uncompressed_bma_controls.attr, + &uvcg_uncompressed_attr_guid_format, + &uvcg_uncompressed_attr_b_bits_per_pixel, + &uvcg_uncompressed_attr_b_default_frame_index, + &uvcg_uncompressed_attr_b_aspect_ratio_x, + &uvcg_uncompressed_attr_b_aspect_ratio_y, + &uvcg_uncompressed_attr_bm_interface_flags, + &uvcg_uncompressed_attr_bma_controls,NULL , };static struct config_item_type uvcg_uncompressed_type = { - .ct_item_ops = &uvcg_uncompressed_item_ops, .ct_group_ops = &uvcg_uncompressed_group_ops, .ct_attrs = uvcg_uncompressed_attrs, .ct_owner =THIS_MODULE ,@@ -1605,22 +1534,15 @@ static struct uvcg_mjpeg *to_uvcg_mjpeg(struct config_item *item) struct uvcg_mjpeg, fmt); } -CONFIGFS_ATTR_STRUCT (uvcg_mjpeg); -CONFIGFS_ATTR_OPS (uvcg_mjpeg); - -static struct configfs_item_operations uvcg_mjpeg_item_ops = { - .show_attribute = uvcg_mjpeg_attr_show, - .store_attribute = uvcg_mjpeg_attr_store, -}; -static struct configfs_group_operations uvcg_mjpeg_group_ops = { .make_item = uvcg_frame_make, .drop_item = uvcg_frame_drop, };#define UVCG_MJPEG_ATTR_RO (cname, aname, conv) \ -static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\ +static ssize_t uvcg_mjpeg_##cname##_show(struct config_item *item, char *page)\ { \ + struct uvcg_mjpeg *u = to_uvcg_mjpeg(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \@@ -1639,13 +1561,12 @@ static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\return result; \ } \ \ -static struct uvcg_mjpeg_attribute \ - uvcg_mjpeg_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_mjpeg_##cname##_show) +UVC_ATTR_RO(uvcg_mjpeg_, cname, aname)#define UVCG_MJPEG_ATTR (cname, aname, conv) \ -static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\ +static ssize_t uvcg_mjpeg_##cname##_show(struct config_item *item, char *page)\ { \ + struct uvcg_mjpeg *u = to_uvcg_mjpeg(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \@@ -1665,9 +1586,10 @@ static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\ } \ \static ssize_t \ -uvcg_mjpeg_##cname##_store(struct uvcg_mjpeg *u, \ +uvcg_mjpeg_##cname##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct uvcg_mjpeg *u =to_uvcg_mjpeg (item); \struct f_uvc_opts *opts; \struct config_item *opts_item; \struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \@@ -1701,11 +1623,7 @@ end: \return ret; \ } \ \ -static struct uvcg_mjpeg_attribute \ - uvcg_mjpeg_##cname = \ - __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \ - uvcg_mjpeg_##cname##_show, \ - uvcg_mjpeg_##cname##_store) +UVC_ATTR(uvcg_mjpeg_, cname, aname)#define identity_conv (x) (x)@@ -1722,35 +1640,33 @@ UVCG_MJPEG_ATTR_RO(bm_interface_flags, bmInterfaceFlags, identity_conv);#undef UVCG_MJPEG_ATTR_ROstatic inline ssize_t -uvcg_mjpeg_bma_controls_show (struct uvcg_mjpeg *unc,char *page) +uvcg_mjpeg_bma_controls_show (struct config_item *item,char *page) { -return uvcg_format_bma_controls_show (&unc->fmt, page); +struct uvcg_mjpeg *u =to_uvcg_mjpeg (item); +return uvcg_format_bma_controls_show (&u->fmt, page); }static inline ssize_t -uvcg_mjpeg_bma_controls_store (struct uvcg_mjpeg *ch, +uvcg_mjpeg_bma_controls_store (struct config_item *item,const char *page,size_t len) { -return uvcg_format_bma_controls_store (&ch->fmt, page, len); +struct uvcg_mjpeg *u =to_uvcg_mjpeg (item); +return uvcg_format_bma_controls_store (&u->fmt, page, len); } -static struct uvcg_mjpeg_attribute uvcg_mjpeg_bma_controls = -__CONFIGFS_ATTR (bmaControls,S_IRUGO |S_IWUSR , - uvcg_mjpeg_bma_controls_show, - uvcg_mjpeg_bma_controls_store); +UVC_ATTR (uvcg_mjpeg_, bma_controls, bmaControls);static struct configfs_attribute *uvcg_mjpeg_attrs[] = { - &uvcg_mjpeg_b_default_frame_index.attr, - &uvcg_mjpeg_bm_flags.attr, - &uvcg_mjpeg_b_aspect_ratio_x.attr, - &uvcg_mjpeg_b_aspect_ratio_y.attr, - &uvcg_mjpeg_bm_interface_flags.attr, - &uvcg_mjpeg_bma_controls.attr, + &uvcg_mjpeg_attr_b_default_frame_index, + &uvcg_mjpeg_attr_bm_flags, + &uvcg_mjpeg_attr_b_aspect_ratio_x, + &uvcg_mjpeg_attr_b_aspect_ratio_y, + &uvcg_mjpeg_attr_bm_interface_flags, + &uvcg_mjpeg_attr_bma_controls,NULL , };static struct config_item_type uvcg_mjpeg_type = { - .ct_item_ops = &uvcg_mjpeg_item_ops, .ct_group_ops = &uvcg_mjpeg_group_ops, .ct_attrs = uvcg_mjpeg_attrs, .ct_owner =THIS_MODULE ,@@ -1811,17 +1727,12 @@ static inline struct uvcg_default_color_matching struct uvcg_default_color_matching, group); } -CONFIGFS_ATTR_STRUCT (uvcg_default_color_matching); -CONFIGFS_ATTR_OPS_RO (uvcg_default_color_matching); - -static struct configfs_item_operations uvcg_default_color_matching_item_ops = { - .show_attribute = uvcg_default_color_matching_attr_show, -}; -#define UVCG_DEFAULT_COLOR_MATCHING_ATTR (cname, aname, conv) \ static ssize_t uvcg_default_color_matching_##cname##_show( \ - struct uvcg_default_color_matching *dc, char *page) \ + struct config_item *item, char *page) \ { \ + struct uvcg_default_color_matching *dc = \ + to_uvcg_default_color_matching(item); \ struct f_uvc_opts *opts; \ struct config_item *opts_item; \ struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; \@@ -1842,9 +1753,7 @@ static ssize_t uvcg_default_color_matching_##cname##_show( \return result; \ } \ \ -static struct uvcg_default_color_matching_attribute \ - uvcg_default_color_matching_##cname = \ - __CONFIGFS_ATTR_RO(aname, uvcg_default_color_matching_##cname##_show) +UVC_ATTR_RO(uvcg_default_color_matching_, cname, aname)#define identity_conv (x) (x)@@ -1860,14 +1769,13 @@ UVCG_DEFAULT_COLOR_MATCHING_ATTR(b_matrix_coefficients, bMatrixCoefficients,#undef UVCG_DEFAULT_COLOR_MATCHING_ATTRstatic struct configfs_attribute *uvcg_default_color_matching_attrs[] = { - &uvcg_default_color_matching_b_color_primaries.attr, - &uvcg_default_color_matching_b_transfer_characteristics.attr, - &uvcg_default_color_matching_b_matrix_coefficients.attr, + &uvcg_default_color_matching_attr_b_color_primaries, + &uvcg_default_color_matching_attr_b_transfer_characteristics, + &uvcg_default_color_matching_attr_b_matrix_coefficients,NULL , };static struct config_item_type uvcg_default_color_matching_type = { - .ct_item_ops = &uvcg_default_color_matching_item_ops, .ct_attrs = uvcg_default_color_matching_attrs, .ct_owner =THIS_MODULE , };@@ -2285,9 +2193,6 @@ static inline struct f_uvc_opts *to_f_uvc_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_uvc_opts); -CONFIGFS_ATTR_OPS (f_uvc_opts); -static void uvc_attr_release (struct config_item *item) {struct f_uvc_opts *opts =to_f_uvc_opts (item);@@ -2297,14 +2202,13 @@ static void uvc_attr_release(struct config_item *item)static struct configfs_item_operations uvc_item_ops = { .release = uvc_attr_release, - .show_attribute = f_uvc_opts_attr_show, - .store_attribute = f_uvc_opts_attr_store, };#define UVCG_OPTS_ATTR (cname, conv, str2u, uxx, vnoc, limit) \ static ssize_t f_uvc_opts_##cname##_show( \ - struct f_uvc_opts *opts, char *page) \ + struct config_item *item, char *page) \ { \ + struct f_uvc_opts *opts = to_f_uvc_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \@@ -2315,9 +2219,10 @@ static ssize_t f_uvc_opts_##cname##_show( \ } \ \static ssize_t \ -f_uvc_opts_##cname##_store(struct f_uvc_opts *opts, \ +f_uvc_opts_##cname##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct f_uvc_opts *opts =to_f_uvc_opts (item); \int ret; \uxx num; \ \@@ -2342,11 +2247,7 @@ end: \return ret; \ } \ \ -static struct f_uvc_opts_attribute \ - f_uvc_opts_attribute_##cname = \ - __CONFIGFS_ATTR(cname, S_IRUGO | S_IWUSR, \ - f_uvc_opts_##cname##_show, \ - f_uvc_opts_##cname##_store) +UVC_ATTR(f_uvc_opts_, cname, aname)#define identity_conv (x) (x)@@ -2362,9 +2263,9 @@ UVCG_OPTS_ATTR(streaming_maxburst, identity_conv, kstrtou8, u8, identity_conv,#undef UVCG_OPTS_ATTRstatic struct configfs_attribute *uvc_attrs[] = { - &f_uvc_opts_attribute_streaming_interval.attr, - &f_uvc_opts_attribute_streaming_maxpacket.attr, - &f_uvc_opts_attribute_streaming_maxburst.attr, + &f_uvc_opts_attr_streaming_interval, + &f_uvc_opts_attr_streaming_maxpacket, + &f_uvc_opts_attr_streaming_maxburst,NULL , };
Re: [PATCH 03/23] usb-gadget/uvc: use per-attribute show and store methods
Quoted 3 lines · Andrzej Pietrasiewicz
Quoted 1 line
-#define
UVCG_STREAMING_CONTROL_SIZE1Moving this define seems an unrelated change to me.
I can move it back - this one wasn't intentional.
Quoted 9 lines
Quoted 1 line
+#define
identity_conv(x)(x)What is this needed for here?
This #define is not used near the place it is defined. Throughout the file the
identity_convis being defined multiple times, each time near the place it is used and then undefined.Without this line the code still compiles.
Looks like a copy & paste erro. I'll fix it up.
PATCH 4/23 usb-gadget/f_hid: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_hid.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)
drivers/usb/gadget/function/f_hid.c +14 -20
@@ -713,9 +713,6 @@ static inline struct f_hid_opts *to_f_hid_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_hid_opts); -CONFIGFS_ATTR_OPS (f_hid_opts); -static void hid_attr_release (struct config_item *item) {struct f_hid_opts *opts =to_f_hid_opts (item);
@@ -725,13 +722,12 @@ static void hid_attr_release(struct config_item *item)static struct configfs_item_operations hidg_item_ops = { .release = hid_attr_release, - .show_attribute = f_hid_opts_attr_show, - .store_attribute = f_hid_opts_attr_store, };#define F_HID_OPT (name, prec, limit) \ -static ssize_t f_hid_opts_##name##_show(struct f_hid_opts *opts, char *page)\ +static ssize_t f_hid_opts_##name##_show(struct config_item *item, char *page)\ { \ + struct f_hid_opts *opts = to_f_hid_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \
@@ -741,9 +737,10 @@ static ssize_t f_hid_opts_##name##_show(struct f_hid_opts *opts, char *page)\return result; \ } \ \ -static ssize_t f_hid_opts_##name##_store(struct f_hid_opts *opts, \ +static ssize_t f_hid_opts_##name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ + struct f_hid_opts *opts = to_f_hid_opts(item); \ int ret; \ u##prec num; \ \
@@ -769,16 +766,15 @@ end: \return ret; \ } \ \ -static struct f_hid_opts_attribute f_hid_opts_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, f_hid_opts_##name##_show,\ - f_hid_opts_##name##_store) +CONFIGFS_ATTR(f_hid_opts_, name)F_HID_OPT (subclass,8 ,255 );F_HID_OPT (protocol,8 ,255 );F_HID_OPT (report_length,16 ,65535 ); -static ssize_t f_hid_opts_report_desc_show (struct f_hid_opts *opts,char *page) +static ssize_t f_hid_opts_report_desc_show (struct config_item *item,char *page) { +struct f_hid_opts *opts =to_f_hid_opts (item);int result;mutex_lock (&opts->lock);
@@ -789,9 +785,10 @@ static ssize_t f_hid_opts_report_desc_show(struct f_hid_opts *opts, char *page)return result; } -static ssize_t f_hid_opts_report_desc_store (struct f_hid_opts *opts, +static ssize_t f_hid_opts_report_desc_store (struct config_item *item,const char *page,size_t len) { +struct f_hid_opts *opts =to_f_hid_opts (item);int ret = -EBUSY ;char *d;
@@ -818,16 +815,13 @@ end:return ret; } -static struct f_hid_opts_attribute f_hid_opts_report_desc = -__CONFIGFS_ATTR (report_desc,S_IRUGO |S_IWUSR , - f_hid_opts_report_desc_show, - f_hid_opts_report_desc_store); +CONFIGFS_ATTR (f_hid_opts_, report_desc);static struct configfs_attribute *hid_attrs[] = { - &f_hid_opts_subclass.attr, - &f_hid_opts_protocol.attr, - &f_hid_opts_report_length.attr, - &f_hid_opts_report_desc.attr, + &f_hid_opts_attr_subclass, + &f_hid_opts_attr_protocol, + &f_hid_opts_attr_report_length, + &f_hid_opts_attr_report_desc,NULL , };
Signature · 1 line
1.9.1
Re: [PATCH 04/23] usb-gadget/f_hid: use per-attribute show and store methods
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 101 lines
--- drivers/usb/gadget/function/f_hid.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)drivers/usb/gadget/function/f_hid.c +14
-20@@ -713,9 +713,6 @@ static inline struct f_hid_opts *to_f_hid_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_hid_opts); -CONFIGFS_ATTR_OPS (f_hid_opts); -static void hid_attr_release (struct config_item *item) {struct f_hid_opts *opts =to_f_hid_opts (item);@@ -725,13 +722,12 @@ static void hid_attr_release(struct config_item *item)static struct configfs_item_operations hidg_item_ops = { .release = hid_attr_release, - .show_attribute = f_hid_opts_attr_show, - .store_attribute = f_hid_opts_attr_store, };#define F_HID_OPT (name, prec, limit) \ -static ssize_t f_hid_opts_##name##_show(struct f_hid_opts *opts, char *page)\ +static ssize_t f_hid_opts_##name##_show(struct config_item *item, char *page)\ { \ + struct f_hid_opts *opts = to_f_hid_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \@@ -741,9 +737,10 @@ static ssize_t f_hid_opts_##name##_show(struct f_hid_opts *opts, char *page)\return result; \ } \ \ -static ssize_t f_hid_opts_##name##_store(struct f_hid_opts *opts, \ +static ssize_t f_hid_opts_##name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ + struct f_hid_opts *opts = to_f_hid_opts(item); \ int ret; \ u##prec num; \ \@@ -769,16 +766,15 @@ end: \return ret; \ } \ \ -static struct f_hid_opts_attribute f_hid_opts_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, f_hid_opts_##name##_show,\ - f_hid_opts_##name##_store) +CONFIGFS_ATTR(f_hid_opts_, name)F_HID_OPT (subclass,8 ,255 );F_HID_OPT (protocol,8 ,255 );F_HID_OPT (report_length,16 ,65535 ); -static ssize_t f_hid_opts_report_desc_show (struct f_hid_opts *opts,char *page) +static ssize_t f_hid_opts_report_desc_show (struct config_item *item,char *page) { +struct f_hid_opts *opts =to_f_hid_opts (item);int result;mutex_lock (&opts->lock);@@ -789,9 +785,10 @@ static ssize_t f_hid_opts_report_desc_show(struct f_hid_opts *opts, char *page)return result; } -static ssize_t f_hid_opts_report_desc_store (struct f_hid_opts *opts, +static ssize_t f_hid_opts_report_desc_store (struct config_item *item,const char *page,size_t len) { +struct f_hid_opts *opts =to_f_hid_opts (item);int ret = -EBUSY ;char *d;@@ -818,16 +815,13 @@ end:return ret; } -static struct f_hid_opts_attribute f_hid_opts_report_desc = -__CONFIGFS_ATTR (report_desc,S_IRUGO |S_IWUSR , - f_hid_opts_report_desc_show, - f_hid_opts_report_desc_store); +CONFIGFS_ATTR (f_hid_opts_, report_desc);static struct configfs_attribute *hid_attrs[] = { - &f_hid_opts_subclass.attr, - &f_hid_opts_protocol.attr, - &f_hid_opts_report_length.attr, - &f_hid_opts_report_desc.attr, + &f_hid_opts_attr_subclass, + &f_hid_opts_attr_protocol, + &f_hid_opts_attr_report_length, + &f_hid_opts_attr_report_desc,NULL , };
PATCH 5/23 usb-gadget/f_acm: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_acm.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/usb/gadget/function/f_acm.c +4 -22
@@ -776,21 +776,6 @@ static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_serial_opts); -static ssize_t f_acm_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -struct f_serial_opts *opts =to_f_serial_opts (item); -struct f_serial_opts_attribute *f_serial_opts_attr = - container_of(attr, struct f_serial_opts_attribute, attr); -ssize_t ret =0 ; - -if (f_serial_opts_attr->show) - ret = f_serial_opts_attr->show (opts, page); -return ret; -} -static void acm_attr_release (struct config_item *item) {struct f_serial_opts *opts =to_f_serial_opts (item);
@@ -800,20 +785,17 @@ static void acm_attr_release(struct config_item *item)static struct configfs_item_operations acm_item_ops = { .release = acm_attr_release, - .show_attribute = f_acm_attr_show, }; -static ssize_t f_acm_port_num_show (struct f_serial_opts *opts,char *page) +static ssize_t f_acm_port_num_show (struct config_item *item,char *page) { -return sprintf (page,"%u\n" , opts->port_num); +return sprintf (page,"%u\n" ,to_f_serial_opts (item)->port_num); } -static struct f_serial_opts_attribute f_acm_port_num = -__CONFIGFS_ATTR_RO (port_num, f_acm_port_num_show); - +CONFIGFS_ATTR_RO (f_acm_port_, num);static struct configfs_attribute *acm_attrs[] = { - &f_acm_port_num.attr, + &f_acm_port_attr_num,NULL , };
Signature · 1 line
1.9.1
Re: [PATCH 05/23] usb-gadget/f_acm: use per-attribute show and store methods
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 56 lines
--- drivers/usb/gadget/function/f_acm.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)drivers/usb/gadget/function/f_acm.c +4
-22@@ -776,21 +776,6 @@ static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_serial_opts); -static ssize_t f_acm_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -struct f_serial_opts *opts =to_f_serial_opts (item); -struct f_serial_opts_attribute *f_serial_opts_attr = - container_of(attr, struct f_serial_opts_attribute, attr); -ssize_t ret =0 ; - -if (f_serial_opts_attr->show) - ret = f_serial_opts_attr->show (opts, page); -return ret; -} -static void acm_attr_release (struct config_item *item) {struct f_serial_opts *opts =to_f_serial_opts (item);@@ -800,20 +785,17 @@ static void acm_attr_release(struct config_item *item)static struct configfs_item_operations acm_item_ops = { .release = acm_attr_release, - .show_attribute = f_acm_attr_show, }; -static ssize_t f_acm_port_num_show (struct f_serial_opts *opts,char *page) +static ssize_t f_acm_port_num_show (struct config_item *item,char *page) { -return sprintf (page,"%u\n" , opts->port_num); +return sprintf (page,"%u\n" ,to_f_serial_opts (item)->port_num); } -static struct f_serial_opts_attribute f_acm_port_num = -__CONFIGFS_ATTR_RO (port_num, f_acm_port_num_show); - +CONFIGFS_ATTR_RO (f_acm_port_, num);static struct configfs_attribute *acm_attrs[] = { - &f_acm_port_num.attr, + &f_acm_port_attr_num,NULL , };
PATCH 6/23 usb-gadget/ether: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_ecm.c | 8 ++--- drivers/usb/gadget/function/f_eem.c | 8 ++--- drivers/usb/gadget/function/f_ncm.c | 8 ++--- drivers/usb/gadget/function/f_rndis.c | 8 ++--- drivers/usb/gadget/function/f_subset.c | 8 ++--- drivers/usb/gadget/function/u_ether_configfs.h | 44 +++++++++++--------------- 6 files changed, 38 insertions(+), 46 deletions(-)
drivers/usb/gadget/function/f_ecm.c +4 -4
@@ -855,10 +855,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ecm);USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME (ecm);static struct configfs_attribute *ecm_attrs[] = { - &f_ecm_opts_dev_addr.attr, - &f_ecm_opts_host_addr.attr, - &f_ecm_opts_qmult.attr, - &f_ecm_opts_ifname.attr, + &ecm_opts_attr_dev_addr, + &ecm_opts_attr_host_addr, + &ecm_opts_attr_qmult, + &ecm_opts_attr_ifname,NULL , };
drivers/usb/gadget/function/f_eem.c +4 -4
@@ -555,10 +555,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(eem);USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME (eem);static struct configfs_attribute *eem_attrs[] = { - &f_eem_opts_dev_addr.attr, - &f_eem_opts_host_addr.attr, - &f_eem_opts_qmult.attr, - &f_eem_opts_ifname.attr, + &eem_opts_attr_dev_addr, + &eem_opts_attr_host_addr, + &eem_opts_attr_qmult, + &eem_opts_attr_ifname,NULL , };
drivers/usb/gadget/function/f_ncm.c +4 -4
@@ -1503,10 +1503,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME (ncm);static struct configfs_attribute *ncm_attrs[] = { - &f_ncm_opts_dev_addr.attr, - &f_ncm_opts_host_addr.attr, - &f_ncm_opts_qmult.attr, - &f_ncm_opts_ifname.attr, + &ncm_opts_attr_dev_addr, + &ncm_opts_attr_host_addr, + &ncm_opts_attr_qmult, + &ncm_opts_attr_ifname,NULL , };
drivers/usb/gadget/function/f_rndis.c +4 -4
@@ -878,10 +878,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(rndis);USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME (rndis);static struct configfs_attribute *rndis_attrs[] = { - &f_rndis_opts_dev_addr.attr, - &f_rndis_opts_host_addr.attr, - &f_rndis_opts_qmult.attr, - &f_rndis_opts_ifname.attr, + &rndis_opts_attr_dev_addr, + &rndis_opts_attr_host_addr, + &rndis_opts_attr_qmult, + &rndis_opts_attr_ifname,NULL , };
drivers/usb/gadget/function/f_subset.c +4 -4
@@ -413,10 +413,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(gether);USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME (gether);static struct configfs_attribute *gether_attrs[] = { - &f_gether_opts_dev_addr.attr, - &f_gether_opts_host_addr.attr, - &f_gether_opts_qmult.attr, - &f_gether_opts_ifname.attr, + &gether_opts_attr_dev_addr, + &gether_opts_attr_host_addr, + &gether_opts_attr_qmult, + &gether_opts_attr_ifname,NULL , };
drivers/usb/gadget/function/u_ether_configfs.h +18 -26
120 lines not on this page · raw message
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 1443189000-13398-7-git-send-email-hch-jcswGhMUV9g@public.gmane.org
Andrzej Pietrasiewicz
Reviewed-byRe: [PATCH 06/23] usb-gadget/ether: use per-attribute show and store methods
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 238 lines
--- drivers/usb/gadget/function/f_ecm.c | 8 ++--- drivers/usb/gadget/function/f_eem.c | 8 ++--- drivers/usb/gadget/function/f_ncm.c | 8 ++--- drivers/usb/gadget/function/f_rndis.c | 8 ++--- drivers/usb/gadget/function/f_subset.c | 8 ++--- drivers/usb/gadget/function/u_ether_configfs.h | 44 +++++++++++--------------- 6 files changed, 38 insertions(+), 46 deletions(-)drivers/usb/gadget/function/f_ecm.c +4
-4@@ -855,10 +855,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ecm);USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME (ecm);static struct configfs_attribute *ecm_attrs[] = { - &f_ecm_opts_dev_addr.attr, - &f_ecm_opts_host_addr.attr, - &f_ecm_opts_qmult.attr, - &f_ecm_opts_ifname.attr, + &ecm_opts_attr_dev_addr, + &ecm_opts_attr_host_addr, + &ecm_opts_attr_qmult, + &ecm_opts_attr_ifname,NULL , };drivers/usb/gadget/function/f_eem.c +4
-4@@ -555,10 +555,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(eem);USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME (eem);static struct configfs_attribute *eem_attrs[] = { - &f_eem_opts_dev_addr.attr, - &f_eem_opts_host_addr.attr, - &f_eem_opts_qmult.attr, - &f_eem_opts_ifname.attr, + &eem_opts_attr_dev_addr, + &eem_opts_attr_host_addr, + &eem_opts_attr_qmult, + &eem_opts_attr_ifname,NULL , };drivers/usb/gadget/function/f_ncm.c +4
-4@@ -1503,10 +1503,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME (ncm);static struct configfs_attribute *ncm_attrs[] = { - &f_ncm_opts_dev_addr.attr, - &f_ncm_opts_host_addr.attr, - &f_ncm_opts_qmult.attr, - &f_ncm_opts_ifname.attr, + &ncm_opts_attr_dev_addr, + &ncm_opts_attr_host_addr, + &ncm_opts_attr_qmult, + &ncm_opts_attr_ifname,NULL , };drivers/usb/gadget/function/f_rndis.c +4
-4@@ -878,10 +878,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(rndis);USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME (rndis);static struct configfs_attribute *rndis_attrs[] = { - &f_rndis_opts_dev_addr.attr, - &f_rndis_opts_host_addr.attr, - &f_rndis_opts_qmult.attr, - &f_rndis_opts_ifname.attr, + &rndis_opts_attr_dev_addr, + &rndis_opts_attr_host_addr, + &rndis_opts_attr_qmult, + &rndis_opts_attr_ifname,NULL , };drivers/usb/gadget/function/f_subset.c +4
-4@@ -413,10 +413,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(gether);USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME (gether);static struct configfs_attribute *gether_attrs[] = { - &f_gether_opts_dev_addr.attr, - &f_gether_opts_host_addr.attr, - &f_gether_opts_qmult.attr, - &f_gether_opts_ifname.attr, + &gether_opts_attr_dev_addr, + &gether_opts_attr_host_addr, + &gether_opts_attr_qmult, + &gether_opts_attr_ifname,NULL , };drivers/usb/gadget/function/u_ether_configfs.h +18
-26@@ -17,9 +17,6 @@#define __U_ETHER_CONFIGFS_H#define USB_ETHERNET_CONFIGFS_ITEM (_f_) \ - CONFIGFS_ATTR_STRUCT(f_##_f_##_opts); \ - CONFIGFS_ATTR_OPS(f_##_f_##_opts); \ - \ static void _f_##_attr_release(struct config_item *item) \ { \ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \@@ -29,14 +26,13 @@ \ static struct configfs_item_operations _f_##_item_ops = { \ .release = _f_##_attr_release, \ - .show_attribute = f_##_f_##_opts_attr_show, \ - .store_attribute = f_##_f_##_opts_attr_store, \ } #define USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(_f_) \ - static ssize_t _f_##_opts_dev_addr_show(struct f_##_f_##_opts *opts, \ + static ssize_t _f_##_opts_dev_addr_show(struct config_item *item, \ char *page) \ { \ + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \int result; \ \mutex_lock (&opts->lock); \@@ -46,9 +42,10 @@return result; \ } \ \ - static ssize_t _f_##_opts_dev_addr_store(struct f_##_f_##_opts *opts, \ + static ssize_t _f_##_opts_dev_addr_store(struct config_item *item, \const char *page,size_t len)\ { \ + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \int ret; \ \mutex_lock (&opts->lock); \@@ -64,15 +61,13 @@return ret; \ } \ \ - static struct f_##_f_##_opts_attribute f_##_f_##_opts_dev_addr = \ -__CONFIGFS_ATTR (dev_addr,S_IRUGO |S_IWUSR , \ - _f_##_opts_dev_addr_show, \ - _f_##_opts_dev_addr_store) + CONFIGFS_ATTR(_f_##_opts_, dev_addr)#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR (_f_) \ - static ssize_t _f_##_opts_host_addr_show(struct f_##_f_##_opts *opts, \ + static ssize_t _f_##_opts_host_addr_show(struct config_item *item, \ char *page) \ { \ + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \@@ -82,9 +77,10 @@return result; \ } \ \ - static ssize_t _f_##_opts_host_addr_store(struct f_##_f_##_opts *opts, \ + static ssize_t _f_##_opts_host_addr_store(struct config_item *item, \const char *page,size_t len)\ { \ + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \int ret; \ \mutex_lock (&opts->lock); \@@ -100,15 +96,13 @@return ret; \ } \ \ - static struct f_##_f_##_opts_attribute f_##_f_##_opts_host_addr = \ -__CONFIGFS_ATTR (host_addr,S_IRUGO |S_IWUSR , \ - _f_##_opts_host_addr_show, \ - _f_##_opts_host_addr_store) + CONFIGFS_ATTR(_f_##_opts_, host_addr)#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT (_f_) \ - static ssize_t _f_##_opts_qmult_show(struct f_##_f_##_opts *opts, \ + static ssize_t _f_##_opts_qmult_show(struct config_item *item, \ char *page) \ { \ + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ unsigned qmult; \ \ mutex_lock(&opts->lock); \@@ -117,9 +111,10 @@return sprintf (page,"%d" , qmult); \ } \ \ - static ssize_t _f_##_opts_qmult_store(struct f_##_f_##_opts *opts, \ + static ssize_t _f_##_opts_qmult_store(struct config_item *item, \const char *page,size_t len)\ { \ + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \u8 val; \int ret; \ \@@ -140,15 +135,13 @@ out: \return ret; \ } \ \ - static struct f_##_f_##_opts_attribute f_##_f_##_opts_qmult = \ -__CONFIGFS_ATTR (qmult,S_IRUGO |S_IWUSR , \ - _f_##_opts_qmult_show, \ - _f_##_opts_qmult_store) + CONFIGFS_ATTR(_f_##_opts_, qmult)#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME (_f_) \ - static ssize_t _f_##_opts_ifname_show(struct f_##_f_##_opts *opts, \ + static ssize_t _f_##_opts_ifname_show(struct config_item *item, \ char *page) \ { \ + struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int ret; \ \ mutex_lock(&opts->lock); \@@ -158,7 +151,6 @@ out: \return ret; \ } \ \ - static struct f_##_f_##_opts_attribute f_##_f_##_opts_ifname = \ - __CONFIGFS_ATTR_RO(ifname, _f_##_opts_ifname_show) + CONFIGFS_ATTR_RO(_f_##_opts_, ifname)#endif /* __U_ETHER_CONFIGFS_H */
A message that is not in the archive (sent off-list or not yet received): 1443189000-13398-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org
PATCH 7/23 usb-gadget/f_loopback: use per-attribute show and store methods
--- drivers/usb/gadget/function/f_loopback.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-)
drivers/usb/gadget/function/f_loopback.c +12 -20
@@ -413,9 +413,6 @@ static inline struct f_lb_opts *to_f_lb_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_lb_opts); -CONFIGFS_ATTR_OPS (f_lb_opts); -static void lb_attr_release (struct config_item *item) {struct f_lb_opts *lb_opts =to_f_lb_opts (item);
@@ -425,12 +422,11 @@ static void lb_attr_release(struct config_item *item)static struct configfs_item_operations lb_item_ops = { .release = lb_attr_release, - .show_attribute = f_lb_opts_attr_show, - .store_attribute = f_lb_opts_attr_store, }; -static ssize_t f_lb_opts_qlen_show (struct f_lb_opts *opts,char *page) +static ssize_t f_lb_opts_qlen_show (struct config_item *item,char *page) { +struct f_lb_opts *opts =to_f_lb_opts (item);int result;mutex_lock (&opts->lock);
@@ -440,9 +436,10 @@ static ssize_t f_lb_opts_qlen_show(struct f_lb_opts *opts, char *page)return result; } -static ssize_t f_lb_opts_qlen_store (struct f_lb_opts *opts, +static ssize_t f_lb_opts_qlen_store (struct config_item *item,const char *page,size_t len) { +struct f_lb_opts *opts =to_f_lb_opts (item);int ret;u32 num;
@@ -463,13 +460,9 @@ end:return ret; } -static struct f_lb_opts_attribute f_lb_opts_qlen = -__CONFIGFS_ATTR (qlen,S_IRUGO |S_IWUSR , - f_lb_opts_qlen_show, - f_lb_opts_qlen_store); - -static ssize_t f_lb_opts_bulk_buflen_show (struct f_lb_opts *opts,char *page) +static ssize_t f_lb_opts_bulk_buflen_show (struct config_item *item,char *page) { +struct f_lb_opts *opts =to_f_lb_opts (item);int result;mutex_lock (&opts->lock);
@@ -479,9 +472,10 @@ static ssize_t f_lb_opts_bulk_buflen_show(struct f_lb_opts *opts, char *page)return result; } -static ssize_t f_lb_opts_bulk_buflen_store (struct f_lb_opts *opts, +static ssize_t f_lb_opts_bulk_buflen_store (struct config_item *item,const char *page,size_t len) { +struct f_lb_opts *opts =to_f_lb_opts (item);int ret;u32 num;
@@ -502,14 +496,12 @@ end:return ret; } -static struct f_lb_opts_attribute f_lb_opts_bulk_buflen = -__CONFIGFS_ATTR (buflen,S_IRUGO |S_IWUSR , - f_lb_opts_bulk_buflen_show, - f_lb_opts_bulk_buflen_store); +CONFIGFS_ATTR (f_lb_opts_, qlen); +CONFIGFS_ATTR (f_lb_opts_, bulk_buflen);static struct configfs_attribute *lb_attrs[] = { - &f_lb_opts_qlen.attr, - &f_lb_opts_bulk_buflen.attr, + &f_lb_opts_attr_qlen, + &f_lb_opts_attr_bulk_buflen,NULL , };
Signature · 1 line
1.9.1
Re: [PATCH 07/23] usb-gadget/f_loopback: use per-attribute show and store methods
Hi Christoph,
Please see comments inline.
With the issue addressed you can add
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 47 lines
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/usb/gadget/function/f_loopback.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-)drivers/usb/gadget/function/f_loopback.c +4
-7@@ -413,9 +413,6 @@ static inline struct f_lb_opts *to_f_lb_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_lb_opts); -CONFIGFS_ATTR_OPS (f_lb_opts); -static void lb_attr_release (struct config_item *item) {struct f_lb_opts *lb_opts =to_f_lb_opts (item);@@ -425,12 +422,11 @@ static void lb_attr_release(struct config_item *item)static struct configfs_item_operations lb_item_ops = { .release = lb_attr_release, - .show_attribute = f_lb_opts_attr_show, - .store_attribute = f_lb_opts_attr_store, }; -static ssize_t f_lb_opts_qlen_show (struct f_lb_opts *opts,char *page) +static ssize_t f_lb_opts_qlen_show (struct config_item *item,char *page) { +struct f_lb_opts *opts =to_f_lb_opts (item);int result;mutex_lock (&opts->lock);@@ -440,9 +436,10 @@ static ssize_t f_lb_opts_qlen_show(struct f_lb_opts *opts, char *page)return result; } -static ssize_t f_lb_opts_qlen_store (struct f_lb_opts *opts, +static ssize_t f_lb_opts_qlen_store (struct config_item *item,const char *page,size_t len) { +struct f_lb_opts *opts =to_f_lb_opts (item);int ret;u32 num;
drivers/usb/gadget/function/f_loopback.c end: · line 470
Quoted 8 lines
drivers/usb/gadget/function/f_loopback.c +0
-5@@ -463,13 +460,9 @@ end:return ret; } -static struct f_lb_opts_attribute f_lb_opts_qlen = -__CONFIGFS_ATTR (qlen,S_IRUGO |S_IWUSR , - f_lb_opts_qlen_show, - f_lb_opts_qlen_store); -
In my opinion the below line belongs here:
+CONFIGFS_ATTR(f_lb_opts_, qlen);
Quoted 20 lines
drivers/usb/gadget/function/f_loopback.c +4
-2-static ssize_t f_lb_opts_bulk_buflen_show (struct f_lb_opts *opts,char *page) +static ssize_t f_lb_opts_bulk_buflen_show (struct config_item *item,char *page) { +struct f_lb_opts *opts =to_f_lb_opts (item);int result;mutex_lock (&opts->lock);@@ -479,9 +472,10 @@ static ssize_t f_lb_opts_bulk_buflen_show(struct f_lb_opts *opts, char *page)return result; } -static ssize_t f_lb_opts_bulk_buflen_store (struct f_lb_opts *opts, +static ssize_t f_lb_opts_bulk_buflen_store (struct config_item *item,const char *page,size_t len) { +struct f_lb_opts *opts =to_f_lb_opts (item);int ret;u32 num;
drivers/usb/gadget/function/f_loopback.c end: · line 500
Quoted 9 lines
drivers/usb/gadget/function/f_loopback.c +2
-4@@ -502,14 +496,12 @@ end:return ret; } -static struct f_lb_opts_attribute f_lb_opts_bulk_buflen = -__CONFIGFS_ATTR (buflen,S_IRUGO |S_IWUSR , - f_lb_opts_bulk_buflen_show, - f_lb_opts_bulk_buflen_store); +CONFIGFS_ATTR (f_lb_opts_, qlen); +CONFIGFS_ATTR (f_lb_opts_, bulk_buflen);
Why group CONFIGFS_ATTR invocations if in the original code their corresponding __CONFIGFS_ATTR invocations were where they were?
Quoted 10 lines
drivers/usb/gadget/function/f_loopback.c +2
-2static struct configfs_attribute *lb_attrs[] = { - &f_lb_opts_qlen.attr, - &f_lb_opts_bulk_buflen.attr, + &f_lb_opts_attr_qlen, + &f_lb_opts_attr_bulk_buflen,NULL , };
Re: [PATCH 07/23] usb-gadget/f_loopback: use per-attribute show and store methods
Quoted 10 lines · Andrzej Pietrasiewicz
drivers/usb/gadget/function/f_loopback.c end: · line 470
Quoted 7 lines
}drivers/usb/gadget/function/f_loopback.c +0
-5-static struct f_lb_opts_attribute f_lb_opts_qlen = -__CONFIGFS_ATTR (qlen,S_IRUGO |S_IWUSR , - f_lb_opts_qlen_show, - f_lb_opts_qlen_store); -In my opinion the below line belongs here:
+CONFIGFS_ATTR(f_lb_opts_, qlen);
The idea is to keep all the attribute defintions near the attribute array, similar to how most drivers define their sysfs attributes.
If you really don't like that way I'll move it back.
Re: [PATCH 07/23] usb-gadget/f_loopback: use per-attribute show and store methods
Hi,
W dniu 28.09.2015 o 15:41, Christoph Hellwig pisze:
Quoted 10 lines · Andrzej Pietrasiewicz
Quoted 9 lines
drivers/usb/gadget/function/f_loopback.c end: · line 470
Quoted 7 lines
}drivers/usb/gadget/function/f_loopback.c +0
-5-static struct f_lb_opts_attribute f_lb_opts_qlen = -__CONFIGFS_ATTR (qlen,S_IRUGO |S_IWUSR , - f_lb_opts_qlen_show, - f_lb_opts_qlen_store); -In my opinion the below line belongs here:
Quoted 5 lines
Quoted 1 line
+CONFIGFS_ATTR(f_lb_opts_, qlen);
The idea is to keep all the attribute defintions near the attribute array, similar to how most drivers define their sysfs attributes.
You were not consistent with the approach, though: with some patches CONFIGFS_ATTR() are where __CONFIGFS_ATTR were, with some other they are grouped.
Quoted 1 line
If you really don't like that way I'll move it back.
I think the change is more explicit/readable if the macro invocations are where what they substitute used to be.
AP
PATCH 20/23 netconsole: use per-attribute show and store methods
In reply to a message not in the archiveNote that the old code actually used the store_attributes method to do locking, this is moved into the individual methods.
--- drivers/net/netconsole.c | 269 +++++++++++++++++++++++------------------------ 1 file changed, 131 insertions(+), 138 deletions(-)
drivers/net/netconsole.c +131 -138
@@ -244,15 +244,6 @@ static void free_param_target(struct netconsole_target *nt)* <target>/... */ -struct netconsole_target_attr { -struct configfs_attribute attr; -ssize_t (*show)(struct netconsole_target *nt, -char *buf); -ssize_t (*store)(struct netconsole_target *nt, -const char *buf, -size_t count); -}; -static struct netconsole_target *to_target (struct config_item *item) { return item ?
@@ -264,58 +255,62 @@ static struct netconsole_target *to_target(struct config_item *item)* Attribute operations for netconsole_target. */ -static ssize_t show_enabled (struct netconsole_target *nt,char *buf) +static ssize_t enabled_show (struct config_item *item,char *buf) { -return snprintf (buf,PAGE_SIZE ,"%d\n" , nt->enabled); +return snprintf (buf,PAGE_SIZE ,"%d\n" ,to_target (item)->enabled); } -static ssize_t show_extended (struct netconsole_target *nt,char *buf) +static ssize_t extended_show (struct config_item *item,char *buf) { -return snprintf (buf,PAGE_SIZE ,"%d\n" , nt->extended); +return snprintf (buf,PAGE_SIZE ,"%d\n" ,to_target (item)->extended); } -static ssize_t show_dev_name (struct netconsole_target *nt,char *buf) +static ssize_t dev_name_show (struct config_item *item,char *buf) { -return snprintf (buf,PAGE_SIZE ,"%s\n" , nt->np.dev_name); +return snprintf (buf,PAGE_SIZE ,"%s\n" ,to_target (item)->np.dev_name); } -static ssize_t show_local_port (struct netconsole_target *nt,char *buf) +static ssize_t local_port_show (struct config_item *item,char *buf) { -return snprintf (buf,PAGE_SIZE ,"%d\n" , nt->np.local_port); +return snprintf (buf,PAGE_SIZE ,"%d\n" ,to_target (item)->np.local_port); } -static ssize_t show_remote_port (struct netconsole_target *nt,char *buf) +static ssize_t remote_port_show (struct config_item *item,char *buf) { -return snprintf (buf,PAGE_SIZE ,"%d\n" , nt->np.remote_port); +return snprintf (buf,PAGE_SIZE ,"%d\n" ,to_target (item)->np.remote_port); } -static ssize_t show_local_ip (struct netconsole_target *nt,char *buf) +static ssize_t local_ip_show (struct config_item *item,char *buf) { +struct netconsole_target *nt =to_target (item); +if (nt->np.ipv6)return snprintf (buf,PAGE_SIZE ,"%pI6c\n" , &nt->np.local_ip.in6);else return snprintf (buf,PAGE_SIZE ,"%pI4\n" , &nt->np.local_ip); } -static ssize_t show_remote_ip (struct netconsole_target *nt,char *buf) +static ssize_t remote_ip_show (struct config_item *item,char *buf) { +struct netconsole_target *nt =to_target (item); +if (nt->np.ipv6)return snprintf (buf,PAGE_SIZE ,"%pI6c\n" , &nt->np.remote_ip.in6);else return snprintf (buf,PAGE_SIZE ,"%pI4\n" , &nt->np.remote_ip); } -static ssize_t show_local_mac (struct netconsole_target *nt,char *buf) +static ssize_t local_mac_show (struct config_item *item,char *buf) { -struct net_device *dev = nt->np.dev; +struct net_device *dev =to_target (item)->np.dev;static const u8 bcast[ETH_ALEN ] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff };return snprintf (buf,PAGE_SIZE ,"%pM\n" , dev ? dev->dev_addr : bcast); } -static ssize_t show_remote_mac (struct netconsole_target *nt,char *buf) +static ssize_t remote_mac_show (struct config_item *item,char *buf) { -return snprintf (buf,PAGE_SIZE ,"%pM\n" , nt->np.remote_mac); +return snprintf (buf,PAGE_SIZE ,"%pM\n" ,to_target (item)->np.remote_mac); }/*
@@ -325,23 +320,26 @@ static ssize_t show_remote_mac(struct netconsole_target *nt, char *buf)* would enable him to dynamically add new netpoll targets for new * network interfaces as and when they come up). */ -static ssize_t store_enabled (struct netconsole_target *nt, -const char *buf, -size_t count) +static ssize_t enabled_store (struct config_item *item, +const char *buf,size_t count) { +struct netconsole_target *nt =to_target (item);unsigned long flags;int enabled;int err; +mutex_lock (&dynamic_netconsole_mutex); err =kstrtoint (buf,10 , &enabled);if (err <0 ) -return err; + goto out_unlock; + + err = -EINVAL ;if (enabled <0 || enabled >1 ) -return -EINVAL ; + goto out_unlock;if ((bool )enabled == nt->enabled) {pr_info ("network logging has already %s\n" , nt->enabled ?"started" :"stopped" ); -return -EINVAL ; + goto out_unlock; }if (enabled) {/* true */
@@ -358,7 +356,7 @@ static ssize_t store_enabled(struct netconsole_target *nt, err =netpoll_setup (&nt->np);if (err) -return err; + goto out_unlock;pr_info ("netconsole: network logging started\n" ); }else {/* false */
@@ -374,42 +372,56 @@ static ssize_t store_enabled(struct netconsole_target *nt, nt->enabled = enabled; +mutex_unlock (&dynamic_netconsole_mutex);return strnlen (buf, count); +out_unlock: +mutex_unlock (&dynamic_netconsole_mutex); +return err; } -static ssize_t store_extended (struct netconsole_target *nt, -const char *buf, -size_t count) +static ssize_t extended_store (struct config_item *item,const char *buf, +size_t count) { +struct netconsole_target *nt =to_target (item);int extended;int err; +mutex_lock (&dynamic_netconsole_mutex);if (nt->enabled) {pr_err ("target (%s) is enabled, disable to update parameters\n" ,config_item_name (&nt->item)); -return -EINVAL ; + err = -EINVAL ; + goto out_unlock; } err =kstrtoint (buf,10 , &extended);if (err <0 ) -return err; -if (extended <0 || extended >1 ) -return -EINVAL ; + goto out_unlock; +if (extended <0 || extended >1 ) { + err = -EINVAL ; + goto out_unlock; + } nt->extended = extended; +mutex_unlock (&dynamic_netconsole_mutex);return strnlen (buf, count); +out_unlock: +mutex_unlock (&dynamic_netconsole_mutex); +return err; } -static ssize_t store_dev_name (struct netconsole_target *nt, -const char *buf, -size_t count) +static ssize_t dev_name_store (struct config_item *item,const char *buf, +size_t count) { +struct netconsole_target *nt =to_target (item);size_t len; +mutex_lock (&dynamic_netconsole_mutex);if (nt->enabled) {pr_err ("target (%s) is enabled, disable to update parameters\n" ,config_item_name (&nt->item)); +mutex_unlock (&dynamic_netconsole_mutex);return -EINVAL ; }
@@ -420,53 +432,66 @@ static ssize_t store_dev_name(struct netconsole_target *nt,if (nt->np.dev_name[len -1 ] =='\n' ) nt->np.dev_name[len -1 ] ='\0' ; +mutex_unlock (&dynamic_netconsole_mutex);return strnlen (buf, count); } -static ssize_t store_local_port (struct netconsole_target *nt, -const char *buf, -size_t count) +static ssize_t local_port_store (struct config_item *item,const char *buf, +size_t count) { -int rv; +struct netconsole_target *nt =to_target (item); +int rv = -EINVAL ; +mutex_lock (&dynamic_netconsole_mutex);if (nt->enabled) {pr_err ("target (%s) is enabled, disable to update parameters\n" ,config_item_name (&nt->item)); -return -EINVAL ; + goto out_unlock; } rv =kstrtou16 (buf,10 , &nt->np.local_port);if (rv <0 ) -return rv; + goto out_unlock; +mutex_unlock (&dynamic_netconsole_mutex);return strnlen (buf, count); +out_unlock: +mutex_unlock (&dynamic_netconsole_mutex); +return rv; } -static ssize_t store_remote_port (struct netconsole_target *nt, -const char *buf, -size_t count) +static ssize_t remote_port_store (struct config_item *item, +const char *buf,size_t count) { -int rv; +struct netconsole_target *nt =to_target (item); +int rv = -EINVAL ; +mutex_lock (&dynamic_netconsole_mutex);if (nt->enabled) {pr_err ("target (%s) is enabled, disable to update parameters\n" ,config_item_name (&nt->item)); -return -EINVAL ; + goto out_unlock; } rv =kstrtou16 (buf,10 , &nt->np.remote_port);if (rv <0 ) -return rv; + goto out_unlock; +mutex_unlock (&dynamic_netconsole_mutex);return strnlen (buf, count); +out_unlock: +mutex_unlock (&dynamic_netconsole_mutex); +return rv; } -static ssize_t store_local_ip (struct netconsole_target *nt, -const char *buf, -size_t count) +static ssize_t local_ip_store (struct config_item *item,const char *buf, +size_t count) { +struct netconsole_target *nt =to_target (item); + +mutex_lock (&dynamic_netconsole_mutex);if (nt->enabled) {pr_err ("target (%s) is enabled, disable to update parameters\n" ,config_item_name (&nt->item)); -return -EINVAL ; + goto out_unlock; }if (strnchr (buf, count,':' )) {
@@ -474,29 +499,35 @@ static ssize_t store_local_ip(struct netconsole_target *nt,if (in6_pton (buf, count, nt->np.local_ip.in6.s6_addr,-1 , &end) >0 ) {if (*end && *end !='\n' ) {pr_err ("invalid IPv6 address at: <%c>\n" , *end); -return -EINVAL ; + goto out_unlock; } nt->np.ipv6 = true; }else -return -EINVAL ; + goto out_unlock; }else {if (!nt->np.ipv6) { nt->np.local_ip.ip =in_aton (buf); }else -return -EINVAL ; + goto out_unlock; } +mutex_unlock (&dynamic_netconsole_mutex);return strnlen (buf, count); +out_unlock: +mutex_unlock (&dynamic_netconsole_mutex); +return -EINVAL ; } -static ssize_t store_remote_ip (struct netconsole_target *nt, -const char *buf, -size_t count) +static ssize_t remote_ip_store (struct config_item *item,const char *buf, +size_t count) { +struct netconsole_target *nt =to_target (item); + +mutex_lock (&dynamic_netconsole_mutex);if (nt->enabled) {pr_err ("target (%s) is enabled, disable to update parameters\n" ,config_item_name (&nt->item)); -return -EINVAL ; + goto out_unlock; }if (strnchr (buf, count,':' )) {
@@ -508,70 +539,67 @@ static ssize_t store_remote_ip(struct netconsole_target *nt, } nt->np.ipv6 = true; }else -return -EINVAL ; + goto out_unlock; }else {if (!nt->np.ipv6) { nt->np.remote_ip.ip =in_aton (buf); }else -return -EINVAL ; + goto out_unlock; } +mutex_unlock (&dynamic_netconsole_mutex);return strnlen (buf, count); +out_unlock: +mutex_unlock (&dynamic_netconsole_mutex); +return -EINVAL ; } -static ssize_t store_remote_mac (struct netconsole_target *nt, -const char *buf, -size_t count) +static ssize_t remote_mac_store (struct config_item *item,const char *buf, +size_t count) { +struct netconsole_target *nt =to_target (item);u8 remote_mac[ETH_ALEN ]; +mutex_lock (&dynamic_netconsole_mutex);if (nt->enabled) {pr_err ("target (%s) is enabled, disable to update parameters\n" ,config_item_name (&nt->item)); -return -EINVAL ; + goto out_unlock; }if (!mac_pton (buf, remote_mac)) -return -EINVAL ; + goto out_unlock;if (buf[3 *ETH_ALEN -1 ] && buf[3 *ETH_ALEN -1 ] !='\n' ) -return -EINVAL ; + goto out_unlock;memcpy (nt->np.remote_mac, remote_mac,ETH_ALEN ); +mutex_unlock (&dynamic_netconsole_mutex);return strnlen (buf, count); +out_unlock: +mutex_unlock (&dynamic_netconsole_mutex); +return -EINVAL ; } -/* -* Attribute definitions for netconsole_target. -*/ - -#define NETCONSOLE_TARGET_ATTR_RO (_name) \ -static struct netconsole_target_attr netconsole_target_##_name = \ - __CONFIGFS_ATTR(_name, S_IRUGO, show_##_name, NULL) - -#define NETCONSOLE_TARGET_ATTR_RW (_name) \ -static struct netconsole_target_attr netconsole_target_##_name = \ - __CONFIGFS_ATTR(_name, S_IRUGO | S_IWUSR, show_##_name, store_##_name) - -NETCONSOLE_TARGET_ATTR_RW (enabled); -NETCONSOLE_TARGET_ATTR_RW (extended); -NETCONSOLE_TARGET_ATTR_RW (dev_name); -NETCONSOLE_TARGET_ATTR_RW (local_port); -NETCONSOLE_TARGET_ATTR_RW (remote_port); -NETCONSOLE_TARGET_ATTR_RW (local_ip); -NETCONSOLE_TARGET_ATTR_RW (remote_ip); -NETCONSOLE_TARGET_ATTR_RO (local_mac); -NETCONSOLE_TARGET_ATTR_RW (remote_mac); +CONFIGFS_ATTR(, enabled); +CONFIGFS_ATTR(, extended); +CONFIGFS_ATTR(, dev_name); +CONFIGFS_ATTR(, local_port); +CONFIGFS_ATTR(, remote_port); +CONFIGFS_ATTR(, local_ip); +CONFIGFS_ATTR(, remote_ip); +CONFIGFS_ATTR_RO(, local_mac); +CONFIGFS_ATTR(, remote_mac);static struct configfs_attribute *netconsole_target_attrs[] = { - &netconsole_target_enabled.attr, - &netconsole_target_extended.attr, - &netconsole_target_dev_name.attr, - &netconsole_target_local_port.attr, - &netconsole_target_remote_port.attr, - &netconsole_target_local_ip.attr, - &netconsole_target_remote_ip.attr, - &netconsole_target_local_mac.attr, - &netconsole_target_remote_mac.attr, + &attr_enabled, + &attr_extended, + &attr_dev_name, + &attr_local_port, + &attr_remote_port, + &attr_local_ip, + &attr_remote_ip, + &attr_local_mac, + &attr_remote_mac,NULL , };
@@ -584,43 +612,8 @@ static void netconsole_target_release(struct config_item *item)kfree (to_target (item)); } -static ssize_t netconsole_target_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *buf) -{ -ssize_t ret = -EINVAL ; -struct netconsole_target *nt =to_target (item); -struct netconsole_target_attr *na = - container_of(attr, struct netconsole_target_attr, attr); - -if (na->show) - ret = na->show (nt, buf); - -return ret; -} - -static ssize_t netconsole_target_attr_store (struct config_item *item, -struct configfs_attribute *attr, -const char *buf, -size_t count) -{ -ssize_t ret = -EINVAL ; -struct netconsole_target *nt =to_target (item); -struct netconsole_target_attr *na = - container_of(attr, struct netconsole_target_attr, attr); - -mutex_lock (&dynamic_netconsole_mutex); -if (na->store) - ret = na->store (nt, buf, count); -mutex_unlock (&dynamic_netconsole_mutex); - -return ret; -} -static struct configfs_item_operations netconsole_target_item_ops = { .release = netconsole_target_release, - .show_attribute = netconsole_target_attr_show, - .store_attribute = netconsole_target_attr_store, };static struct config_item_type netconsole_target_type = {
Signature · 1 line
1.9.1
PATCH 21/23 ocfs2/cluster: move locking into attribute store methods
In reply to a message not in the archiveThe test and separate set bit scheme was racy to start with, so move to do a test_and_set_bit after doing the earlier error checks inside the actual store methods. Also remove the locking for the local attribute which already has a different scheme to synchronize.
--- fs/ocfs2/cluster/nodemanager.c | 54 +++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 35 deletions(-)
fs/ocfs2/cluster/nodemanager.c +19 -35
@@ -188,7 +188,6 @@ enum {O2NM_NODE_ATTR_NUM =0 ,O2NM_NODE_ATTR_PORT , O2NM_NODE_ATTR_ADDRESS, - O2NM_NODE_ATTR_LOCAL, }; static ssize_t o2nm_node_num_write(struct o2nm_node *node, const char *page,
@@ -197,6 +196,7 @@ static ssize_t o2nm_node_num_write(struct o2nm_node *node, const char *page,struct o2nm_cluster *cluster =to_o2nm_cluster_from_node (node);unsigned long tmp;char *p = (char *)page; +int ret =0 ; tmp =simple_strtoul (p, &p,0 );if (!p || (*p && (*p !='\n' )))
@@ -215,15 +215,18 @@ static ssize_t o2nm_node_num_write(struct o2nm_node *node, const char *page,write_lock (&cluster->cl_nodes_lock);if (cluster->cl_nodes[tmp]) - p =NULL ; + ret = -EEXIST ; +else if (test_and_set_bit (O2NM_NODE_ATTR_NUM , + &node->nd_set_attributes)) + ret = -EBUSY ;else { cluster->cl_nodes[tmp] = node; node->nd_num = tmp;set_bit (tmp, cluster->cl_nodes_bitmap); }write_unlock (&cluster->cl_nodes_lock); -if (p ==NULL ) -return -EEXIST ; +if (ret) +return ret;return count; }
@@ -247,6 +250,8 @@ static ssize_t o2nm_node_ipv4_port_write(struct o2nm_node *node,if (tmp >= (u16)-1 )return -ERANGE ; +if (test_and_set_bit (O2NM_NODE_ATTR_PORT , &node->nd_set_attributes)) +return -EBUSY ; node->nd_ipv4_port =htons (tmp);return count;
@@ -282,6 +287,9 @@ static ssize_t o2nm_node_ipv4_address_write(struct o2nm_node *node,write_lock (&cluster->cl_nodes_lock);if (o2nm_node_ip_tree_lookup (cluster, ipv4_addr, &p, &parent)) ret = -EEXIST ; +else if (test_and_set_bit (O2NM_NODE_ATTR_ADDRESS , + &node->nd_set_attributes)) + ret = -EBUSY ;else {rb_link_node (&node->nd_ip_node, parent, p);rb_insert_color (&node->nd_ip_node, &cluster->cl_node_ip_tree);
@@ -388,24 +396,13 @@ static struct o2nm_node_attribute o2nm_node_attr_local = { };static struct configfs_attribute *o2nm_node_attrs[] = { - [O2NM_NODE_ATTR_NUM ] = &o2nm_node_attr_num.attr, - [O2NM_NODE_ATTR_PORT ] = &o2nm_node_attr_ipv4_port.attr, - [O2NM_NODE_ATTR_ADDRESS ] = &o2nm_node_attr_ipv4_address.attr, - [O2NM_NODE_ATTR_LOCAL ] = &o2nm_node_attr_local.attr, + &o2nm_node_attr_num.attr, + &o2nm_node_attr_ipv4_port.attr, + &o2nm_node_attr_ipv4_address.attr, + &o2nm_node_attr_local.attr,NULL , }; -static int o2nm_attr_index (struct configfs_attribute *attr) -{ -int i; -for (i =0 ; i <ARRAY_SIZE (o2nm_node_attrs); i++) { -if (attr == o2nm_node_attrs[i]) -return i; - } -BUG (); -return 0 ; -} -static ssize_t o2nm_node_show (struct config_item *item,struct configfs_attribute *attr,char *page)
@@ -427,24 +424,11 @@ static ssize_t o2nm_node_store(struct config_item *item,struct o2nm_node *node =to_o2nm_node (item);struct o2nm_node_attribute *o2nm_node_attr = container_of(attr, struct o2nm_node_attribute, attr); -ssize_t ret; -int attr_index =o2nm_attr_index (attr); -if (o2nm_node_attr->store ==NULL ) { - ret = -EINVAL ; - goto out; - } - -if (test_bit (attr_index, &node->nd_set_attributes)) -return -EBUSY ; - - ret = o2nm_node_attr->store (node, page, count); -if (ret < count) - goto out; +if (o2nm_node_attr->store ==NULL ) +return -EINVAL ; -set_bit (attr_index, &node->nd_set_attributes); -out: -return ret; +return o2nm_node_attr->store (node, page, count); }static struct configfs_item_operations o2nm_node_item_ops = {
Signature · 1 line
1.9.1
Any I promised to Cc Pantelis when posting this for his binary attribute work but failed to do. I'm very sorry for that and blame in on the lack of sleep.
PATCH 8/23 usb-gadget/f_midi: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_midi.c | 37 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 21 deletions(-)
drivers/usb/gadget/function/f_midi.c +16 -21
@@ -906,9 +906,6 @@ static inline struct f_midi_opts *to_f_midi_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_midi_opts); -CONFIGFS_ATTR_OPS (f_midi_opts); -static void midi_attr_release (struct config_item *item) {struct f_midi_opts *opts =to_f_midi_opts (item);
@@ -918,13 +915,12 @@ static void midi_attr_release(struct config_item *item)static struct configfs_item_operations midi_item_ops = { .release = midi_attr_release, - .show_attribute = f_midi_opts_attr_show, - .store_attribute = f_midi_opts_attr_store, };#define F_MIDI_OPT (name, test_limit, limit) \ -static ssize_t f_midi_opts_##name##_show(struct f_midi_opts *opts, char *page) \ +static ssize_t f_midi_opts_##name##_show(struct config_item *item, char *page) \ { \ + struct f_midi_opts *opts = to_f_midi_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \
@@ -934,9 +930,10 @@ static ssize_t f_midi_opts_##name##_show(struct f_midi_opts *opts, char *page) \return result; \ } \ \ -static ssize_t f_midi_opts_##name##_store(struct f_midi_opts *opts, \ +static ssize_t f_midi_opts_##name##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct f_midi_opts *opts =to_f_midi_opts (item); \int ret; \u32 num; \ \
@@ -962,9 +959,7 @@ end: \return ret; \ } \ \ -static struct f_midi_opts_attribute f_midi_opts_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, f_midi_opts_##name##_show, \ - f_midi_opts_##name##_store) +CONFIGFS_ATTR (f_midi_opts_, name);F_MIDI_OPT (index, true,SNDRV_CARDS );F_MIDI_OPT (buflen, false,0 );
@@ -972,8 +967,9 @@ F_MIDI_OPT(qlen, false, 0);F_MIDI_OPT (in_ports, true,MAX_PORTS );F_MIDI_OPT (out_ports, true,MAX_PORTS ); -static ssize_t f_midi_opts_id_show (struct f_midi_opts *opts,char *page) +static ssize_t f_midi_opts_id_show (struct config_item *item,char *page) { +struct f_midi_opts *opts =to_f_midi_opts (item);int result;mutex_lock (&opts->lock);
@@ -989,9 +985,10 @@ static ssize_t f_midi_opts_id_show(struct f_midi_opts *opts, char *page)return result; } -static ssize_t f_midi_opts_id_store (struct f_midi_opts *opts, +static ssize_t f_midi_opts_id_store (struct config_item *item,const char *page,size_t len) { +struct f_midi_opts *opts =to_f_midi_opts (item);int ret;char *c;
@@ -1016,17 +1013,15 @@ end:return ret; } -static struct f_midi_opts_attribute f_midi_opts_id = -__CONFIGFS_ATTR (id,S_IRUGO |S_IWUSR , f_midi_opts_id_show, - f_midi_opts_id_store); +CONFIGFS_ATTR (f_midi_opts_, id);static struct configfs_attribute *midi_attrs[] = { - &f_midi_opts_index.attr, - &f_midi_opts_buflen.attr, - &f_midi_opts_qlen.attr, - &f_midi_opts_in_ports.attr, - &f_midi_opts_out_ports.attr, - &f_midi_opts_id.attr, + &f_midi_opts_attr_index, + &f_midi_opts_attr_buflen, + &f_midi_opts_attr_qlen, + &f_midi_opts_attr_in_ports, + &f_midi_opts_attr_out_ports, + &f_midi_opts_attr_id,NULL , };
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 1443189000-13398-9-git-send-email-hch-jcswGhMUV9g@public.gmane.org
Andrzej Pietrasiewicz
Reviewed-byRe: [PATCH 08/23] usb-gadget/f_midi: use per-attribute show and store methods
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 106 lines
--- drivers/usb/gadget/function/f_midi.c | 37 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 21 deletions(-)drivers/usb/gadget/function/f_midi.c +16
-21@@ -906,9 +906,6 @@ static inline struct f_midi_opts *to_f_midi_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_midi_opts); -CONFIGFS_ATTR_OPS (f_midi_opts); -static void midi_attr_release (struct config_item *item) {struct f_midi_opts *opts =to_f_midi_opts (item);@@ -918,13 +915,12 @@ static void midi_attr_release(struct config_item *item)static struct configfs_item_operations midi_item_ops = { .release = midi_attr_release, - .show_attribute = f_midi_opts_attr_show, - .store_attribute = f_midi_opts_attr_store, };#define F_MIDI_OPT (name, test_limit, limit) \ -static ssize_t f_midi_opts_##name##_show(struct f_midi_opts *opts, char *page) \ +static ssize_t f_midi_opts_##name##_show(struct config_item *item, char *page) \ { \ + struct f_midi_opts *opts = to_f_midi_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \@@ -934,9 +930,10 @@ static ssize_t f_midi_opts_##name##_show(struct f_midi_opts *opts, char *page) \return result; \ } \ \ -static ssize_t f_midi_opts_##name##_store(struct f_midi_opts *opts, \ +static ssize_t f_midi_opts_##name##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct f_midi_opts *opts =to_f_midi_opts (item); \int ret; \u32 num; \ \@@ -962,9 +959,7 @@ end: \return ret; \ } \ \ -static struct f_midi_opts_attribute f_midi_opts_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, f_midi_opts_##name##_show, \ - f_midi_opts_##name##_store) +CONFIGFS_ATTR (f_midi_opts_, name);F_MIDI_OPT (index, true,SNDRV_CARDS );F_MIDI_OPT (buflen, false,0 );@@ -972,8 +967,9 @@ F_MIDI_OPT(qlen, false, 0);F_MIDI_OPT (in_ports, true,MAX_PORTS );F_MIDI_OPT (out_ports, true,MAX_PORTS ); -static ssize_t f_midi_opts_id_show (struct f_midi_opts *opts,char *page) +static ssize_t f_midi_opts_id_show (struct config_item *item,char *page) { +struct f_midi_opts *opts =to_f_midi_opts (item);int result;mutex_lock (&opts->lock);@@ -989,9 +985,10 @@ static ssize_t f_midi_opts_id_show(struct f_midi_opts *opts, char *page)return result; } -static ssize_t f_midi_opts_id_store (struct f_midi_opts *opts, +static ssize_t f_midi_opts_id_store (struct config_item *item,const char *page,size_t len) { +struct f_midi_opts *opts =to_f_midi_opts (item);int ret;char *c;@@ -1016,17 +1013,15 @@ end:return ret; } -static struct f_midi_opts_attribute f_midi_opts_id = -__CONFIGFS_ATTR (id,S_IRUGO |S_IWUSR , f_midi_opts_id_show, - f_midi_opts_id_store); +CONFIGFS_ATTR (f_midi_opts_, id);static struct configfs_attribute *midi_attrs[] = { - &f_midi_opts_index.attr, - &f_midi_opts_buflen.attr, - &f_midi_opts_qlen.attr, - &f_midi_opts_in_ports.attr, - &f_midi_opts_out_ports.attr, - &f_midi_opts_id.attr, + &f_midi_opts_attr_index, + &f_midi_opts_attr_buflen, + &f_midi_opts_attr_qlen, + &f_midi_opts_attr_in_ports, + &f_midi_opts_attr_out_ports, + &f_midi_opts_attr_id,NULL , };
PATCH 9/23 usb-gadget/f_printer: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_printer.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-)
drivers/usb/gadget/function/f_printer.c +12 -19
@@ -1148,9 +1148,6 @@ static inline struct f_printer_opts func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_printer_opts); -CONFIGFS_ATTR_OPS (f_printer_opts); -static void printer_attr_release (struct config_item *item) {struct f_printer_opts *opts =to_f_printer_opts (item);
@@ -1160,13 +1157,12 @@ static void printer_attr_release(struct config_item *item)static struct configfs_item_operations printer_item_ops = { .release = printer_attr_release, - .show_attribute = f_printer_opts_attr_show, - .store_attribute = f_printer_opts_attr_store, }; -static ssize_t f_printer_opts_pnp_string_show (struct f_printer_opts *opts, +static ssize_t f_printer_opts_pnp_string_show (struct config_item *item,char *page) { +struct f_printer_opts *opts =to_f_printer_opts (item);int result;mutex_lock (&opts->lock);
@@ -1176,9 +1172,10 @@ static ssize_t f_printer_opts_pnp_string_show(struct f_printer_opts *opts,return result; } -static ssize_t f_printer_opts_pnp_string_store (struct f_printer_opts *opts, +static ssize_t f_printer_opts_pnp_string_store (struct config_item *item,const char *page,size_t len) { +struct f_printer_opts *opts =to_f_printer_opts (item);int result, l;mutex_lock (&opts->lock);
@@ -1191,14 +1188,10 @@ static ssize_t f_printer_opts_pnp_string_store(struct f_printer_opts *opts,return result; } -static struct f_printer_opts_attribute f_printer_opts_pnp_string = -__CONFIGFS_ATTR (pnp_string,S_IRUGO |S_IWUSR , - f_printer_opts_pnp_string_show, - f_printer_opts_pnp_string_store); - -static ssize_t f_printer_opts_q_len_show (struct f_printer_opts *opts, +static ssize_t f_printer_opts_q_len_show (struct config_item *item,char *page) { +struct f_printer_opts *opts =to_f_printer_opts (item);int result;mutex_lock (&opts->lock);
@@ -1208,9 +1201,10 @@ static ssize_t f_printer_opts_q_len_show(struct f_printer_opts *opts,return result; } -static ssize_t f_printer_opts_q_len_store (struct f_printer_opts *opts, +static ssize_t f_printer_opts_q_len_store (struct config_item *item,const char *page,size_t len) { +struct f_printer_opts *opts =to_f_printer_opts (item);int ret;u16 num;
@@ -1231,13 +1225,12 @@ end:return ret; } -static struct f_printer_opts_attribute f_printer_opts_q_len = -__CONFIGFS_ATTR (q_len,S_IRUGO |S_IWUSR , f_printer_opts_q_len_show, - f_printer_opts_q_len_store); +CONFIGFS_ATTR (f_printer_opts_, pnp_string); +CONFIGFS_ATTR (f_printer_opts_, q_len);static struct configfs_attribute *printer_attrs[] = { - &f_printer_opts_pnp_string.attr, - &f_printer_opts_q_len.attr, + &f_printer_opts_attr_pnp_string, + &f_printer_opts_attr_q_len,NULL , };
Signature · 1 line
1.9.1
Re: [PATCH 09/23] usb-gadget/f_printer: use per-attribute show and store methods
Hi Christoph,
The same remark as for f_loopback (__CONFIGFS_ATTR location vs CONFIGFS_ATTR location after applying)
If addressed
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 95 lines
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/usb/gadget/function/f_printer.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-)drivers/usb/gadget/function/f_printer.c +12
-19@@ -1148,9 +1148,6 @@ static inline struct f_printer_opts func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_printer_opts); -CONFIGFS_ATTR_OPS (f_printer_opts); -static void printer_attr_release (struct config_item *item) {struct f_printer_opts *opts =to_f_printer_opts (item);@@ -1160,13 +1157,12 @@ static void printer_attr_release(struct config_item *item)static struct configfs_item_operations printer_item_ops = { .release = printer_attr_release, - .show_attribute = f_printer_opts_attr_show, - .store_attribute = f_printer_opts_attr_store, }; -static ssize_t f_printer_opts_pnp_string_show (struct f_printer_opts *opts, +static ssize_t f_printer_opts_pnp_string_show (struct config_item *item,char *page) { +struct f_printer_opts *opts =to_f_printer_opts (item);int result;mutex_lock (&opts->lock);@@ -1176,9 +1172,10 @@ static ssize_t f_printer_opts_pnp_string_show(struct f_printer_opts *opts,return result; } -static ssize_t f_printer_opts_pnp_string_store (struct f_printer_opts *opts, +static ssize_t f_printer_opts_pnp_string_store (struct config_item *item,const char *page,size_t len) { +struct f_printer_opts *opts =to_f_printer_opts (item);int result, l;mutex_lock (&opts->lock);@@ -1191,14 +1188,10 @@ static ssize_t f_printer_opts_pnp_string_store(struct f_printer_opts *opts,return result; } -static struct f_printer_opts_attribute f_printer_opts_pnp_string = -__CONFIGFS_ATTR (pnp_string,S_IRUGO |S_IWUSR , - f_printer_opts_pnp_string_show, - f_printer_opts_pnp_string_store); - -static ssize_t f_printer_opts_q_len_show (struct f_printer_opts *opts, +static ssize_t f_printer_opts_q_len_show (struct config_item *item,char *page) { +struct f_printer_opts *opts =to_f_printer_opts (item);int result;mutex_lock (&opts->lock);@@ -1208,9 +1201,10 @@ static ssize_t f_printer_opts_q_len_show(struct f_printer_opts *opts,return result; } -static ssize_t f_printer_opts_q_len_store (struct f_printer_opts *opts, +static ssize_t f_printer_opts_q_len_store (struct config_item *item,const char *page,size_t len) { +struct f_printer_opts *opts =to_f_printer_opts (item);int ret;u16 num;@@ -1231,13 +1225,12 @@ end:return ret; } -static struct f_printer_opts_attribute f_printer_opts_q_len = -__CONFIGFS_ATTR (q_len,S_IRUGO |S_IWUSR , f_printer_opts_q_len_show, - f_printer_opts_q_len_store); +CONFIGFS_ATTR (f_printer_opts_, pnp_string); +CONFIGFS_ATTR (f_printer_opts_, q_len);static struct configfs_attribute *printer_attrs[] = { - &f_printer_opts_pnp_string.attr, - &f_printer_opts_q_len.attr, + &f_printer_opts_attr_pnp_string, + &f_printer_opts_attr_q_len,NULL , };
PATCH 10/23 usb-gadget/f_sourcesink: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_sourcesink.c | 88 ++++++++++++------------------ 1 file changed, 36 insertions(+), 52 deletions(-)
drivers/usb/gadget/function/f_sourcesink.c +36 -52
@@ -898,9 +898,6 @@ static inline struct f_ss_opts *to_f_ss_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_ss_opts); -CONFIGFS_ATTR_OPS (f_ss_opts); -static void ss_attr_release (struct config_item *item) {struct f_ss_opts *ss_opts =to_f_ss_opts (item);
@@ -910,12 +907,11 @@ static void ss_attr_release(struct config_item *item)static struct configfs_item_operations ss_item_ops = { .release = ss_attr_release, - .show_attribute = f_ss_opts_attr_show, - .store_attribute = f_ss_opts_attr_store, }; -static ssize_t f_ss_opts_pattern_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_pattern_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);
@@ -925,9 +921,10 @@ static ssize_t f_ss_opts_pattern_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_pattern_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_pattern_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u8 num;
@@ -953,13 +950,9 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_pattern = -__CONFIGFS_ATTR (pattern,S_IRUGO |S_IWUSR , - f_ss_opts_pattern_show, - f_ss_opts_pattern_store); - -static ssize_t f_ss_opts_isoc_interval_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_isoc_interval_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);
@@ -969,9 +962,10 @@ static ssize_t f_ss_opts_isoc_interval_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_isoc_interval_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_isoc_interval_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u8 num;
@@ -997,13 +991,9 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_isoc_interval = -__CONFIGFS_ATTR (isoc_interval,S_IRUGO |S_IWUSR , - f_ss_opts_isoc_interval_show, - f_ss_opts_isoc_interval_store); - -static ssize_t f_ss_opts_isoc_maxpacket_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_isoc_maxpacket_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);
@@ -1013,9 +1003,10 @@ static ssize_t f_ss_opts_isoc_maxpacket_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_isoc_maxpacket_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_isoc_maxpacket_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u16 num;
@@ -1041,13 +1032,9 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_isoc_maxpacket = -__CONFIGFS_ATTR (isoc_maxpacket,S_IRUGO |S_IWUSR , - f_ss_opts_isoc_maxpacket_show, - f_ss_opts_isoc_maxpacket_store); - -static ssize_t f_ss_opts_isoc_mult_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_isoc_mult_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);
@@ -1057,9 +1044,10 @@ static ssize_t f_ss_opts_isoc_mult_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_isoc_mult_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_isoc_mult_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u8 num;
@@ -1085,13 +1073,9 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_isoc_mult = -__CONFIGFS_ATTR (isoc_mult,S_IRUGO |S_IWUSR , - f_ss_opts_isoc_mult_show, - f_ss_opts_isoc_mult_store); - -static ssize_t f_ss_opts_isoc_maxburst_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_isoc_maxburst_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);
@@ -1101,9 +1085,10 @@ static ssize_t f_ss_opts_isoc_maxburst_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_isoc_maxburst_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_isoc_maxburst_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u8 num;
@@ -1129,13 +1114,9 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_isoc_maxburst = -__CONFIGFS_ATTR (isoc_maxburst,S_IRUGO |S_IWUSR , - f_ss_opts_isoc_maxburst_show, - f_ss_opts_isoc_maxburst_store); - -static ssize_t f_ss_opts_bulk_buflen_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_bulk_buflen_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);
@@ -1145,9 +1126,10 @@ static ssize_t f_ss_opts_bulk_buflen_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_bulk_buflen_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_bulk_buflen_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u32 num;
@@ -1168,18 +1150,20 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_bulk_buflen = -__CONFIGFS_ATTR (buflen,S_IRUGO |S_IWUSR , - f_ss_opts_bulk_buflen_show, - f_ss_opts_bulk_buflen_store); +CONFIGFS_ATTR (f_ss_opts_, pattern); +CONFIGFS_ATTR (f_ss_opts_, isoc_interval); +CONFIGFS_ATTR (f_ss_opts_, isoc_maxpacket); +CONFIGFS_ATTR (f_ss_opts_, isoc_mult); +CONFIGFS_ATTR (f_ss_opts_, isoc_maxburst); +CONFIGFS_ATTR (f_ss_opts_, bulk_buflen);static struct configfs_attribute *ss_attrs[] = { - &f_ss_opts_pattern.attr, - &f_ss_opts_isoc_interval.attr, - &f_ss_opts_isoc_maxpacket.attr, - &f_ss_opts_isoc_mult.attr, - &f_ss_opts_isoc_maxburst.attr, - &f_ss_opts_bulk_buflen.attr, + &f_ss_opts_attr_pattern, + &f_ss_opts_attr_isoc_interval, + &f_ss_opts_attr_isoc_maxpacket, + &f_ss_opts_attr_isoc_mult, + &f_ss_opts_attr_isoc_maxburst, + &f_ss_opts_attr_bulk_buflen,NULL , };
Signature · 1 line
1.9.1
Re: [PATCH 10/23] usb-gadget/f_sourcesink: use per-attribute show and store methods
Hi Christoph,
The same remark as for f_loopback (__CONFIGFS_ATTR location vs CONFIGFS_ATTR location after applying)
If addressed
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 218 lines
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/usb/gadget/function/f_sourcesink.c | 88 ++++++++++++------------------ 1 file changed, 36 insertions(+), 52 deletions(-)drivers/usb/gadget/function/f_sourcesink.c +36
-52@@ -898,9 +898,6 @@ static inline struct f_ss_opts *to_f_ss_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_ss_opts); -CONFIGFS_ATTR_OPS (f_ss_opts); -static void ss_attr_release (struct config_item *item) {struct f_ss_opts *ss_opts =to_f_ss_opts (item);@@ -910,12 +907,11 @@ static void ss_attr_release(struct config_item *item)static struct configfs_item_operations ss_item_ops = { .release = ss_attr_release, - .show_attribute = f_ss_opts_attr_show, - .store_attribute = f_ss_opts_attr_store, }; -static ssize_t f_ss_opts_pattern_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_pattern_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);@@ -925,9 +921,10 @@ static ssize_t f_ss_opts_pattern_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_pattern_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_pattern_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u8 num;@@ -953,13 +950,9 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_pattern = -__CONFIGFS_ATTR (pattern,S_IRUGO |S_IWUSR , - f_ss_opts_pattern_show, - f_ss_opts_pattern_store); - -static ssize_t f_ss_opts_isoc_interval_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_isoc_interval_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);@@ -969,9 +962,10 @@ static ssize_t f_ss_opts_isoc_interval_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_isoc_interval_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_isoc_interval_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u8 num;@@ -997,13 +991,9 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_isoc_interval = -__CONFIGFS_ATTR (isoc_interval,S_IRUGO |S_IWUSR , - f_ss_opts_isoc_interval_show, - f_ss_opts_isoc_interval_store); - -static ssize_t f_ss_opts_isoc_maxpacket_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_isoc_maxpacket_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);@@ -1013,9 +1003,10 @@ static ssize_t f_ss_opts_isoc_maxpacket_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_isoc_maxpacket_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_isoc_maxpacket_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u16 num;@@ -1041,13 +1032,9 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_isoc_maxpacket = -__CONFIGFS_ATTR (isoc_maxpacket,S_IRUGO |S_IWUSR , - f_ss_opts_isoc_maxpacket_show, - f_ss_opts_isoc_maxpacket_store); - -static ssize_t f_ss_opts_isoc_mult_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_isoc_mult_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);@@ -1057,9 +1044,10 @@ static ssize_t f_ss_opts_isoc_mult_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_isoc_mult_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_isoc_mult_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u8 num;@@ -1085,13 +1073,9 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_isoc_mult = -__CONFIGFS_ATTR (isoc_mult,S_IRUGO |S_IWUSR , - f_ss_opts_isoc_mult_show, - f_ss_opts_isoc_mult_store); - -static ssize_t f_ss_opts_isoc_maxburst_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_isoc_maxburst_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);@@ -1101,9 +1085,10 @@ static ssize_t f_ss_opts_isoc_maxburst_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_isoc_maxburst_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_isoc_maxburst_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u8 num;@@ -1129,13 +1114,9 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_isoc_maxburst = -__CONFIGFS_ATTR (isoc_maxburst,S_IRUGO |S_IWUSR , - f_ss_opts_isoc_maxburst_show, - f_ss_opts_isoc_maxburst_store); - -static ssize_t f_ss_opts_bulk_buflen_show (struct f_ss_opts *opts,char *page) +static ssize_t f_ss_opts_bulk_buflen_show (struct config_item *item,char *page) { +struct f_ss_opts *opts =to_f_ss_opts (item);int result;mutex_lock (&opts->lock);@@ -1145,9 +1126,10 @@ static ssize_t f_ss_opts_bulk_buflen_show(struct f_ss_opts *opts, char *page)return result; } -static ssize_t f_ss_opts_bulk_buflen_store (struct f_ss_opts *opts, +static ssize_t f_ss_opts_bulk_buflen_store (struct config_item *item,const char *page,size_t len) { +struct f_ss_opts *opts =to_f_ss_opts (item);int ret;u32 num;@@ -1168,18 +1150,20 @@ end:return ret; } -static struct f_ss_opts_attribute f_ss_opts_bulk_buflen = -__CONFIGFS_ATTR (buflen,S_IRUGO |S_IWUSR , - f_ss_opts_bulk_buflen_show, - f_ss_opts_bulk_buflen_store); +CONFIGFS_ATTR (f_ss_opts_, pattern); +CONFIGFS_ATTR (f_ss_opts_, isoc_interval); +CONFIGFS_ATTR (f_ss_opts_, isoc_maxpacket); +CONFIGFS_ATTR (f_ss_opts_, isoc_mult); +CONFIGFS_ATTR (f_ss_opts_, isoc_maxburst); +CONFIGFS_ATTR (f_ss_opts_, bulk_buflen);static struct configfs_attribute *ss_attrs[] = { - &f_ss_opts_pattern.attr, - &f_ss_opts_isoc_interval.attr, - &f_ss_opts_isoc_maxpacket.attr, - &f_ss_opts_isoc_mult.attr, - &f_ss_opts_isoc_maxburst.attr, - &f_ss_opts_bulk_buflen.attr, + &f_ss_opts_attr_pattern, + &f_ss_opts_attr_isoc_interval, + &f_ss_opts_attr_isoc_maxpacket, + &f_ss_opts_attr_isoc_mult, + &f_ss_opts_attr_isoc_maxburst, + &f_ss_opts_attr_bulk_buflen,NULL , };
PATCH 11/23 usb-gadget/f_mass_storage: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_mass_storage.c | 123 ++++++++++----------------- 1 file changed, 46 insertions(+), 77 deletions(-)
drivers/usb/gadget/function/f_mass_storage.c +46 -77
@@ -3144,9 +3144,6 @@ static inline struct fsg_opts *to_fsg_opts(struct config_item *item) 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) {struct fsg_lun_opts *lun_opts;
@@ -3157,110 +3154,89 @@ static void fsg_lun_attr_release(struct config_item *item)static struct configfs_item_operations fsg_lun_item_ops = { .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; - - fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent); +struct fsg_lun_opts *opts =to_fsg_lun_opts (item); +struct fsg_opts *fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent);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) { -struct fsg_opts *fsg_opts; - - fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent); +struct fsg_lun_opts *opts =to_fsg_lun_opts (item); +struct fsg_opts *fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent);return fsg_store_file (opts->lun, &fsg_opts->common->filesem, page, len); } -static struct fsg_lun_opts_attribute 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) { -struct fsg_opts *fsg_opts; - - fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent); +struct fsg_lun_opts *opts =to_fsg_lun_opts (item); +struct fsg_opts *fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent);return fsg_store_ro (opts->lun, &fsg_opts->common->filesem, page, len); } -static struct fsg_lun_opts_attribute 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) { -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) { -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 (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) { -struct fsg_opts *fsg_opts; - - fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent); +struct fsg_lun_opts *opts =to_fsg_lun_opts (item); +struct fsg_opts *fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent);return fsg_store_cdrom (opts->lun, &fsg_opts->common->filesem, page, len); } -static struct fsg_lun_opts_attribute 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) { -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 (nofua,S_IRUGO |S_IWUSR , fsg_lun_opts_nofua_show, - fsg_lun_opts_nofua_store); +CONFIGFS_ATTR (fsg_lun_opts_, file); +CONFIGFS_ATTR (fsg_lun_opts_, ro); +CONFIGFS_ATTR (fsg_lun_opts_, removable); +CONFIGFS_ATTR (fsg_lun_opts_, cdrom); +CONFIGFS_ATTR (fsg_lun_opts_, nofua);static struct configfs_attribute *fsg_lun_attrs[] = { - &fsg_lun_opts_file.attr, - &fsg_lun_opts_ro.attr, - &fsg_lun_opts_removable.attr, - &fsg_lun_opts_cdrom.attr, - &fsg_lun_opts_nofua.attr, + &fsg_lun_opts_attr_file, + &fsg_lun_opts_attr_ro, + &fsg_lun_opts_attr_removable, + &fsg_lun_opts_attr_cdrom, + &fsg_lun_opts_attr_nofua,NULL , };
@@ -3352,9 +3328,6 @@ static void fsg_lun_drop(struct config_group *group, struct config_item *item)config_item_put (item); } -CONFIGFS_ATTR_STRUCT (fsg_opts); -CONFIGFS_ATTR_OPS (fsg_opts); -static void fsg_attr_release (struct config_item *item) {struct fsg_opts *opts =to_fsg_opts (item);
@@ -3364,12 +3337,11 @@ static void fsg_attr_release(struct config_item *item)static struct configfs_item_operations fsg_item_ops = { .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;mutex_lock (&opts->lock);
@@ -3379,9 +3351,10 @@ static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page)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) { +struct fsg_opts *opts =to_fsg_opts (item);int ret;bool stall;
@@ -3403,13 +3376,12 @@ static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page,return ret; } -static struct fsg_opts_attribute fsg_opts_stall = -__CONFIGFS_ATTR (stall,S_IRUGO |S_IWUSR , fsg_opts_stall_show, - fsg_opts_stall_store); +CONFIGFS_ATTR (fsg_opts_, stall);#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;mutex_lock (&opts->lock);
@@ -3419,9 +3391,10 @@ static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page)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) { +struct fsg_opts *opts =to_fsg_opts (item);int ret;u8 num;
@@ -3446,17 +3419,13 @@ end:return ret; } -static struct fsg_opts_attribute fsg_opts_num_buffers = -__CONFIGFS_ATTR (num_buffers,S_IRUGO |S_IWUSR , - fsg_opts_num_buffers_show, - fsg_opts_num_buffers_store); - +CONFIGFS_ATTR (fsg_opts_, num_buffers);#endif static struct configfs_attribute *fsg_attrs[] = { - &fsg_opts_stall.attr, + &fsg_opts_attr_stall, #ifdef CONFIG_USB_GADGET_DEBUG_FILES - &fsg_opts_num_buffers.attr, + &fsg_opts_attr_num_buffers, #endifNULL , };
Signature · 1 line
1.9.1
Re: [PATCH 11/23] usb-gadget/f_mass_storage: use per-attribute show and store methods
Hi Christoph,
The same remark as for f_loopback (__CONFIGFS_ATTR location vs CONFIGFS_ATTR location after applying)
If addressed
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 252 lines
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/usb/gadget/function/f_mass_storage.c | 123 ++++++++++----------------- 1 file changed, 46 insertions(+), 77 deletions(-)drivers/usb/gadget/function/f_mass_storage.c +46
-77@@ -3144,9 +3144,6 @@ static inline struct fsg_opts *to_fsg_opts(struct config_item *item) 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) {struct fsg_lun_opts *lun_opts;@@ -3157,110 +3154,89 @@ static void fsg_lun_attr_release(struct config_item *item)static struct configfs_item_operations fsg_lun_item_ops = { .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; - - fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent); +struct fsg_lun_opts *opts =to_fsg_lun_opts (item); +struct fsg_opts *fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent);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) { -struct fsg_opts *fsg_opts; - - fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent); +struct fsg_lun_opts *opts =to_fsg_lun_opts (item); +struct fsg_opts *fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent);return fsg_store_file (opts->lun, &fsg_opts->common->filesem, page, len); } -static struct fsg_lun_opts_attribute 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) { -struct fsg_opts *fsg_opts; - - fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent); +struct fsg_lun_opts *opts =to_fsg_lun_opts (item); +struct fsg_opts *fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent);return fsg_store_ro (opts->lun, &fsg_opts->common->filesem, page, len); } -static struct fsg_lun_opts_attribute 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) { -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) { -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 (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) { -struct fsg_opts *fsg_opts; - - fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent); +struct fsg_lun_opts *opts =to_fsg_lun_opts (item); +struct fsg_opts *fsg_opts =to_fsg_opts (opts->group.cg_item.ci_parent);return fsg_store_cdrom (opts->lun, &fsg_opts->common->filesem, page, len); } -static struct fsg_lun_opts_attribute 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) { -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 (nofua,S_IRUGO |S_IWUSR , fsg_lun_opts_nofua_show, - fsg_lun_opts_nofua_store); +CONFIGFS_ATTR (fsg_lun_opts_, file); +CONFIGFS_ATTR (fsg_lun_opts_, ro); +CONFIGFS_ATTR (fsg_lun_opts_, removable); +CONFIGFS_ATTR (fsg_lun_opts_, cdrom); +CONFIGFS_ATTR (fsg_lun_opts_, nofua);static struct configfs_attribute *fsg_lun_attrs[] = { - &fsg_lun_opts_file.attr, - &fsg_lun_opts_ro.attr, - &fsg_lun_opts_removable.attr, - &fsg_lun_opts_cdrom.attr, - &fsg_lun_opts_nofua.attr, + &fsg_lun_opts_attr_file, + &fsg_lun_opts_attr_ro, + &fsg_lun_opts_attr_removable, + &fsg_lun_opts_attr_cdrom, + &fsg_lun_opts_attr_nofua,NULL , };@@ -3352,9 +3328,6 @@ static void fsg_lun_drop(struct config_group *group, struct config_item *item)config_item_put (item); } -CONFIGFS_ATTR_STRUCT (fsg_opts); -CONFIGFS_ATTR_OPS (fsg_opts); -static void fsg_attr_release (struct config_item *item) {struct fsg_opts *opts =to_fsg_opts (item);@@ -3364,12 +3337,11 @@ static void fsg_attr_release(struct config_item *item)static struct configfs_item_operations fsg_item_ops = { .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;mutex_lock (&opts->lock);@@ -3379,9 +3351,10 @@ static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page)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) { +struct fsg_opts *opts =to_fsg_opts (item);int ret;bool stall;@@ -3403,13 +3376,12 @@ static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page,return ret; } -static struct fsg_opts_attribute fsg_opts_stall = -__CONFIGFS_ATTR (stall,S_IRUGO |S_IWUSR , fsg_opts_stall_show, - fsg_opts_stall_store); +CONFIGFS_ATTR (fsg_opts_, stall);#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;mutex_lock (&opts->lock);@@ -3419,9 +3391,10 @@ static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page)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) { +struct fsg_opts *opts =to_fsg_opts (item);int ret;u8 num;@@ -3446,17 +3419,13 @@ end:return ret; } -static struct fsg_opts_attribute fsg_opts_num_buffers = -__CONFIGFS_ATTR (num_buffers,S_IRUGO |S_IWUSR , - fsg_opts_num_buffers_show, - fsg_opts_num_buffers_store); - +CONFIGFS_ATTR (fsg_opts_, num_buffers);#endif static struct configfs_attribute *fsg_attrs[] = { - &fsg_opts_stall.attr, + &fsg_opts_attr_stall, #ifdef CONFIG_USB_GADGET_DEBUG_FILES - &fsg_opts_num_buffers.attr, + &fsg_opts_attr_num_buffers, #endifNULL , };
PATCH 12/23 usb-gadget/f_ac1: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_uac1.c | 39 +++++++++++++++--------------------- 1 file changed, 16 insertions(+), 23 deletions(-)
drivers/usb/gadget/function/f_uac1.c +16 -23
@@ -773,9 +773,6 @@ static inline struct f_uac1_opts *to_f_uac1_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_uac1_opts); -CONFIGFS_ATTR_OPS (f_uac1_opts); -static void f_uac1_attr_release (struct config_item *item) {struct f_uac1_opts *opts =to_f_uac1_opts (item);
@@ -785,14 +782,13 @@ static void f_uac1_attr_release(struct config_item *item)static struct configfs_item_operations f_uac1_item_ops = { .release = f_uac1_attr_release, - .show_attribute = f_uac1_opts_attr_show, - .store_attribute = f_uac1_opts_attr_store, };#define UAC1_INT_ATTRIBUTE (name) \ -static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \ +static ssize_t f_uac1_opts_##name##_show(struct config_item *item, \ char *page) \ { \ + struct f_uac1_opts *opts = to_f_uac1_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \
@@ -802,9 +798,10 @@ static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \return result; \ } \ \ -static ssize_t f_uac1_opts_##name##_store(struct f_uac1_opts *opts, \ +static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct f_uac1_opts *opts =to_f_uac1_opts (item); \int ret; \u32 num; \ \
@@ -826,19 +823,17 @@ end: \return ret; \ } \ \ -static struct f_uac1_opts_attribute f_uac1_opts_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - f_uac1_opts_##name##_show, \ - f_uac1_opts_##name##_store) +CONFIGFS_ATTR(f_uac1_opts_, name)UAC1_INT_ATTRIBUTE (req_buf_size);UAC1_INT_ATTRIBUTE (req_count);UAC1_INT_ATTRIBUTE (audio_buf_size);#define UAC1_STR_ATTRIBUTE (name) \ -static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \ +static ssize_t f_uac1_opts_##name##_show(struct config_item *item, \ char *page) \ { \ + struct f_uac1_opts *opts = to_f_uac1_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \
@@ -848,9 +843,10 @@ static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \return result; \ } \ \ -static ssize_t f_uac1_opts_##name##_store(struct f_uac1_opts *opts, \ +static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct f_uac1_opts *opts =to_f_uac1_opts (item); \int ret = -EBUSY ; \char *tmp; \ \
@@ -874,22 +870,19 @@ end: \return ret; \ } \ \ -static struct f_uac1_opts_attribute f_uac1_opts_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - f_uac1_opts_##name##_show, \ - f_uac1_opts_##name##_store) +CONFIGFS_ATTR(f_uac1_opts_, name)UAC1_STR_ATTRIBUTE (fn_play);UAC1_STR_ATTRIBUTE (fn_cap);UAC1_STR_ATTRIBUTE (fn_cntl);static struct configfs_attribute *f_uac1_attrs[] = { - &f_uac1_opts_req_buf_size.attr, - &f_uac1_opts_req_count.attr, - &f_uac1_opts_audio_buf_size.attr, - &f_uac1_opts_fn_play.attr, - &f_uac1_opts_fn_cap.attr, - &f_uac1_opts_fn_cntl.attr, + &f_uac1_opts_attr_req_buf_size, + &f_uac1_opts_attr_req_count, + &f_uac1_opts_attr_audio_buf_size, + &f_uac1_opts_attr_fn_play, + &f_uac1_opts_attr_fn_cap, + &f_uac1_opts_attr_fn_cntl,NULL , };
Signature · 1 line
1.9.1
Re: [PATCH 12/23] usb-gadget/f_ac1: use per-attribute show and store methods
Hi Christoph,
The commit title should be ".... usb-gadget/f_uac1 ..." instead of ".... f_ac1 ..."
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 114 lines
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/usb/gadget/function/f_uac1.c | 39 +++++++++++++++--------------------- 1 file changed, 16 insertions(+), 23 deletions(-)drivers/usb/gadget/function/f_uac1.c +16
-23@@ -773,9 +773,6 @@ static inline struct f_uac1_opts *to_f_uac1_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_uac1_opts); -CONFIGFS_ATTR_OPS (f_uac1_opts); -static void f_uac1_attr_release (struct config_item *item) {struct f_uac1_opts *opts =to_f_uac1_opts (item);@@ -785,14 +782,13 @@ static void f_uac1_attr_release(struct config_item *item)static struct configfs_item_operations f_uac1_item_ops = { .release = f_uac1_attr_release, - .show_attribute = f_uac1_opts_attr_show, - .store_attribute = f_uac1_opts_attr_store, };#define UAC1_INT_ATTRIBUTE (name) \ -static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \ +static ssize_t f_uac1_opts_##name##_show(struct config_item *item, \ char *page) \ { \ + struct f_uac1_opts *opts = to_f_uac1_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \@@ -802,9 +798,10 @@ static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \return result; \ } \ \ -static ssize_t f_uac1_opts_##name##_store(struct f_uac1_opts *opts, \ +static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct f_uac1_opts *opts =to_f_uac1_opts (item); \int ret; \u32 num; \ \@@ -826,19 +823,17 @@ end: \return ret; \ } \ \ -static struct f_uac1_opts_attribute f_uac1_opts_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - f_uac1_opts_##name##_show, \ - f_uac1_opts_##name##_store) +CONFIGFS_ATTR(f_uac1_opts_, name)UAC1_INT_ATTRIBUTE (req_buf_size);UAC1_INT_ATTRIBUTE (req_count);UAC1_INT_ATTRIBUTE (audio_buf_size);#define UAC1_STR_ATTRIBUTE (name) \ -static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \ +static ssize_t f_uac1_opts_##name##_show(struct config_item *item, \ char *page) \ { \ + struct f_uac1_opts *opts = to_f_uac1_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \@@ -848,9 +843,10 @@ static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \return result; \ } \ \ -static ssize_t f_uac1_opts_##name##_store(struct f_uac1_opts *opts, \ +static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct f_uac1_opts *opts =to_f_uac1_opts (item); \int ret = -EBUSY ; \char *tmp; \ \@@ -874,22 +870,19 @@ end: \return ret; \ } \ \ -static struct f_uac1_opts_attribute f_uac1_opts_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - f_uac1_opts_##name##_show, \ - f_uac1_opts_##name##_store) +CONFIGFS_ATTR(f_uac1_opts_, name)UAC1_STR_ATTRIBUTE (fn_play);UAC1_STR_ATTRIBUTE (fn_cap);UAC1_STR_ATTRIBUTE (fn_cntl);static struct configfs_attribute *f_uac1_attrs[] = { - &f_uac1_opts_req_buf_size.attr, - &f_uac1_opts_req_count.attr, - &f_uac1_opts_audio_buf_size.attr, - &f_uac1_opts_fn_play.attr, - &f_uac1_opts_fn_cap.attr, - &f_uac1_opts_fn_cntl.attr, + &f_uac1_opts_attr_req_buf_size, + &f_uac1_opts_attr_req_count, + &f_uac1_opts_attr_audio_buf_size, + &f_uac1_opts_attr_fn_play, + &f_uac1_opts_attr_fn_cap, + &f_uac1_opts_attr_fn_cntl,NULL , };
PATCH 13/23 usb-gadget/f_uac2: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_uac2.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
drivers/usb/gadget/function/f_uac2.c +11 -17
@@ -1445,9 +1445,6 @@ static inline struct f_uac2_opts *to_f_uac2_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_uac2_opts); -CONFIGFS_ATTR_OPS (f_uac2_opts); -static void f_uac2_attr_release (struct config_item *item) {struct f_uac2_opts *opts =to_f_uac2_opts (item);
@@ -1457,14 +1454,13 @@ static void f_uac2_attr_release(struct config_item *item)static struct configfs_item_operations f_uac2_item_ops = { .release = f_uac2_attr_release, - .show_attribute = f_uac2_opts_attr_show, - .store_attribute = f_uac2_opts_attr_store, };#define UAC2_ATTRIBUTE (name) \ -static ssize_t f_uac2_opts_##name##_show(struct f_uac2_opts *opts, \ +static ssize_t f_uac2_opts_##name##_show(struct config_item *item, \ char *page) \ { \ + struct f_uac2_opts *opts = to_f_uac2_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \
@@ -1474,9 +1470,10 @@ static ssize_t f_uac2_opts_##name##_show(struct f_uac2_opts *opts, \return result; \ } \ \ -static ssize_t f_uac2_opts_##name##_store(struct f_uac2_opts *opts, \ +static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct f_uac2_opts *opts =to_f_uac2_opts (item); \int ret; \u32 num; \ \
@@ -1498,10 +1495,7 @@ end: \return ret; \ } \ \ -static struct f_uac2_opts_attribute f_uac2_opts_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - f_uac2_opts_##name##_show, \ - f_uac2_opts_##name##_store) +CONFIGFS_ATTR(f_uac2_opts_, name)UAC2_ATTRIBUTE (p_chmask);UAC2_ATTRIBUTE (p_srate);
@@ -1511,12 +1505,12 @@ UAC2_ATTRIBUTE(c_srate);UAC2_ATTRIBUTE (c_ssize);static struct configfs_attribute *f_uac2_attrs[] = { - &f_uac2_opts_p_chmask.attr, - &f_uac2_opts_p_srate.attr, - &f_uac2_opts_p_ssize.attr, - &f_uac2_opts_c_chmask.attr, - &f_uac2_opts_c_srate.attr, - &f_uac2_opts_c_ssize.attr, + &f_uac2_opts_attr_p_chmask, + &f_uac2_opts_attr_p_srate, + &f_uac2_opts_attr_p_ssize, + &f_uac2_opts_attr_c_chmask, + &f_uac2_opts_attr_c_srate, + &f_uac2_opts_attr_c_ssize,NULL , };
Signature · 1 line
1.9.1
Re: [PATCH 13/23] usb-gadget/f_uac2: use per-attribute show and store methods
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 79 lines
--- drivers/usb/gadget/function/f_uac2.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)drivers/usb/gadget/function/f_uac2.c +11
-17@@ -1445,9 +1445,6 @@ static inline struct f_uac2_opts *to_f_uac2_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_uac2_opts); -CONFIGFS_ATTR_OPS (f_uac2_opts); -static void f_uac2_attr_release (struct config_item *item) {struct f_uac2_opts *opts =to_f_uac2_opts (item);@@ -1457,14 +1454,13 @@ static void f_uac2_attr_release(struct config_item *item)static struct configfs_item_operations f_uac2_item_ops = { .release = f_uac2_attr_release, - .show_attribute = f_uac2_opts_attr_show, - .store_attribute = f_uac2_opts_attr_store, };#define UAC2_ATTRIBUTE (name) \ -static ssize_t f_uac2_opts_##name##_show(struct f_uac2_opts *opts, \ +static ssize_t f_uac2_opts_##name##_show(struct config_item *item, \ char *page) \ { \ + struct f_uac2_opts *opts = to_f_uac2_opts(item); \ int result; \ \ mutex_lock(&opts->lock); \@@ -1474,9 +1470,10 @@ static ssize_t f_uac2_opts_##name##_show(struct f_uac2_opts *opts, \return result; \ } \ \ -static ssize_t f_uac2_opts_##name##_store(struct f_uac2_opts *opts, \ +static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \const char *page,size_t len) \ { \ +struct f_uac2_opts *opts =to_f_uac2_opts (item); \int ret; \u32 num; \ \@@ -1498,10 +1495,7 @@ end: \return ret; \ } \ \ -static struct f_uac2_opts_attribute f_uac2_opts_##name = \ - __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ - f_uac2_opts_##name##_show, \ - f_uac2_opts_##name##_store) +CONFIGFS_ATTR(f_uac2_opts_, name)UAC2_ATTRIBUTE (p_chmask);UAC2_ATTRIBUTE (p_srate);@@ -1511,12 +1505,12 @@ UAC2_ATTRIBUTE(c_srate);UAC2_ATTRIBUTE (c_ssize);static struct configfs_attribute *f_uac2_attrs[] = { - &f_uac2_opts_p_chmask.attr, - &f_uac2_opts_p_srate.attr, - &f_uac2_opts_p_ssize.attr, - &f_uac2_opts_c_chmask.attr, - &f_uac2_opts_c_srate.attr, - &f_uac2_opts_c_ssize.attr, + &f_uac2_opts_attr_p_chmask, + &f_uac2_opts_attr_p_srate, + &f_uac2_opts_attr_p_ssize, + &f_uac2_opts_attr_c_chmask, + &f_uac2_opts_attr_c_srate, + &f_uac2_opts_attr_c_ssize,NULL , };
PATCH 14/23 usb-gadget/f_obex: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_obex.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/usb/gadget/function/f_obex.c +4 -22
@@ -395,22 +395,6 @@ static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_serial_opts); -static ssize_t f_obex_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -struct f_serial_opts *opts =to_f_serial_opts (item); -struct f_serial_opts_attribute *f_serial_opts_attr = - container_of(attr, struct f_serial_opts_attribute, attr); -ssize_t ret =0 ; - -if (f_serial_opts_attr->show) - ret = f_serial_opts_attr->show (opts, page); - -return ret; -} -static void obex_attr_release (struct config_item *item) {struct f_serial_opts *opts =to_f_serial_opts (item);
@@ -420,19 +404,17 @@ static void obex_attr_release(struct config_item *item)static struct configfs_item_operations obex_item_ops = { .release = obex_attr_release, - .show_attribute = f_obex_attr_show, }; -static ssize_t f_obex_port_num_show (struct f_serial_opts *opts,char *page) +static ssize_t f_obex_port_num_show (struct config_item *item,char *page) { -return sprintf (page,"%u\n" , opts->port_num); +return sprintf (page,"%u\n" ,to_f_serial_opts (item)->port_num); } -static struct f_serial_opts_attribute f_obex_port_num = -__CONFIGFS_ATTR_RO (port_num, f_obex_port_num_show); +CONFIGFS_ATTR_RO (f_obex_, port_num);static struct configfs_attribute *acm_attrs[] = { - &f_obex_port_num.attr, + &f_obex_attr_port_num,NULL , };
Signature · 1 line
1.9.1
Re: [PATCH 14/23] usb-gadget/f_obex: use per-attribute show and store methods
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 56 lines
--- drivers/usb/gadget/function/f_obex.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)drivers/usb/gadget/function/f_obex.c +4
-22@@ -395,22 +395,6 @@ static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_serial_opts); -static ssize_t f_obex_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -struct f_serial_opts *opts =to_f_serial_opts (item); -struct f_serial_opts_attribute *f_serial_opts_attr = - container_of(attr, struct f_serial_opts_attribute, attr); -ssize_t ret =0 ; - -if (f_serial_opts_attr->show) - ret = f_serial_opts_attr->show (opts, page); - -return ret; -} -static void obex_attr_release (struct config_item *item) {struct f_serial_opts *opts =to_f_serial_opts (item);@@ -420,19 +404,17 @@ static void obex_attr_release(struct config_item *item)static struct configfs_item_operations obex_item_ops = { .release = obex_attr_release, - .show_attribute = f_obex_attr_show, }; -static ssize_t f_obex_port_num_show (struct f_serial_opts *opts,char *page) +static ssize_t f_obex_port_num_show (struct config_item *item,char *page) { -return sprintf (page,"%u\n" , opts->port_num); +return sprintf (page,"%u\n" ,to_f_serial_opts (item)->port_num); } -static struct f_serial_opts_attribute f_obex_port_num = -__CONFIGFS_ATTR_RO (port_num, f_obex_port_num_show); +CONFIGFS_ATTR_RO (f_obex_, port_num);static struct configfs_attribute *acm_attrs[] = { - &f_obex_port_num.attr, + &f_obex_attr_port_num,NULL , };
PATCH 15/23 usb-gadget/f_phonet: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_phonet.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-)
drivers/usb/gadget/function/f_phonet.c +4 -21
@@ -589,21 +589,6 @@ static inline struct f_phonet_opts *to_f_phonet_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_phonet_opts); -static ssize_t f_phonet_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -struct f_phonet_opts *opts =to_f_phonet_opts (item); -struct f_phonet_opts_attribute *f_phonet_opts_attr = - container_of(attr, struct f_phonet_opts_attribute, attr); -ssize_t ret =0 ; - -if (f_phonet_opts_attr->show) - ret = f_phonet_opts_attr->show (opts, page); -return ret; -} -static void phonet_attr_release (struct config_item *item) {struct f_phonet_opts *opts =to_f_phonet_opts (item);
@@ -613,19 +598,17 @@ static void phonet_attr_release(struct config_item *item)static struct configfs_item_operations phonet_item_ops = { .release = phonet_attr_release, - .show_attribute = f_phonet_attr_show, }; -static ssize_t f_phonet_ifname_show (struct f_phonet_opts *opts,char *page) +static ssize_t f_phonet_ifname_show (struct config_item *item,char *page) { -return gether_get_ifname (opts->net, page,PAGE_SIZE ); +return gether_get_ifname (to_f_phonet_opts (item)->net, page,PAGE_SIZE ); } -static struct f_phonet_opts_attribute f_phonet_ifname = -__CONFIGFS_ATTR_RO (ifname, f_phonet_ifname_show); +CONFIGFS_ATTR_RO (f_phonet_, ifname);static struct configfs_attribute *phonet_attrs[] = { - &f_phonet_ifname.attr, + &f_phonet_attr_ifname,NULL , };
Signature · 1 line
1.9.1
Re: [PATCH 15/23] usb-gadget/f_phonet: use per-attribute show and store methods
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 55 lines
--- drivers/usb/gadget/function/f_phonet.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-)drivers/usb/gadget/function/f_phonet.c +4
-21@@ -589,21 +589,6 @@ static inline struct f_phonet_opts *to_f_phonet_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_phonet_opts); -static ssize_t f_phonet_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -struct f_phonet_opts *opts =to_f_phonet_opts (item); -struct f_phonet_opts_attribute *f_phonet_opts_attr = - container_of(attr, struct f_phonet_opts_attribute, attr); -ssize_t ret =0 ; - -if (f_phonet_opts_attr->show) - ret = f_phonet_opts_attr->show (opts, page); -return ret; -} -static void phonet_attr_release (struct config_item *item) {struct f_phonet_opts *opts =to_f_phonet_opts (item);@@ -613,19 +598,17 @@ static void phonet_attr_release(struct config_item *item)static struct configfs_item_operations phonet_item_ops = { .release = phonet_attr_release, - .show_attribute = f_phonet_attr_show, }; -static ssize_t f_phonet_ifname_show (struct f_phonet_opts *opts,char *page) +static ssize_t f_phonet_ifname_show (struct config_item *item,char *page) { -return gether_get_ifname (opts->net, page,PAGE_SIZE ); +return gether_get_ifname (to_f_phonet_opts (item)->net, page,PAGE_SIZE ); } -static struct f_phonet_opts_attribute f_phonet_ifname = -__CONFIGFS_ATTR_RO (ifname, f_phonet_ifname_show); +CONFIGFS_ATTR_RO (f_phonet_, ifname);static struct configfs_attribute *phonet_attrs[] = { - &f_phonet_ifname.attr, + &f_phonet_attr_ifname,NULL , };
PATCH 16/23 usb-gadget/f_serial: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/usb/gadget/function/f_serial.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/usb/gadget/function/f_serial.c +4 -22
@@ -266,22 +266,6 @@ static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_serial_opts); -static ssize_t f_serial_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -struct f_serial_opts *opts =to_f_serial_opts (item); -struct f_serial_opts_attribute *f_serial_opts_attr = - container_of(attr, struct f_serial_opts_attribute, attr); -ssize_t ret =0 ; - -if (f_serial_opts_attr->show) - ret = f_serial_opts_attr->show (opts, page); - -return ret; -} -static void serial_attr_release (struct config_item *item) {struct f_serial_opts *opts =to_f_serial_opts (item);
@@ -291,19 +275,17 @@ static void serial_attr_release(struct config_item *item)static struct configfs_item_operations serial_item_ops = { .release = serial_attr_release, - .show_attribute = f_serial_attr_show, }; -static ssize_t f_serial_port_num_show (struct f_serial_opts *opts,char *page) +static ssize_t f_serial_port_num_show (struct config_item *item,char *page) { -return sprintf (page,"%u\n" , opts->port_num); +return sprintf (page,"%u\n" ,to_f_serial_opts (item)->port_num); } -static struct f_serial_opts_attribute f_serial_port_num = -__CONFIGFS_ATTR_RO (port_num, f_serial_port_num_show); +CONFIGFS_ATTR_RO (f_serial_, port_num);static struct configfs_attribute *acm_attrs[] = { - &f_serial_port_num.attr, + &f_serial_attr_port_num,NULL , };
Signature · 1 line
1.9.1
Re: [PATCH 16/23] usb-gadget/f_serial: use per-attribute show and store methods
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 56 lines
--- drivers/usb/gadget/function/f_serial.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)drivers/usb/gadget/function/f_serial.c +4
-22@@ -266,22 +266,6 @@ static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item) func_inst.group); } -CONFIGFS_ATTR_STRUCT (f_serial_opts); -static ssize_t f_serial_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -struct f_serial_opts *opts =to_f_serial_opts (item); -struct f_serial_opts_attribute *f_serial_opts_attr = - container_of(attr, struct f_serial_opts_attribute, attr); -ssize_t ret =0 ; - -if (f_serial_opts_attr->show) - ret = f_serial_opts_attr->show (opts, page); - -return ret; -} -static void serial_attr_release (struct config_item *item) {struct f_serial_opts *opts =to_f_serial_opts (item);@@ -291,19 +275,17 @@ static void serial_attr_release(struct config_item *item)static struct configfs_item_operations serial_item_ops = { .release = serial_attr_release, - .show_attribute = f_serial_attr_show, }; -static ssize_t f_serial_port_num_show (struct f_serial_opts *opts,char *page) +static ssize_t f_serial_port_num_show (struct config_item *item,char *page) { -return sprintf (page,"%u\n" , opts->port_num); +return sprintf (page,"%u\n" ,to_f_serial_opts (item)->port_num); } -static struct f_serial_opts_attribute f_serial_port_num = -__CONFIGFS_ATTR_RO (port_num, f_serial_port_num_show); +CONFIGFS_ATTR_RO (f_serial_, port_num);static struct configfs_attribute *acm_attrs[] = { - &f_serial_port_num.attr, + &f_serial_attr_port_num,NULL , };
PATCH 17/23 dlm: use per-attribute show and store methods
In reply to Christoph Hellwig--- fs/dlm/config.c | 288 +++++++++++++++----------------------------------------- 1 file changed, 74 insertions(+), 214 deletions(-)
fs/dlm/config.c +74 -214
@@ -61,35 +61,8 @@ static struct config_item *make_node(struct config_group *, const char *);static void drop_node (struct config_group *,struct config_item *);static void release_node (struct config_item *); -static ssize_t show_cluster (struct config_item *i,struct configfs_attribute *a, -char *buf); -static ssize_t store_cluster (struct config_item *i, -struct configfs_attribute *a, -const char *buf,size_t len); -static ssize_t show_comm (struct config_item *i,struct configfs_attribute *a, -char *buf); -static ssize_t store_comm (struct config_item *i,struct configfs_attribute *a, -const char *buf,size_t len); -static ssize_t show_node (struct config_item *i,struct configfs_attribute *a, -char *buf); -static ssize_t store_node (struct config_item *i,struct configfs_attribute *a, -const char *buf,size_t len); - -static ssize_t comm_nodeid_read (struct dlm_comm *cm,char *buf); -static ssize_t comm_nodeid_write (struct dlm_comm *cm,const char *buf, -size_t len); -static ssize_t comm_local_read (struct dlm_comm *cm,char *buf); -static ssize_t comm_local_write (struct dlm_comm *cm,const char *buf, -size_t len); -static ssize_t comm_addr_write (struct dlm_comm *cm,const char *buf, -size_t len); -static ssize_t comm_addr_list_read (struct dlm_comm *cm,char *buf); -static ssize_t node_nodeid_read (struct dlm_node *nd,char *buf); -static ssize_t node_nodeid_write (struct dlm_node *nd,const char *buf, -size_t len); -static ssize_t node_weight_read (struct dlm_node *nd,char *buf); -static ssize_t node_weight_write (struct dlm_node *nd,const char *buf, -size_t len); +static struct configfs_attribute *comm_attrs[]; +static struct configfs_attribute *node_attrs[];struct dlm_cluster {struct config_group group;
@@ -108,6 +81,12 @@ struct dlm_cluster {char cl_cluster_name[DLM_LOCKSPACE_LEN ]; }; +static struct dlm_cluster *config_item_to_cluster (struct config_item *i) +{ + return i ? container_of(to_config_group(i), struct dlm_cluster, group) : +NULL ; +} +enum {CLUSTER_ATTR_TCP_PORT =0 ,CLUSTER_ATTR_BUFFER_SIZE ,
@@ -124,33 +103,24 @@ enum { CLUSTER_ATTR_CLUSTER_NAME, }; -struct cluster_attribute { -struct configfs_attribute attr; -ssize_t (*show)(struct dlm_cluster *,char *); -ssize_t (*store)(struct dlm_cluster *,const char *,size_t ); -}; - -static ssize_t cluster_cluster_name_read (struct dlm_cluster *cl,char *buf) +static ssize_t cluster_cluster_name_show (struct config_item *item,char *buf) { +struct dlm_cluster *cl =config_item_to_cluster (item);return sprintf (buf,"%s\n" , cl->cl_cluster_name); } -static ssize_t cluster_cluster_name_write (struct dlm_cluster *cl, +static ssize_t cluster_cluster_name_store (struct config_item *item,const char *buf,size_t len) { +struct dlm_cluster *cl =config_item_to_cluster (item); +strlcpy (dlm_config.ci_cluster_name, buf,sizeof (dlm_config.ci_cluster_name));strlcpy (cl->cl_cluster_name, buf,sizeof (cl->cl_cluster_name));return len; } -static struct cluster_attribute cluster_attr_cluster_name = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="cluster_name" , - .ca_mode =S_IRUGO |S_IWUSR }, - .show = cluster_cluster_name_read, - .store = cluster_cluster_name_write, -}; +CONFIGFS_ATTR (cluster_, cluster_name); static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field, int *info_field, int check_zero,
@@ -175,17 +145,19 @@ static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field, }#define CLUSTER_ATTR (name, check_zero) \ -static ssize_t name##_write(struct dlm_cluster *cl, const char *buf, size_t len) \ +static ssize_t cluster_##name##_store(struct config_item *item, \ + const char *buf, size_t len) \ { \ + struct dlm_cluster *cl = config_item_to_cluster(item); \ return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \ check_zero, buf, len); \ } \ -static ssize_t name##_read(struct dlm_cluster *cl, char *buf) \ +static ssize_t cluster_##name##_show(struct config_item *item, char *buf) \ { \ + struct dlm_cluster *cl = config_item_to_cluster(item); \ return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \ } \ -static struct cluster_attribute cluster_attr_##name = \ -__CONFIGFS_ATTR(name, 0644, name##_read, name##_write) +CONFIGFS_ATTR(cluster_, name);CLUSTER_ATTR (tcp_port,1 );CLUSTER_ATTR (buffer_size,1 );
@@ -201,19 +173,19 @@ CLUSTER_ATTR(new_rsb_count, 0);CLUSTER_ATTR (recover_callbacks,0 );static struct configfs_attribute *cluster_attrs[] = { - [CLUSTER_ATTR_TCP_PORT ] = &cluster_attr_tcp_port.attr, - [CLUSTER_ATTR_BUFFER_SIZE ] = &cluster_attr_buffer_size.attr, - [CLUSTER_ATTR_RSBTBL_SIZE ] = &cluster_attr_rsbtbl_size.attr, - [CLUSTER_ATTR_RECOVER_TIMER ] = &cluster_attr_recover_timer.attr, - [CLUSTER_ATTR_TOSS_SECS ] = &cluster_attr_toss_secs.attr, - [CLUSTER_ATTR_SCAN_SECS ] = &cluster_attr_scan_secs.attr, - [CLUSTER_ATTR_LOG_DEBUG ] = &cluster_attr_log_debug.attr, - [CLUSTER_ATTR_PROTOCOL ] = &cluster_attr_protocol.attr, - [CLUSTER_ATTR_TIMEWARN_CS ] = &cluster_attr_timewarn_cs.attr, - [CLUSTER_ATTR_WAITWARN_US ] = &cluster_attr_waitwarn_us.attr, - [CLUSTER_ATTR_NEW_RSB_COUNT ] = &cluster_attr_new_rsb_count.attr, - [CLUSTER_ATTR_RECOVER_CALLBACKS ] = &cluster_attr_recover_callbacks.attr, - [CLUSTER_ATTR_CLUSTER_NAME ] = &cluster_attr_cluster_name.attr, + [CLUSTER_ATTR_TCP_PORT ] = &cluster_attr_tcp_port, + [CLUSTER_ATTR_BUFFER_SIZE ] = &cluster_attr_buffer_size, + [CLUSTER_ATTR_RSBTBL_SIZE ] = &cluster_attr_rsbtbl_size, + [CLUSTER_ATTR_RECOVER_TIMER ] = &cluster_attr_recover_timer, + [CLUSTER_ATTR_TOSS_SECS ] = &cluster_attr_toss_secs, + [CLUSTER_ATTR_SCAN_SECS ] = &cluster_attr_scan_secs, + [CLUSTER_ATTR_LOG_DEBUG ] = &cluster_attr_log_debug, + [CLUSTER_ATTR_PROTOCOL ] = &cluster_attr_protocol, + [CLUSTER_ATTR_TIMEWARN_CS ] = &cluster_attr_timewarn_cs, + [CLUSTER_ATTR_WAITWARN_US ] = &cluster_attr_waitwarn_us, + [CLUSTER_ATTR_NEW_RSB_COUNT ] = &cluster_attr_new_rsb_count, + [CLUSTER_ATTR_RECOVER_CALLBACKS ] = &cluster_attr_recover_callbacks, + [CLUSTER_ATTR_CLUSTER_NAME ] = &cluster_attr_cluster_name,NULL , };
@@ -224,83 +196,11 @@ enum { COMM_ATTR_ADDR_LIST, }; -struct comm_attribute { -struct configfs_attribute attr; -ssize_t (*show)(struct dlm_comm *,char *); -ssize_t (*store)(struct dlm_comm *,const char *,size_t ); -}; - -static struct comm_attribute comm_attr_nodeid = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="nodeid" , - .ca_mode =S_IRUGO |S_IWUSR }, - .show = comm_nodeid_read, - .store = comm_nodeid_write, -}; - -static struct comm_attribute comm_attr_local = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="local" , - .ca_mode =S_IRUGO |S_IWUSR }, - .show = comm_local_read, - .store = comm_local_write, -}; - -static struct comm_attribute comm_attr_addr = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="addr" , - .ca_mode =S_IWUSR }, - .store = comm_addr_write, -}; - -static struct comm_attribute comm_attr_addr_list = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="addr_list" , - .ca_mode =S_IRUGO }, - .show = comm_addr_list_read, -}; - -static struct configfs_attribute *comm_attrs[] = { - [COMM_ATTR_NODEID ] = &comm_attr_nodeid.attr, - [COMM_ATTR_LOCAL ] = &comm_attr_local.attr, - [COMM_ATTR_ADDR ] = &comm_attr_addr.attr, - [COMM_ATTR_ADDR_LIST ] = &comm_attr_addr_list.attr, -NULL , -}; -enum {NODE_ATTR_NODEID =0 ,NODE_ATTR_WEIGHT , }; -struct node_attribute { -struct configfs_attribute attr; -ssize_t (*show)(struct dlm_node *,char *); -ssize_t (*store)(struct dlm_node *,const char *,size_t ); -}; - -static struct node_attribute node_attr_nodeid = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="nodeid" , - .ca_mode =S_IRUGO |S_IWUSR }, - .show = node_nodeid_read, - .store = node_nodeid_write, -}; - -static struct node_attribute node_attr_weight = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="weight" , - .ca_mode =S_IRUGO |S_IWUSR }, - .show = node_weight_read, - .store = node_weight_write, -}; - -static struct configfs_attribute *node_attrs[] = { - [NODE_ATTR_NODEID ] = &node_attr_nodeid.attr, - [NODE_ATTR_WEIGHT ] = &node_attr_weight.attr, -NULL , -}; -struct dlm_clusters {struct configfs_subsystem subsys; };
@@ -349,8 +249,6 @@ static struct configfs_group_operations clusters_ops = {static struct configfs_item_operations cluster_ops = { .release = release_cluster, - .show_attribute = show_cluster, - .store_attribute = store_cluster, };static struct configfs_group_operations spaces_ops = {
@@ -369,8 +267,6 @@ static struct configfs_group_operations comms_ops = {static struct configfs_item_operations comm_ops = { .release = release_comm, - .show_attribute = show_comm, - .store_attribute = store_comm, };static struct configfs_group_operations nodes_ops = {
@@ -380,8 +276,6 @@ static struct configfs_group_operations nodes_ops = {static struct configfs_item_operations node_ops = { .release = release_node, - .show_attribute = show_node, - .store_attribute = store_node, };static struct config_item_type clusters_type = {
@@ -427,12 +321,6 @@ static struct config_item_type node_type = { .ct_owner = THIS_MODULE, }; -static struct dlm_cluster *config_item_to_cluster (struct config_item *i) -{ - return i ? container_of(to_config_group(i), struct dlm_cluster, group) : -NULL ; -} -static struct dlm_space *config_item_to_space (struct config_item *i) { return i ? container_of(to_config_group(i), struct dlm_space, group) :
@@ -687,66 +575,30 @@ void dlm_config_exit(void)* Functions for user space to read/write attributes */ -static ssize_t show_cluster (struct config_item *i,struct configfs_attribute *a, -char *buf) -{ -struct dlm_cluster *cl =config_item_to_cluster (i); -struct cluster_attribute *cla = - container_of(a, struct cluster_attribute, attr); -return cla->show ? cla->show (cl, buf) :0 ; -} - -static ssize_t store_cluster (struct config_item *i, -struct configfs_attribute *a, -const char *buf,size_t len) +static ssize_t comm_nodeid_show (struct config_item *item,char *buf) { -struct dlm_cluster *cl =config_item_to_cluster (i); -struct cluster_attribute *cla = - container_of(a, struct cluster_attribute, attr); -return cla->store ? cla->store (cl, buf, len) : -EINVAL ; -} - -static ssize_t show_comm (struct config_item *i,struct configfs_attribute *a, -char *buf) -{ -struct dlm_comm *cm =config_item_to_comm (i); -struct comm_attribute *cma = - container_of(a, struct comm_attribute, attr); -return cma->show ? cma->show (cm, buf) :0 ; -} - -static ssize_t store_comm (struct config_item *i,struct configfs_attribute *a, -const char *buf,size_t len) -{ -struct dlm_comm *cm =config_item_to_comm (i); -struct comm_attribute *cma = - container_of(a, struct comm_attribute, attr); -return cma->store ? cma->store (cm, buf, len) : -EINVAL ; +return sprintf (buf,"%d\n" ,config_item_to_comm (item)->nodeid); } -static ssize_t comm_nodeid_read (struct dlm_comm *cm,char *buf) -{ -return sprintf (buf,"%d\n" , cm->nodeid); -} - -static ssize_t comm_nodeid_write (struct dlm_comm *cm,const char *buf, +static ssize_t comm_nodeid_store (struct config_item *item,const char *buf,size_t len) { -int rc =kstrtoint (buf,0 , &cm->nodeid); +int rc =kstrtoint (buf,0 , &config_item_to_comm (item)->nodeid);if (rc)return rc;return len; } -static ssize_t comm_local_read (struct dlm_comm *cm,char *buf) +static ssize_t comm_local_show (struct config_item *item,char *buf) { -return sprintf (buf,"%d\n" , cm->local); +return sprintf (buf,"%d\n" ,config_item_to_comm (item)->local); } -static ssize_t comm_local_write (struct dlm_comm *cm,const char *buf, +static ssize_t comm_local_store (struct config_item *item,const char *buf,size_t len) { +struct dlm_comm *cm =config_item_to_comm (item);int rc =kstrtoint (buf,0 , &cm->local);if (rc)
@@ -756,8 +608,10 @@ static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,return len; } -static ssize_t comm_addr_write (struct dlm_comm *cm,const char *buf,size_t len) +static ssize_t comm_addr_store (struct config_item *item,const char *buf, +size_t len) { +struct dlm_comm *cm =config_item_to_comm (item);struct sockaddr_storage *addr;int rv;
@@ -783,8 +637,9 @@ static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len)return len; } -static ssize_t comm_addr_list_read (struct dlm_comm *cm,char *buf) +static ssize_t comm_addr_list_show (struct config_item *item,char *buf) { +struct dlm_comm *cm =config_item_to_comm (item);ssize_t s;ssize_t allowance;int i;
@@ -827,32 +682,28 @@ static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf)return 4096 - allowance; } -static ssize_t show_node (struct config_item *i,struct configfs_attribute *a, -char *buf) -{ -struct dlm_node *nd =config_item_to_node (i); -struct node_attribute *nda = - container_of(a, struct node_attribute, attr); -return nda->show ? nda->show (nd, buf) :0 ; -} +CONFIGFS_ATTR (comm_, nodeid); +CONFIGFS_ATTR (comm_, local); +CONFIGFS_ATTR_WO (comm_, addr); +CONFIGFS_ATTR_RO (comm_, addr_list); -static ssize_t store_node (struct config_item *i,struct configfs_attribute *a, -const char *buf,size_t len) -{ -struct dlm_node *nd =config_item_to_node (i); -struct node_attribute *nda = - container_of(a, struct node_attribute, attr); -return nda->store ? nda->store (nd, buf, len) : -EINVAL ; -} +static struct configfs_attribute *comm_attrs[] = { + [COMM_ATTR_NODEID ] = &comm_attr_nodeid, + [COMM_ATTR_LOCAL ] = &comm_attr_local, + [COMM_ATTR_ADDR ] = &comm_attr_addr, + [COMM_ATTR_ADDR_LIST ] = &comm_attr_addr_list, +NULL , +}; -static ssize_t node_nodeid_read (struct dlm_node *nd,char *buf) +static ssize_t node_nodeid_show (struct config_item *item,char *buf) { -return sprintf (buf,"%d\n" , nd->nodeid); +return sprintf (buf,"%d\n" ,config_item_to_node (item)->nodeid); } -static ssize_t node_nodeid_write (struct dlm_node *nd,const char *buf, +static ssize_t node_nodeid_store (struct config_item *item,const char *buf,size_t len) { +struct dlm_node *nd =config_item_to_node (item);uint32_t seq =0 ;int rc =kstrtoint (buf,0 , &nd->nodeid);
@@ -863,21 +714,30 @@ static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,return len; } -static ssize_t node_weight_read (struct dlm_node *nd,char *buf) +static ssize_t node_weight_show (struct config_item *item,char *buf) { -return sprintf (buf,"%d\n" , nd->weight); +return sprintf (buf,"%d\n" ,config_item_to_node (item)->weight); } -static ssize_t node_weight_write (struct dlm_node *nd,const char *buf, +static ssize_t node_weight_store (struct config_item *item,const char *buf,size_t len) { -int rc =kstrtoint (buf,0 , &nd->weight); +int rc =kstrtoint (buf,0 , &config_item_to_node (item)->weight);if (rc)return rc;return len; } +CONFIGFS_ATTR (node_, nodeid); +CONFIGFS_ATTR (node_, weight); + +static struct configfs_attribute *node_attrs[] = { + [NODE_ATTR_NODEID ] = &node_attr_nodeid, + [NODE_ATTR_WEIGHT ] = &node_attr_weight, +NULL , +}; +/* * Functions for the dlm to get the info that's been configured */
Signature · 1 line
1.9.1
David Teigland
maintainerRe: [PATCH 17/23] dlm: use per-attribute show and store methods
Quoted 4 lines · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>--- fs/dlm/config.c | 288 +++++++++++++++----------------------------------------- 1 file changed, 74 insertions(+), 214 deletions(-)
Looks good to me.
Dave
PATCH 18/23 spear13xx_pcie_gadget: use per-attribute show and store methods
In reply to Christoph Hellwig--- drivers/misc/spear13xx_pcie_gadget.c | 216 ++++++++++++----------------------- 1 file changed, 71 insertions(+), 145 deletions(-)
drivers/misc/spear13xx_pcie_gadget.c +71 -145
@@ -220,11 +220,17 @@ static irqreturn_t spear_pcie_gadget_irq(int irq, void *dev_id)/* * configfs interfaces show/store functions */ -static ssize_t pcie_gadget_show_link ( -struct spear_pcie_gadget_config *config, -char *buf) + +static struct pcie_gadget_target *to_target (struct config_item *item) { -struct pcie_app_reg __iomem *app_reg = config->va_app_base; +return item ? +container_of (to_configfs_subsystem (to_config_group (item)), + struct pcie_gadget_target, subsys) : NULL; +} + +static ssize_t pcie_gadget_link_show (struct config_item *item,char *buf) +{ +struct pcie_app_reg __iomem *app_reg =to_target (item)->va_app_base;if (readl (&app_reg->app_status_1) & ((u32 )1 <<XMLH_LINK_UP_ID ))return sprintf (buf,"UP" );
@@ -232,11 +238,10 @@ static ssize_t pcie_gadget_show_link(return sprintf (buf,"DOWN" ); } -static ssize_t pcie_gadget_store_link ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_link_store (struct config_item *item,const char *buf,size_t count) { -struct pcie_app_reg __iomem *app_reg = config->va_app_base; +struct pcie_app_reg __iomem *app_reg =to_target (item)->va_app_base;if (sysfs_streq (buf,"UP" )) writel(readl(&app_reg->app_ctrl_0) | (1 << APP_LTSSM_ENABLE_ID),
@@ -250,17 +255,15 @@ static ssize_t pcie_gadget_store_link(return count; } -static ssize_t pcie_gadget_show_int_type ( -struct spear_pcie_gadget_config *config, -char *buf) +static ssize_t pcie_gadget_int_type_show (struct config_item *item,char *buf) { -return sprintf (buf,"%s" , config->int_type); +return sprintf (buf,"%s" ,to_target (item)->int_type); } -static ssize_t pcie_gadget_store_int_type ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_int_type_store (struct config_item *item,const char *buf,size_t count) { + struct spear_pcie_gadget_config *config = to_target(item)u32 cap, vec, flags;ulong vector;
@@ -288,11 +291,10 @@ static ssize_t pcie_gadget_store_int_type(return count; } -static ssize_t pcie_gadget_show_no_of_msi ( -struct spear_pcie_gadget_config *config, -char *buf) +static ssize_t pcie_gadget_no_of_msi_show (struct config_item *item,char *buf) { -struct pcie_app_reg __iomem *app_reg = config->va_app_base; + struct spear_pcie_gadget_config *config = to_target(item) +struct pcie_app_reg __iomem *app_reg =to_target (item)->va_app_base;u32 cap, vec, flags;ulong vector;
@@ -313,13 +315,12 @@ static ssize_t pcie_gadget_show_no_of_msi(return sprintf (buf,"%lu" , vector); } -static ssize_t pcie_gadget_store_no_of_msi ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_no_of_msi_store (struct config_item *item,const char *buf,size_t count) {int ret; - ret =kstrtoul (buf,0 , &config->requested_msi); + ret =kstrtoul (buf,0 , &to_target (item)->requested_msi);if (ret)return ret;
@@ -329,11 +330,10 @@ static ssize_t pcie_gadget_store_no_of_msi(return count; } -static ssize_t pcie_gadget_store_inta ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_inta_store (struct config_item *item,const char *buf,size_t count) { -struct pcie_app_reg __iomem *app_reg = config->va_app_base; +struct pcie_app_reg __iomem *app_reg =to_target (item)->va_app_base;ulong en;int ret;
@@ -351,10 +351,10 @@ static ssize_t pcie_gadget_store_inta(return count; } -static ssize_t pcie_gadget_store_send_msi ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_send_msi_store (struct config_item *item,const char *buf,size_t count) { + struct spear_pcie_gadget_config *config = to_target(item)struct pcie_app_reg __iomem *app_reg = config->va_app_base;ulong vector;u32 ven_msi;
@@ -388,19 +388,16 @@ static ssize_t pcie_gadget_store_send_msi(return count; } -static ssize_t pcie_gadget_show_vendor_id ( -struct spear_pcie_gadget_config *config, -char *buf) +static ssize_t pcie_gadget_vendor_id_show (struct config_item *item,char *buf) {u32 id; -spear_dbi_read_reg (config,PCI_VENDOR_ID ,2 , &id); +spear_dbi_read_reg (to_target (item),PCI_VENDOR_ID ,2 , &id);return sprintf (buf,"%x" , id); } -static ssize_t pcie_gadget_store_vendor_id ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_vendor_id_store (struct config_item *item,const char *buf,size_t count) {ulong id;
@@ -410,24 +407,21 @@ static ssize_t pcie_gadget_store_vendor_id(if (ret)return ret; -spear_dbi_write_reg (config,PCI_VENDOR_ID ,2 , id); +spear_dbi_write_reg (to_target (item),PCI_VENDOR_ID ,2 , id);return count; } -static ssize_t pcie_gadget_show_device_id ( -struct spear_pcie_gadget_config *config, -char *buf) +static ssize_t pcie_gadget_device_id_show (struct config_item *item,char *buf) {u32 id; -spear_dbi_read_reg (config,PCI_DEVICE_ID ,2 , &id); +spear_dbi_read_reg (to_target (item),PCI_DEVICE_ID ,2 , &id);return sprintf (buf,"%x" , id); } -static ssize_t pcie_gadget_store_device_id ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_device_id_store (struct config_item *item,const char *buf,size_t count) {ulong id;
@@ -437,22 +431,20 @@ static ssize_t pcie_gadget_store_device_id(if (ret)return ret; -spear_dbi_write_reg (config,PCI_DEVICE_ID ,2 , id); +spear_dbi_write_reg (to_target (item),PCI_DEVICE_ID ,2 , id);return count; } -static ssize_t pcie_gadget_show_bar0_size ( -struct spear_pcie_gadget_config *config, -char *buf) +static ssize_t pcie_gadget_bar0_size_show (struct config_item *item,char *buf) { -return sprintf (buf,"%lx" , config->bar0_size); +return sprintf (buf,"%lx" ,to_target (item)->bar0_size); } -static ssize_t pcie_gadget_store_bar0_size ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_bar0_size_store (struct config_item *item,const char *buf,size_t count) { + struct spear_pcie_gadget_config *config = to_target(item)ulong size;u32 pos, pos1;u32 no_of_bit =0 ;
@@ -489,21 +481,20 @@ static ssize_t pcie_gadget_store_bar0_size(return count; } -static ssize_t pcie_gadget_show_bar0_address ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_bar0_address_show (struct config_item *item,char *buf) { -struct pcie_app_reg __iomem *app_reg = config->va_app_base; +struct pcie_app_reg __iomem *app_reg =to_target (item)->va_app_base;u32 address =readl (&app_reg->pim0_mem_addr_start);return sprintf (buf,"%x" , address); } -static ssize_t pcie_gadget_store_bar0_address ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_bar0_address_store (struct config_item *item,const char *buf,size_t count) { + struct spear_pcie_gadget_config *config = to_target(item)struct pcie_app_reg __iomem *app_reg = config->va_app_base;ulong address;int ret;
@@ -524,15 +515,13 @@ static ssize_t pcie_gadget_store_bar0_address(return count; } -static ssize_t pcie_gadget_show_bar0_rw_offset ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_bar0_rw_offset_show (struct config_item *item,char *buf) { -return sprintf (buf,"%lx" , config->bar0_rw_offset); +return sprintf (buf,"%lx" ,to_target (item)->bar0_rw_offset); } -static ssize_t pcie_gadget_store_bar0_rw_offset ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_bar0_rw_offset_store (struct config_item *item,const char *buf,size_t count) {ulong offset;
@@ -545,15 +534,14 @@ static ssize_t pcie_gadget_store_bar0_rw_offset(if (offset %4 )return -EINVAL ; - config->bar0_rw_offset = offset; +to_target (item)->bar0_rw_offset = offset;return count; } -static ssize_t pcie_gadget_show_bar0_data ( -struct spear_pcie_gadget_config *config, -char *buf) +static ssize_t pcie_gadget_bar0_data_show (struct config_item *item,char *buf) { + struct spear_pcie_gadget_config *config = to_target(item)ulong data;if (!config->va_bar0_address)
@@ -564,10 +552,10 @@ static ssize_t pcie_gadget_show_bar0_data(return sprintf (buf,"%lx" , data); } -static ssize_t pcie_gadget_store_bar0_data ( -struct spear_pcie_gadget_config *config, +static ssize_t pcie_gadget_bar0_data_store (struct config_item *item,const char *buf,size_t count) { + struct spear_pcie_gadget_config *config = to_target(item)ulong data;int ret;
@@ -583,97 +571,35 @@ static ssize_t pcie_gadget_store_bar0_data(return count; } -/* -* Attribute definitions. -*/ - -#define PCIE_GADGET_TARGET_ATTR_RO (_name) \ -static struct pcie_gadget_target_attr pcie_gadget_target_##_name = \ - __CONFIGFS_ATTR(_name, S_IRUGO, pcie_gadget_show_##_name, NULL) - -#define PCIE_GADGET_TARGET_ATTR_WO (_name) \ -static struct pcie_gadget_target_attr pcie_gadget_target_##_name = \ - __CONFIGFS_ATTR(_name, S_IWUSR, NULL, pcie_gadget_store_##_name) - -#define PCIE_GADGET_TARGET_ATTR_RW (_name) \ -static struct pcie_gadget_target_attr pcie_gadget_target_##_name = \ - __CONFIGFS_ATTR(_name, S_IRUGO | S_IWUSR, pcie_gadget_show_##_name, \ - pcie_gadget_store_##_name) -PCIE_GADGET_TARGET_ATTR_RW (link); -PCIE_GADGET_TARGET_ATTR_RW (int_type); -PCIE_GADGET_TARGET_ATTR_RW (no_of_msi); -PCIE_GADGET_TARGET_ATTR_WO (inta); -PCIE_GADGET_TARGET_ATTR_WO (send_msi); -PCIE_GADGET_TARGET_ATTR_RW (vendor_id); -PCIE_GADGET_TARGET_ATTR_RW (device_id); -PCIE_GADGET_TARGET_ATTR_RW (bar0_size); -PCIE_GADGET_TARGET_ATTR_RW (bar0_address); -PCIE_GADGET_TARGET_ATTR_RW (bar0_rw_offset); -PCIE_GADGET_TARGET_ATTR_RW (bar0_data); +CONFIGFS_ATTR (pcie_gadget_, link); +CONFIGFS_ATTR (pcie_gadget_, int_type); +CONFIGFS_ATTR (pcie_gadget_, no_of_msi); +CONFIGFS_ATTR_WO (pcie_gadget_, inta); +CONFIGFS_ATTR_WO (pcie_gadget_, send_msi); +CONFIGFS_ATTR (pcie_gadget_, vendor_id); +CONFIGFS_ATTR (pcie_gadget_, device_id); +CONFIGFS_ATTR (pcie_gadget_, bar0_size); +CONFIGFS_ATTR (pcie_gadget_, bar0_address); +CONFIGFS_ATTR (pcie_gadget_, bar0_rw_offset); +CONFIGFS_ATTR (pcie_gadget_, bar0_data);static struct configfs_attribute *pcie_gadget_target_attrs[] = { - &pcie_gadget_target_link.attr, - &pcie_gadget_target_int_type.attr, - &pcie_gadget_target_no_of_msi.attr, - &pcie_gadget_target_inta.attr, - &pcie_gadget_target_send_msi.attr, - &pcie_gadget_target_vendor_id.attr, - &pcie_gadget_target_device_id.attr, - &pcie_gadget_target_bar0_size.attr, - &pcie_gadget_target_bar0_address.attr, - &pcie_gadget_target_bar0_rw_offset.attr, - &pcie_gadget_target_bar0_data.attr, + &pcie_gadget_attr_link, + &pcie_gadget_attr_int_type, + &pcie_gadget_attr_no_of_msi, + &pcie_gadget_attr_inta, + &pcie_gadget_attr_send_msi, + &pcie_gadget_attr_vendor_id, + &pcie_gadget_attr_device_id, + &pcie_gadget_attr_bar0_size, + &pcie_gadget_attr_bar0_address, + &pcie_gadget_attr_bar0_rw_offset, + &pcie_gadget_attr_bar0_data,NULL , }; -static struct pcie_gadget_target *to_target (struct config_item *item) -{ -return item ? -container_of (to_configfs_subsystem (to_config_group (item)), - struct pcie_gadget_target, subsys) : NULL; -} - -/* -* Item operations and type for pcie_gadget_target. -*/ - -static ssize_t pcie_gadget_target_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *buf) -{ -ssize_t ret = -EINVAL ; -struct pcie_gadget_target *target =to_target (item); -struct pcie_gadget_target_attr *t_attr = - container_of(attr, struct pcie_gadget_target_attr, attr); - -if (t_attr->show) - ret = t_attr->show (&target->config, buf); -return ret; -} - -static ssize_t pcie_gadget_target_attr_store (struct config_item *item, -struct configfs_attribute *attr, -const char *buf, -size_t count) -{ -ssize_t ret = -EINVAL ; -struct pcie_gadget_target *target =to_target (item); -struct pcie_gadget_target_attr *t_attr = - container_of(attr, struct pcie_gadget_target_attr, attr); - -if (t_attr->store) - ret = t_attr->store (&target->config, buf, count); -return ret; -} - -static struct configfs_item_operations pcie_gadget_target_item_ops = { - .show_attribute = pcie_gadget_target_attr_show, - .store_attribute = pcie_gadget_target_attr_store, -}; -static struct config_item_type pcie_gadget_target_type = { .ct_attrs = pcie_gadget_target_attrs, - .ct_item_ops = &pcie_gadget_target_item_ops, .ct_owner =THIS_MODULE , };
Signature · 1 line
1.9.1
PATCH 19/23 target: use per-attribute show and store methods
In reply to Christoph HellwigThis also allows to remove the target-specific old configfs macros, and gets rid of the target_core_fabric_configfs.h header which only had one function declaration left that could be moved to a better place.
--- Documentation/target/tcm_mod_builder.py | 17 - drivers/infiniband/ulp/srpt/ib_srpt.c | 78 +- drivers/scsi/qla2xxx/tcm_qla2xxx.c | 153 ++-- drivers/target/iscsi/iscsi_target_configfs.c | 791 ++++++----------- drivers/target/iscsi/iscsi_target_stat.c | 666 ++++++-------- drivers/target/loopback/tcm_loop.c | 60 +- drivers/target/sbp/sbp_target.c | 87 +- drivers/target/target_core_configfs.c | 1209 ++++++++++---------------- drivers/target/target_core_fabric_configfs.c | 275 ++---- drivers/target/target_core_internal.h | 3 + drivers/target/target_core_stat.c | 918 ++++++++----------- drivers/target/tcm_fc/tfc_cmd.c | 1 - drivers/target/tcm_fc/tfc_conf.c | 44 +- drivers/target/tcm_fc/tfc_io.c | 1 - drivers/target/tcm_fc/tfc_sess.c | 1 - drivers/usb/gadget/legacy/tcm_usb_gadget.c | 44 +- drivers/vhost/scsi.c | 41 +- drivers/xen/xen-scsiback.c | 32 +- include/target/configfs_macros.h | 147 ---- include/target/target_core_base.h | 60 ++ include/target/target_core_fabric_configfs.h | 122 --- 21 files changed, 1689 insertions(+), 3061 deletions(-) delete mode 100644 include/target/configfs_macros.h delete mode 100644 include/target/target_core_fabric_configfs.h
Documentation/target/tcm_mod_builder.py +0 -17
@@ -203,8 +203,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name): buf += "#include <scsi/scsi_proto.h>\n\n" buf += "#include <target/target_core_base.h>\n" buf += "#include <target/target_core_fabric.h>\n" - buf += "#include <target/target_core_fabric_configfs.h>\n" - buf += "#include <target/configfs_macros.h>\n\n" buf += "#include \"" + fabric_mod_name + "_base.h\"\n" buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
@@ -283,19 +281,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name): buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n" buf += " kfree(" + fabric_mod_port + ");\n" buf += "}\n\n" - buf += "static ssize_t " + fabric_mod_name + "_wwn_show_attr_version(\n" - buf += " struct target_fabric_configfs *tf,\n" - buf += " char *page)\n" - buf += "{\n" - buf += " return sprintf(page, \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n" - buf += " \"on \"UTS_RELEASE\"\\n\", " + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n" - buf += " utsname()->machine);\n" - buf += "}\n\n" - buf += "TF_WWN_ATTR_RO(" + fabric_mod_name + ", version);\n\n" - buf += "static struct configfs_attribute *" + fabric_mod_name + "_wwn_attrs[] = {\n" - buf += " &" + fabric_mod_name + "_wwn_version.attr,\n" - buf += " NULL,\n" - buf += "};\n\n" buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n" buf += " .module = THIS_MODULE,\n"
@@ -328,8 +313,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name): buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n" buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n" buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n" - buf += "\n" - buf += " .tfc_wwn_attrs = " + fabric_mod_name + "_wwn_attrs,\n" buf += "};\n\n" buf += "static int __init " + fabric_mod_name + "_init(void)\n"
drivers/infiniband/ulp/srpt/ib_srpt.c +34 -44
162 lines not on this page · raw message
drivers/scsi/qla2xxx/tcm_qla2xxx.c +51 -102
264 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_configfs.c +271 -520
1,128 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_stat.c +262 -404
1,027 lines not on this page · raw message
drivers/target/loopback/tcm_loop.c +26 -34
136 lines not on this page · raw message
drivers/target/sbp/sbp_target.c +38 -49
184 lines not on this page · raw message
drivers/target/target_core_configfs.c +441 -768
64 lines not on this page · raw message
drivers/target/target_core_fabric_configfs.c +69 -206
275 lines not on this page · raw message
drivers/target/target_core_stat.c +362 -556
918 lines not on this page · raw message
drivers/target/tcm_fc/tfc_conf.c +18 -26
44 lines not on this page · raw message
drivers/usb/gadget/legacy/tcm_usb_gadget.c +19 -25
44 lines not on this page · raw message
drivers/vhost/scsi.c +19 -22
41 lines not on this page · raw message
include/target/configfs_macros.h deleted +0 -147
147 lines not on this page · raw message
include/target/target_core_base.h +60 -0
60 lines not on this page · raw message
include/target/target_core_fabric_configfs.h deleted +0 -122
122 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.9.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH 19/23] target: use per-attribute show and store methods
Quoted 22 lines · Christoph Hellwig
This also allows to remove the target-specific old configfs macros, and gets rid of the
target_core_fabric_configfs.hheader which only had one function declaration left that could be moved to a better place.Signed-off-by Christoph Hellwig <[email protected]>--- Documentation/target/tcm_mod_builder.py | 17 - drivers/infiniband/ulp/srpt/ib_srpt.c | 78 +- drivers/scsi/qla2xxx/tcm_qla2xxx.c | 153 ++-- drivers/target/iscsi/iscsi_target_configfs.c | 791 ++++++----------- drivers/target/iscsi/iscsi_target_stat.c | 666 ++++++-------- drivers/target/loopback/tcm_loop.c | 60 +- drivers/target/sbp/sbp_target.c | 87 +- drivers/target/target_core_configfs.c | 1209 ++++++++++---------------- drivers/target/target_core_fabric_configfs.c | 275 ++---- drivers/target/target_core_internal.h | 3 + drivers/target/target_core_stat.c | 918 ++++++++----------- drivers/target/tcm_fc/tfc_cmd.c | 1 - drivers/target/tcm_fc/tfc_conf.c | 44 +- drivers/target/tcm_fc/tfc_io.c | 1 - drivers/target/tcm_fc/tfc_sess.c | 1 - drivers/usb/gadget/legacy/tcm_usb_gadget.c | 44 +-
Quoted 9 lines
drivers/vhost/scsi.c | 41 +- drivers/xen/xen-scsiback.c | 32 +- include/target/configfs_macros.h | 147 ---- include/target/target_core_base.h | 60 ++ include/target/target_core_fabric_configfs.h | 122 --- 21 files changed, 1689 insertions(+), 3061 deletions(-) delete mode 100644 include/target/configfs_macros.h delete mode 100644 include/target/target_core_fabric_configfs.h
I'm totally crazy for this patch.
Very nice work to drop this much boilerplate macro-fu in target-core + fabric driver code.
PATCH 22/23 ocfs2/cluster: use per-attribute show and store methods
In reply to Christoph Hellwig--- fs/ocfs2/cluster/heartbeat.c | 205 +++++++---------------------------- fs/ocfs2/cluster/nodemanager.c | 241 ++++++++++------------------------------- 2 files changed, 100 insertions(+), 346 deletions(-)
fs/ocfs2/cluster/heartbeat.c +41 -164
@@ -1473,16 +1473,17 @@ static int o2hb_read_block_input(struct o2hb_region *reg,return 0 ; } -static ssize_t o2hb_region_block_bytes_read (struct o2hb_region *reg, +static ssize_t o2hb_region_block_bytes_show (struct config_item *item,char *page) { -return sprintf (page,"%u\n" , reg->hr_block_bytes); +return sprintf (page,"%u\n" ,to_o2hb_region (item)->hr_block_bytes); } -static ssize_t o2hb_region_block_bytes_write (struct o2hb_region *reg, +static ssize_t o2hb_region_block_bytes_store (struct config_item *item,const char *page,size_t count) { +struct o2hb_region *reg =to_o2hb_region (item);int status;unsigned long block_bytes;unsigned int block_bits;
@@ -1501,16 +1502,17 @@ static ssize_t o2hb_region_block_bytes_write(struct o2hb_region *reg,return count; } -static ssize_t o2hb_region_start_block_read (struct o2hb_region *reg, +static ssize_t o2hb_region_start_block_show (struct config_item *item,char *page) { -return sprintf (page,"%llu\n" , reg->hr_start_block); +return sprintf (page,"%llu\n" ,to_o2hb_region (item)->hr_start_block); } -static ssize_t o2hb_region_start_block_write (struct o2hb_region *reg, +static ssize_t o2hb_region_start_block_store (struct config_item *item,const char *page,size_t count) { +struct o2hb_region *reg =to_o2hb_region (item);unsigned long long tmp;char *p = (char *)page;
@@ -1526,16 +1528,16 @@ static ssize_t o2hb_region_start_block_write(struct o2hb_region *reg,return count; } -static ssize_t o2hb_region_blocks_read (struct o2hb_region *reg, -char *page) +static ssize_t o2hb_region_blocks_show (struct config_item *item,char *page) { -return sprintf (page,"%d\n" , reg->hr_blocks); +return sprintf (page,"%d\n" ,to_o2hb_region (item)->hr_blocks); } -static ssize_t o2hb_region_blocks_write (struct o2hb_region *reg, +static ssize_t o2hb_region_blocks_store (struct config_item *item,const char *page,size_t count) { +struct o2hb_region *reg =to_o2hb_region (item);unsigned long tmp;char *p = (char *)page;
@@ -1554,13 +1556,12 @@ static ssize_t o2hb_region_blocks_write(struct o2hb_region *reg,return count; } -static ssize_t o2hb_region_dev_read (struct o2hb_region *reg, -char *page) +static ssize_t o2hb_region_dev_show (struct config_item *item,char *page) {unsigned int ret =0 ; -if (reg->hr_bdev) - ret =sprintf (page,"%s\n" , reg->hr_dev_name); +if (to_o2hb_region (item)->hr_bdev) + ret =sprintf (page,"%s\n" ,to_o2hb_region (item)->hr_dev_name);return ret; }
@@ -1670,10 +1671,11 @@ out: }/* this is acting as commit; we set up all of hr_bdev and hr_task or nothing */ -static ssize_t o2hb_region_dev_write (struct o2hb_region *reg, +static ssize_t o2hb_region_dev_store (struct config_item *item,const char *page,size_t count) { +struct o2hb_region *reg =to_o2hb_region (item);struct task_struct *hb_task;long fd;int sectsize;
@@ -1828,9 +1830,9 @@ out:return ret; } -static ssize_t o2hb_region_pid_read (struct o2hb_region *reg, -char *page) +static ssize_t o2hb_region_pid_show (struct config_item *item,char *page) { +struct o2hb_region *reg =to_o2hb_region (item);pid_t pid =0 ;spin_lock (&o2hb_live_lock);
@@ -1844,92 +1846,23 @@ static ssize_t o2hb_region_pid_read(struct o2hb_region *reg,return sprintf (page,"%u\n" , pid); } -struct o2hb_region_attribute { -struct configfs_attribute attr; -ssize_t (*show)(struct o2hb_region *,char *); -ssize_t (*store)(struct o2hb_region *,const char *,size_t ); -}; - -static struct o2hb_region_attribute o2hb_region_attr_block_bytes = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="block_bytes" , - .ca_mode =S_IRUGO |S_IWUSR }, - .show = o2hb_region_block_bytes_read, - .store = o2hb_region_block_bytes_write, -}; - -static struct o2hb_region_attribute o2hb_region_attr_start_block = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="start_block" , - .ca_mode =S_IRUGO |S_IWUSR }, - .show = o2hb_region_start_block_read, - .store = o2hb_region_start_block_write, -}; - -static struct o2hb_region_attribute o2hb_region_attr_blocks = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="blocks" , - .ca_mode =S_IRUGO |S_IWUSR }, - .show = o2hb_region_blocks_read, - .store = o2hb_region_blocks_write, -}; - -static struct o2hb_region_attribute o2hb_region_attr_dev = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="dev" , - .ca_mode =S_IRUGO |S_IWUSR }, - .show = o2hb_region_dev_read, - .store = o2hb_region_dev_write, -}; - -static struct o2hb_region_attribute o2hb_region_attr_pid = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="pid" , - .ca_mode =S_IRUGO |S_IRUSR }, - .show = o2hb_region_pid_read, -}; +CONFIGFS_ATTR (o2hb_region_, block_bytes); +CONFIGFS_ATTR (o2hb_region_, start_block); +CONFIGFS_ATTR (o2hb_region_, blocks); +CONFIGFS_ATTR (o2hb_region_, dev); +CONFIGFS_ATTR_RO (o2hb_region_, pid);static struct configfs_attribute *o2hb_region_attrs[] = { - &o2hb_region_attr_block_bytes.attr, - &o2hb_region_attr_start_block.attr, - &o2hb_region_attr_blocks.attr, - &o2hb_region_attr_dev.attr, - &o2hb_region_attr_pid.attr, + &o2hb_region_attr_block_bytes, + &o2hb_region_attr_start_block, + &o2hb_region_attr_blocks, + &o2hb_region_attr_dev, + &o2hb_region_attr_pid,NULL , }; -static ssize_t o2hb_region_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -struct o2hb_region *reg =to_o2hb_region (item); -struct o2hb_region_attribute *o2hb_region_attr = - container_of(attr, struct o2hb_region_attribute, attr); -ssize_t ret =0 ; - -if (o2hb_region_attr->show) - ret = o2hb_region_attr->show (reg, page); -return ret; -} - -static ssize_t o2hb_region_store (struct config_item *item, -struct configfs_attribute *attr, -const char *page,size_t count) -{ -struct o2hb_region *reg =to_o2hb_region (item); -struct o2hb_region_attribute *o2hb_region_attr = - container_of(attr, struct o2hb_region_attribute, attr); -ssize_t ret = -EINVAL ; - -if (o2hb_region_attr->store) - ret = o2hb_region_attr->store (reg, page, count); -return ret; -} -static struct configfs_item_operations o2hb_region_item_ops = { .release = o2hb_region_release, - .show_attribute = o2hb_region_show, - .store_attribute = o2hb_region_store, };static struct config_item_type o2hb_region_type = {
@@ -2124,49 +2057,14 @@ unlock:spin_unlock (&o2hb_live_lock); } -struct o2hb_heartbeat_group_attribute { -struct configfs_attribute attr; -ssize_t (*show)(struct o2hb_heartbeat_group *,char *); -ssize_t (*store)(struct o2hb_heartbeat_group *,const char *,size_t ); -}; - -static ssize_t o2hb_heartbeat_group_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -struct o2hb_heartbeat_group *reg =to_o2hb_heartbeat_group (to_config_group (item)); -struct o2hb_heartbeat_group_attribute *o2hb_heartbeat_group_attr = - container_of(attr, struct o2hb_heartbeat_group_attribute, attr); -ssize_t ret =0 ; - -if (o2hb_heartbeat_group_attr->show) - ret = o2hb_heartbeat_group_attr->show (reg, page); -return ret; -} - -static ssize_t o2hb_heartbeat_group_store (struct config_item *item, -struct configfs_attribute *attr, -const char *page,size_t count) -{ -struct o2hb_heartbeat_group *reg =to_o2hb_heartbeat_group (to_config_group (item)); -struct o2hb_heartbeat_group_attribute *o2hb_heartbeat_group_attr = - container_of(attr, struct o2hb_heartbeat_group_attribute, attr); -ssize_t ret = -EINVAL ; - -if (o2hb_heartbeat_group_attr->store) - ret = o2hb_heartbeat_group_attr->store (reg, page, count); -return ret; -} - -static ssize_t o2hb_heartbeat_group_threshold_show (struct o2hb_heartbeat_group *group, -char *page) +static ssize_t o2hb_heartbeat_group_threshold_show (struct config_item *item, +char *page) {return sprintf (page,"%u\n" , o2hb_dead_threshold); } -static ssize_t o2hb_heartbeat_group_threshold_store (struct o2hb_heartbeat_group *group, -const char *page, -size_t count) +static ssize_t o2hb_heartbeat_group_threshold_store (struct config_item *item, +const char *page,size_t count) {unsigned long tmp;char *p = (char *)page;
@@ -2181,17 +2079,15 @@ static ssize_t o2hb_heartbeat_group_threshold_store(struct o2hb_heartbeat_groupreturn count; } -static -ssize_t o2hb_heartbeat_group_mode_show (struct o2hb_heartbeat_group *group, -char *page) +static ssize_t o2hb_heartbeat_group_mode_show (struct config_item *item, +char *page) {return sprintf (page,"%s\n" , o2hb_heartbeat_mode_desc[o2hb_heartbeat_mode]); } -static -ssize_t o2hb_heartbeat_group_mode_store (struct o2hb_heartbeat_group *group, -const char *page,size_t count) +static ssize_t o2hb_heartbeat_group_mode_store (struct config_item *item, +const char *page,size_t count) {unsigned int i;int ret;
@@ -2216,33 +2112,15 @@ ssize_t o2hb_heartbeat_group_mode_store(struct o2hb_heartbeat_group *group, } -static struct o2hb_heartbeat_group_attribute o2hb_heartbeat_group_attr_threshold = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="dead_threshold" , - .ca_mode =S_IRUGO |S_IWUSR }, - .show = o2hb_heartbeat_group_threshold_show, - .store = o2hb_heartbeat_group_threshold_store, -}; - -static struct o2hb_heartbeat_group_attribute o2hb_heartbeat_group_attr_mode = { - .attr = { .ca_owner =THIS_MODULE , - .ca_name ="mode" , - .ca_mode =S_IRUGO |S_IWUSR }, - .show = o2hb_heartbeat_group_mode_show, - .store = o2hb_heartbeat_group_mode_store, -}; +CONFIGFS_ATTR (o2hb_heartbeat_group_, threshold); +CONFIGFS_ATTR (o2hb_heartbeat_group_, mode);static struct configfs_attribute *o2hb_heartbeat_group_attrs[] = { - &o2hb_heartbeat_group_attr_threshold.attr, - &o2hb_heartbeat_group_attr_mode.attr, + &o2hb_heartbeat_group_attr_threshold, + &o2hb_heartbeat_group_attr_mode,NULL , }; -static struct configfs_item_operations o2hb_heartbeat_group_item_ops = { - .show_attribute = o2hb_heartbeat_group_show, - .store_attribute = o2hb_heartbeat_group_store, -}; -static struct configfs_group_operations o2hb_heartbeat_group_group_ops = { .make_item = o2hb_heartbeat_group_make_item, .drop_item = o2hb_heartbeat_group_drop_item,
@@ -2250,7 +2128,6 @@ static struct configfs_group_operations o2hb_heartbeat_group_group_ops = {static struct config_item_type o2hb_heartbeat_group_type = { .ct_group_ops = &o2hb_heartbeat_group_group_ops, - .ct_item_ops = &o2hb_heartbeat_group_item_ops, .ct_attrs = o2hb_heartbeat_group_attrs, .ct_owner =THIS_MODULE , };
fs/ocfs2/cluster/nodemanager.c +59 -182
373 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 23/23 configfs: remove old API
In reply to Christoph HellwigRemove the old show_attribute and store_attribute methods and update the documentation. Also replace the two C samples with a single new one in the proper samples directory where people expect to find it.
--- Documentation/filesystems/Makefile | 2 - Documentation/filesystems/configfs/Makefile | 3 - Documentation/filesystems/configfs/configfs.txt | 43 +- .../configfs/configfs_example_explicit.c | 483 --------------------- .../filesystems/configfs/configfs_example_macros.c | 446 ------------------- fs/configfs/file.c | 15 +- include/linux/configfs.h | 82 ---- samples/Makefile | 3 +- samples/configfs/Makefile | 2 + samples/configfs/configfs_sample.c | 404 +++++++++++++++++ 10 files changed, 427 insertions(+), 1056 deletions(-) delete mode 100644 Documentation/filesystems/configfs/Makefile delete mode 100644 Documentation/filesystems/configfs/configfs_example_explicit.c delete mode 100644 Documentation/filesystems/configfs/configfs_example_macros.c create mode 100644 samples/configfs/Makefile create mode 100644 samples/configfs/configfs_sample.c
Documentation/filesystems/Makefile +0 -2
@@ -1,5 +1,3 @@ -subdir-y := configfs - # List of programs to build hostprogs-y := dnotify_test
Documentation/filesystems/configfs/Makefile deleted +0 -3
@@ -1,3 +0,0 @@ -ifneq ($(CONFIG_CONFIGFS_FS),) -obj-m += configfs_example_explicit.o configfs_example_macros.o -endif
Documentation/filesystems/configfs/configfs.txt +16 -27
73 lines not on this page · raw message
Documentation/filesystems/configfs/configfs_example_explicit.c deleted +0 -483
483 lines not on this page · raw message
Documentation/filesystems/configfs/configfs_example_macros.c deleted +0 -446
446 lines not on this page · raw message
fs/configfs/file.c +3 -12
@@ -65,7 +65,6 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * buf {struct configfs_attribute * attr =to_attr (dentry);struct config_item * item =to_item (dentry->d_parent); -struct configfs_item_operations * ops = buffer->ops;int ret =0 ;ssize_t count;
@@ -74,10 +73,7 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * bufif (!buffer->page)return -ENOMEM ; -if (ops->show_attribute) - count = ops->show_attribute (item, attr, buffer->page); -else - count = attr->show (item, buffer->page); + count = attr->show (item, buffer->page); buffer->needs_read_fill =0 ;BUG_ON (count > (ssize_t )SIMPLE_ATTR_SIZE );
@@ -175,10 +171,7 @@ flush_write_buffer(struct dentry * dentry, struct configfs_buffer * buffer, size {struct configfs_attribute * attr =to_attr (dentry);struct config_item * item =to_item (dentry->d_parent); -struct configfs_item_operations * ops = buffer->ops; -if (ops->store_attribute) -return ops->store_attribute (item, attr, buffer->page, count);return attr->store (item, buffer->page, count); }
@@ -243,8 +236,7 @@ static int check_perm(struct inode * inode, struct file * file)* and we must have a store method. */ if (file->f_mode &FMODE_WRITE ) { -if (!(inode->i_mode &S_IWUGO ) || - (!ops->store_attribute && !attr->store)) +if (!(inode->i_mode &S_IWUGO ) || !attr->store) goto Eaccess; }
@@ -254,8 +246,7 @@ static int check_perm(struct inode * inode, struct file * file)* must be a show method for it. */ if (file->f_mode &FMODE_READ ) { -if (!(inode->i_mode &S_IRUGO ) || - (!ops->show_attribute && !attr->show)) +if (!(inode->i_mode &S_IRUGO ) || !attr->show) goto Eaccess; }
include/linux/configfs.h +0 -82
94 lines not on this page · raw message
samples/Makefile +2 -1
@@ -1,4 +1,5 @@ # Makefile for Linux samples code obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \ - hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ + hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ \ + configfs/
samples/configfs/Makefile new file +2 -0
@@ -0,0 +1,2 @@ + +obj-m += configfs_sample.o
samples/configfs/configfs_sample.c new file +404 -0
404 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH 23/23] configfs: remove old API
Hi Christoph,
Please see inline.
W dniu 25.09.2015 o 15:50, Christoph Hellwig pisze:
Quoted 82 lines
Remove the old
show_attributeandstore_attributemethods and update the documentation. Also replace the two C samples with a single new one in the proper samples directory where people expect to find it.Signed-off-by Christoph Hellwig <[email protected]>--- Documentation/filesystems/Makefile | 2 - Documentation/filesystems/configfs/Makefile | 3 - Documentation/filesystems/configfs/configfs.txt | 43 +- .../configfs/configfs_example_explicit.c | 483 --------------------- .../filesystems/configfs/configfs_example_macros.c | 446 ------------------- fs/configfs/file.c | 15 +- include/linux/configfs.h | 82 ---- samples/Makefile | 3 +- samples/configfs/Makefile | 2 + samples/configfs/configfs_sample.c | 404 +++++++++++++++++ 10 files changed, 427 insertions(+), 1056 deletions(-)delete mode 100644
Documentation/filesystems/configfs/Makefiledelete mode 100644Documentation/filesystems/configfs/configfs_example_explicit.cdelete mode 100644Documentation/filesystems/configfs/configfs_example_macros.ccreate mode 100644samples/configfs/Makefile
create mode 100644samples/configfs/configfs_sample.cDocumentation/filesystems/Makefile +0
-2@@ -1,5 +1,3 @@ -subdir-y := configfs - # List of programs to build hostprogs-y := dnotify_testDocumentation/filesystems/configfs/Makefile deleted +0
-3@@ -1,3 +0,0 @@ -ifneq ($(CONFIG_CONFIGFS_FS),) -obj-m += configfs_example_explicit.o configfs_example_macros.o -endifDocumentation/filesystems/configfs/configfs.txt +3
-9@@ -160,12 +160,6 @@ among other things. For that, it needs a type. struct configfs_item_operations { void (*release)(struct config_item *); - ssize_t (*show_attribute)(struct config_item *, - struct configfs_attribute *, - char *); - ssize_t (*store_attribute)(struct config_item *, - struct configfs_attribute *, - const char *, size_t); int (*allow_link)(struct config_item *src, struct config_item *target); int (*drop_link)(struct config_item *src,@@ -183,9 +177,7 @@ The most basic function of a config_item_type is to define what operations can be performed on a config_item. All items that have been allocated dynamically will need to provide the ct_item_ops->release() method. This method is called when the config_item's reference count -reaches zero. Items that wish to display an attribute need to provide -the ct_item_ops->show_attribute() method. Similarly, storing a new -attribute value uses the store_attribute() method. +reaches zero. [struct configfs_attribute]@@ -193,6 +185,8 @@ attribute value uses the store_attribute() method. char *ca_name; struct module *ca_owner; umode_t ca_mode; + ssize_t (*show)(struct config_item *, char *); + ssize_t (*store)(struct config_item *, const char *, size_t); }; When a config_item wants an attribute to appear as a file in the item's@@ -202,10 +196,15 @@ config_item_type->ct_attrs. When the item appears in configfs, the attribute file will appear with the configfs_attribute->ca_name filename. configfs_attribute->ca_mode specifies the file permissions.
Documentation/filesystems/configfs/configfs.txt config_item_type->ct_attrs. When the item appears in configfs, the · line 203
Quoted 10 lines
Documentation/filesystems/configfs/configfs.txt +5
-4-If an attribute is readable and the config_item provides a -ct_item_ops->show_attribute() method, that method will be called -whenever userspace asks for a read(2) on the attribute. The converse -will happen for write(2). +Items that wish to display an attribute need to provide +the ct_item_ops->show_attribute() method. Similarly, storing a new +attribute value uses the store_attribute() method. + +
Haven't you just removed show_attribute() and store_attribute() from configfs_item_operations?
Quoted 1,558 lines
Documentation/filesystems/configfs/configfs.txt +8
-14+If an attribute is readable and provides a ->show method, that method will +be called whenever userspace asks for a read(2) on the attribute. If an +attribute is writable and provides a ->store method, that method will be +be called whenever userspace asks for a write(2) on the attribute. [struct config_group]@@ -311,20 +310,10 @@ the subsystem must be ready for it. [An Example] The best example of these basic concepts is the simple_children -subsystem/group and the simple_child item in configfs_example_explicit.c -and configfs_example_macros.c. It shows a trivial object displaying and -storing an attribute, and a simple group creating and destroying these -children. - -The only difference between configfs_example_explicit.c and -configfs_example_macros.c is how the attributes of the childless item -are defined. The childless item has extended attributes, each with -their own show()/store() operation. This follows a convention commonly -used in sysfs. configfs_example_explicit.c creates these attributes -by explicitly defining the structures involved. Conversely -configfs_example_macros.c uses some convenience macros from configfs.h -to define the attributes. These macros are similar to their sysfs -counterparts. +subsystem/group and the simple_child item in +samples/configfs/configfs_sample.c. It shows a trivial object displaying +and storing an attribute, and a simple group creating and destroying +these children. [Hierarchy Navigation and the Subsystem Mutex]Documentation/filesystems/configfs/configfs_example_explicit.c deleted +0
-483@@ -1,483 +0,0 @@ -/* -* vim: noexpandtab ts=8 sts=0 sw=8: -* -* configfs_example_explicit.c - This file is a demonstration module -* containing a number of configfs subsystems. It explicitly defines -* each structure without using the helper macros defined in -* configfs.h. -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public -* License as published by the Free Software Foundation; either -* version 2 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 59 Temple Place - Suite 330, -* Boston, MA 021110-1307, USA. -* -* Based on sysfs: -* sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel -* -* configfs Copyright (C) 2005 Oracle. All rights reserved. -*/ - -#include <linux/init.h> -#include <linux/module.h> -#include <linux/slab.h> - -#include <linux/configfs.h> - - - -/* -* 01-childless -* -* This first example is a childless subsystem. It cannot create -* any config_items. It just has attributes. -* -* Note that we are enclosing the configfs_subsystem inside a container. -* This is not necessary if a subsystem has no attributes directly -* on the subsystem. See the next example, 02-simple-children, for -* such a subsystem. -*/ - -struct childless { -struct configfs_subsystem subsys; -int showme; -int storeme; -}; - -struct childless_attribute { -struct configfs_attribute attr; -ssize_t (*show)(struct childless *,char *); -ssize_t (*store)(struct childless *,const char *,size_t ); -}; - -static inline struct childless *to_childless (struct config_item *item) -{ - return item ? container_of(to_configfs_subsystem(to_config_group(item)), struct childless, subsys) : NULL; -} - -static ssize_t childless_showme_read (struct childless *childless, -char *page) -{ -ssize_t pos; - - pos =sprintf (page,"%d\n" , childless->showme); - childless->showme++; - -return pos; -} - -static ssize_t childless_storeme_read (struct childless *childless, -char *page) -{ -return sprintf (page,"%d\n" , childless->storeme); -} - -static ssize_t childless_storeme_write (struct childless *childless, -const char *page, -size_t count) -{ -unsigned long tmp; -char *p = (char *) page; - - tmp =simple_strtoul (p, &p,10 ); -if ((*p !='\0' ) && (*p !='\n' )) -return -EINVAL ; - -if (tmp >INT_MAX ) -return -ERANGE ; - - childless->storeme = tmp; - -return count; -} - -static ssize_t childless_description_read (struct childless *childless, -char *page) -{ -return sprintf (page, -"[01-childless]\n" -"\n" -"The childless subsystem is the simplest possible subsystem in\n" -"configfs. It does not support the creation of child config_items.\n" -"It only has a few attributes. In fact, it isn't much different\n" -"than a directory in /proc.\n" ); -} - -static struct childless_attribute childless_attr_showme = { - .attr = { .ca_owner =THIS_MODULE , .ca_name ="showme" , .ca_mode =S_IRUGO }, - .show = childless_showme_read, -}; -static struct childless_attribute childless_attr_storeme = { - .attr = { .ca_owner =THIS_MODULE , .ca_name ="storeme" , .ca_mode =S_IRUGO |S_IWUSR }, - .show = childless_storeme_read, - .store = childless_storeme_write, -}; -static struct childless_attribute childless_attr_description = { - .attr = { .ca_owner =THIS_MODULE , .ca_name ="description" , .ca_mode =S_IRUGO }, - .show = childless_description_read, -}; - -static struct configfs_attribute *childless_attrs[] = { - &childless_attr_showme.attr, - &childless_attr_storeme.attr, - &childless_attr_description.attr, -NULL , -}; - -static ssize_t childless_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -struct childless *childless =to_childless (item); -struct childless_attribute *childless_attr = - container_of(attr, struct childless_attribute, attr); -ssize_t ret =0 ; - -if (childless_attr->show) - ret = childless_attr->show (childless, page); -return ret; -} - -static ssize_t childless_attr_store (struct config_item *item, -struct configfs_attribute *attr, -const char *page,size_t count) -{ -struct childless *childless =to_childless (item); -struct childless_attribute *childless_attr = - container_of(attr, struct childless_attribute, attr); -ssize_t ret = -EINVAL ; - -if (childless_attr->store) - ret = childless_attr->store (childless, page, count); -return ret; -} - -static struct configfs_item_operations childless_item_ops = { - .show_attribute = childless_attr_show, - .store_attribute = childless_attr_store, -}; - -static struct config_item_type childless_type = { - .ct_item_ops = &childless_item_ops, - .ct_attrs = childless_attrs, - .ct_owner =THIS_MODULE , -}; - -static struct childless childless_subsys = { - .subsys = { - .su_group = { - .cg_item = { - .ci_namebuf ="01-childless" , - .ci_type = &childless_type, - }, - }, - }, -}; - - -/* ----------------------------------------------------------------- */ - -/* -* 02-simple-children -* -* This example merely has a simple one-attribute child. Note that -* there is no extra attribute structure, as the child's attribute is -* known from the get-go. Also, there is no container for the -* subsystem, as it has no attributes of its own. -*/ - -struct simple_child { -struct config_item item; -int storeme; -}; - -static inline struct simple_child *to_simple_child (struct config_item *item) -{ - return item ? container_of(item, struct simple_child, item) : NULL; -} - -static struct configfs_attribute simple_child_attr_storeme = { - .ca_owner =THIS_MODULE , - .ca_name ="storeme" , - .ca_mode =S_IRUGO |S_IWUSR , -}; - -static struct configfs_attribute *simple_child_attrs[] = { - &simple_child_attr_storeme, -NULL , -}; - -static ssize_t simple_child_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -ssize_t count; -struct simple_child *simple_child =to_simple_child (item); - - count =sprintf (page,"%d\n" , simple_child->storeme); - -return count; -} - -static ssize_t simple_child_attr_store (struct config_item *item, -struct configfs_attribute *attr, -const char *page,size_t count) -{ -struct simple_child *simple_child =to_simple_child (item); -unsigned long tmp; -char *p = (char *) page; - - tmp =simple_strtoul (p, &p,10 ); -if (!p || (*p && (*p !='\n' ))) -return -EINVAL ; - -if (tmp >INT_MAX ) -return -ERANGE ; - - simple_child->storeme = tmp; - -return count; -} - -static void simple_child_release (struct config_item *item) -{ -kfree (to_simple_child (item)); -} - -static struct configfs_item_operations simple_child_item_ops = { - .release = simple_child_release, - .show_attribute = simple_child_attr_show, - .store_attribute = simple_child_attr_store, -}; - -static struct config_item_type simple_child_type = { - .ct_item_ops = &simple_child_item_ops, - .ct_attrs = simple_child_attrs, - .ct_owner =THIS_MODULE , -}; - - -struct simple_children { -struct config_group group; -}; - -static inline struct simple_children *to_simple_children (struct config_item *item) -{ - return item ? container_of(to_config_group(item), struct simple_children, group) : NULL; -} - -static struct config_item *simple_children_make_item (struct config_group *group,const char *name) -{ -struct simple_child *simple_child; - - simple_child =kzalloc (sizeof (struct simple_child ),GFP_KERNEL ); -if (!simple_child) -return ERR_PTR (-ENOMEM ); - -config_item_init_type_name (&simple_child->item, name, - &simple_child_type); - - simple_child->storeme =0 ; - -return &simple_child->item; -} - -static struct configfs_attribute simple_children_attr_description = { - .ca_owner =THIS_MODULE , - .ca_name ="description" , - .ca_mode =S_IRUGO , -}; - -static struct configfs_attribute *simple_children_attrs[] = { - &simple_children_attr_description, -NULL , -}; - -static ssize_t simple_children_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -return sprintf (page, -"[02-simple-children]\n" -"\n" -"This subsystem allows the creation of child config_items. These\n" -"items have only one attribute that is readable and writeable.\n" ); -} - -static void simple_children_release (struct config_item *item) -{ -kfree (to_simple_children (item)); -} - -static struct configfs_item_operations simple_children_item_ops = { - .release = simple_children_release, - .show_attribute = simple_children_attr_show, -}; - -/* -* Note that, since no extra work is required on ->drop_item(), -* no ->drop_item() is provided. -*/ -static struct configfs_group_operations simple_children_group_ops = { - .make_item = simple_children_make_item, -}; - -static struct config_item_type simple_children_type = { - .ct_item_ops = &simple_children_item_ops, - .ct_group_ops = &simple_children_group_ops, - .ct_attrs = simple_children_attrs, - .ct_owner =THIS_MODULE , -}; - -static struct configfs_subsystem simple_children_subsys = { - .su_group = { - .cg_item = { - .ci_namebuf ="02-simple-children" , - .ci_type = &simple_children_type, - }, - }, -}; - - -/* ----------------------------------------------------------------- */ - -/* -* 03-group-children -* -* This example reuses the simple_children group from above. However, -* the simple_children group is not the subsystem itself, it is a -* child of the subsystem. Creation of a group in the subsystem creates -* a new simple_children group. That group can then have simple_child -* children of its own. -*/ - -static struct config_group *group_children_make_group (struct config_group *group,const char *name) -{ -struct simple_children *simple_children; - - simple_children =kzalloc (sizeof (struct simple_children ), -GFP_KERNEL ); -if (!simple_children) -return ERR_PTR (-ENOMEM ); - -config_group_init_type_name (&simple_children->group, name, - &simple_children_type); - -return &simple_children->group; -} - -static struct configfs_attribute group_children_attr_description = { - .ca_owner =THIS_MODULE , - .ca_name ="description" , - .ca_mode =S_IRUGO , -}; - -static struct configfs_attribute *group_children_attrs[] = { - &group_children_attr_description, -NULL , -}; - -static ssize_t group_children_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -return sprintf (page, -"[03-group-children]\n" -"\n" -"This subsystem allows the creation of child config_groups. These\n" -"groups are like the subsystem simple-children.\n" ); -} - -static struct configfs_item_operations group_children_item_ops = { - .show_attribute = group_children_attr_show, -}; - -/* -* Note that, since no extra work is required on ->drop_item(), -* no ->drop_item() is provided. -*/ -static struct configfs_group_operations group_children_group_ops = { - .make_group = group_children_make_group, -}; - -static struct config_item_type group_children_type = { - .ct_item_ops = &group_children_item_ops, - .ct_group_ops = &group_children_group_ops, - .ct_attrs = group_children_attrs, - .ct_owner =THIS_MODULE , -}; - -static struct configfs_subsystem group_children_subsys = { - .su_group = { - .cg_item = { - .ci_namebuf ="03-group-children" , - .ci_type = &group_children_type, - }, - }, -}; - -/* ----------------------------------------------------------------- */ - -/* -* We're now done with our subsystem definitions. -* For convenience in this module, here's a list of them all. It -* allows the init function to easily register them. Most modules -* will only have one subsystem, and will only call register_subsystem -* on it directly. -*/ -static struct configfs_subsystem *example_subsys[] = { - &childless_subsys.subsys, - &simple_children_subsys, - &group_children_subsys, -NULL , -}; - -static int __init configfs_example_init (void ) -{ -int ret; -int i; -struct configfs_subsystem *subsys; - -for (i =0 ; example_subsys[i]; i++) { - subsys = example_subsys[i]; - -config_group_init (&subsys->su_group); -mutex_init (&subsys->su_mutex); - ret =configfs_register_subsystem (subsys); -if (ret) { -printk (KERN_ERR "Error %d while registering subsystem %s\n" , - ret, - subsys->su_group.cg_item.ci_namebuf); - goto out_unregister; - } - } - -return 0 ; - -out_unregister: -for (i--; i >=0 ; i--) -configfs_unregister_subsystem (example_subsys[i]); - -return ret; -} - -static void __exit configfs_example_exit(void) -{ -int i; - -for (i =0 ; example_subsys[i]; i++) -configfs_unregister_subsystem (example_subsys[i]); -} - -module_init (configfs_example_init); -module_exit (configfs_example_exit); -MODULE_LICENSE ("GPL" );Documentation/filesystems/configfs/configfs_example_macros.c deleted +0
-446@@ -1,446 +0,0 @@ -/* -* vim: noexpandtab ts=8 sts=0 sw=8: -* -* configfs_example_macros.c - This file is a demonstration module -* containing a number of configfs subsystems. It uses the helper -* macros defined by configfs.h -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public -* License as published by the Free Software Foundation; either -* version 2 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 59 Temple Place - Suite 330, -* Boston, MA 021110-1307, USA. -* -* Based on sysfs: -* sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel -* -* configfs Copyright (C) 2005 Oracle. All rights reserved. -*/ - -#include <linux/init.h> -#include <linux/module.h> -#include <linux/slab.h> - -#include <linux/configfs.h> - - - -/* -* 01-childless -* -* This first example is a childless subsystem. It cannot create -* any config_items. It just has attributes. -* -* Note that we are enclosing the configfs_subsystem inside a container. -* This is not necessary if a subsystem has no attributes directly -* on the subsystem. See the next example, 02-simple-children, for -* such a subsystem. -*/ - -struct childless { -struct configfs_subsystem subsys; -int showme; -int storeme; -}; - -static inline struct childless *to_childless (struct config_item *item) -{ - return item ? container_of(to_configfs_subsystem(to_config_group(item)), struct childless, subsys) : NULL; -} - -CONFIGFS_ATTR_STRUCT (childless); -#define CHILDLESS_ATTR (_name, _mode, _show, _store) \ -struct childless_attribute childless_attr_##_name = __CONFIGFS_ATTR(_name, _mode, _show, _store) -#define CHILDLESS_ATTR_RO (_name, _show) \ -struct childless_attribute childless_attr_##_name = __CONFIGFS_ATTR_RO(_name, _show); - -static ssize_t childless_showme_read (struct childless *childless, -char *page) -{ -ssize_t pos; - - pos =sprintf (page,"%d\n" , childless->showme); - childless->showme++; - -return pos; -} - -static ssize_t childless_storeme_read (struct childless *childless, -char *page) -{ -return sprintf (page,"%d\n" , childless->storeme); -} - -static ssize_t childless_storeme_write (struct childless *childless, -const char *page, -size_t count) -{ -unsigned long tmp; -char *p = (char *) page; - - tmp =simple_strtoul (p, &p,10 ); -if (!p || (*p && (*p !='\n' ))) -return -EINVAL ; - -if (tmp >INT_MAX ) -return -ERANGE ; - - childless->storeme = tmp; - -return count; -} - -static ssize_t childless_description_read (struct childless *childless, -char *page) -{ -return sprintf (page, -"[01-childless]\n" -"\n" -"The childless subsystem is the simplest possible subsystem in\n" -"configfs. It does not support the creation of child config_items.\n" -"It only has a few attributes. In fact, it isn't much different\n" -"than a directory in /proc.\n" ); -} - -CHILDLESS_ATTR_RO (showme, childless_showme_read); -CHILDLESS_ATTR (storeme,S_IRUGO |S_IWUSR , childless_storeme_read, - childless_storeme_write); -CHILDLESS_ATTR_RO (description, childless_description_read); - -static struct configfs_attribute *childless_attrs[] = { - &childless_attr_showme.attr, - &childless_attr_storeme.attr, - &childless_attr_description.attr, -NULL , -}; - -CONFIGFS_ATTR_OPS (childless); -static struct configfs_item_operations childless_item_ops = { - .show_attribute = childless_attr_show, - .store_attribute = childless_attr_store, -}; - -static struct config_item_type childless_type = { - .ct_item_ops = &childless_item_ops, - .ct_attrs = childless_attrs, - .ct_owner =THIS_MODULE , -}; - -static struct childless childless_subsys = { - .subsys = { - .su_group = { - .cg_item = { - .ci_namebuf ="01-childless" , - .ci_type = &childless_type, - }, - }, - }, -}; - - -/* ----------------------------------------------------------------- */ - -/* -* 02-simple-children -* -* This example merely has a simple one-attribute child. Note that -* there is no extra attribute structure, as the child's attribute is -* known from the get-go. Also, there is no container for the -* subsystem, as it has no attributes of its own. -*/ - -struct simple_child { -struct config_item item; -int storeme; -}; - -static inline struct simple_child *to_simple_child (struct config_item *item) -{ - return item ? container_of(item, struct simple_child, item) : NULL; -} - -static struct configfs_attribute simple_child_attr_storeme = { - .ca_owner =THIS_MODULE , - .ca_name ="storeme" , - .ca_mode =S_IRUGO |S_IWUSR , -}; - -static struct configfs_attribute *simple_child_attrs[] = { - &simple_child_attr_storeme, -NULL , -}; - -static ssize_t simple_child_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -ssize_t count; -struct simple_child *simple_child =to_simple_child (item); - - count =sprintf (page,"%d\n" , simple_child->storeme); - -return count; -} - -static ssize_t simple_child_attr_store (struct config_item *item, -struct configfs_attribute *attr, -const char *page,size_t count) -{ -struct simple_child *simple_child =to_simple_child (item); -unsigned long tmp; -char *p = (char *) page; - - tmp =simple_strtoul (p, &p,10 ); -if (!p || (*p && (*p !='\n' ))) -return -EINVAL ; - -if (tmp >INT_MAX ) -return -ERANGE ; - - simple_child->storeme = tmp; - -return count; -} - -static void simple_child_release (struct config_item *item) -{ -kfree (to_simple_child (item)); -} - -static struct configfs_item_operations simple_child_item_ops = { - .release = simple_child_release, - .show_attribute = simple_child_attr_show, - .store_attribute = simple_child_attr_store, -}; - -static struct config_item_type simple_child_type = { - .ct_item_ops = &simple_child_item_ops, - .ct_attrs = simple_child_attrs, - .ct_owner =THIS_MODULE , -}; - - -struct simple_children { -struct config_group group; -}; - -static inline struct simple_children *to_simple_children (struct config_item *item) -{ - return item ? container_of(to_config_group(item), struct simple_children, group) : NULL; -} - -static struct config_item *simple_children_make_item (struct config_group *group,const char *name) -{ -struct simple_child *simple_child; - - simple_child =kzalloc (sizeof (struct simple_child ),GFP_KERNEL ); -if (!simple_child) -return ERR_PTR (-ENOMEM ); - -config_item_init_type_name (&simple_child->item, name, - &simple_child_type); - - simple_child->storeme =0 ; - -return &simple_child->item; -} - -static struct configfs_attribute simple_children_attr_description = { - .ca_owner =THIS_MODULE , - .ca_name ="description" , - .ca_mode =S_IRUGO , -}; - -static struct configfs_attribute *simple_children_attrs[] = { - &simple_children_attr_description, -NULL , -}; - -static ssize_t simple_children_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -return sprintf (page, -"[02-simple-children]\n" -"\n" -"This subsystem allows the creation of child config_items. These\n" -"items have only one attribute that is readable and writeable.\n" ); -} - -static void simple_children_release (struct config_item *item) -{ -kfree (to_simple_children (item)); -} - -static struct configfs_item_operations simple_children_item_ops = { - .release = simple_children_release, - .show_attribute = simple_children_attr_show, -}; - -/* -* Note that, since no extra work is required on ->drop_item(), -* no ->drop_item() is provided. -*/ -static struct configfs_group_operations simple_children_group_ops = { - .make_item = simple_children_make_item, -}; - -static struct config_item_type simple_children_type = { - .ct_item_ops = &simple_children_item_ops, - .ct_group_ops = &simple_children_group_ops, - .ct_attrs = simple_children_attrs, - .ct_owner =THIS_MODULE , -}; - -static struct configfs_subsystem simple_children_subsys = { - .su_group = { - .cg_item = { - .ci_namebuf ="02-simple-children" , - .ci_type = &simple_children_type, - }, - }, -}; - - -/* ----------------------------------------------------------------- */ - -/* -* 03-group-children -* -* This example reuses the simple_children group from above. However, -* the simple_children group is not the subsystem itself, it is a -* child of the subsystem. Creation of a group in the subsystem creates -* a new simple_children group. That group can then have simple_child -* children of its own. -*/ - -static struct config_group *group_children_make_group (struct config_group *group,const char *name) -{ -struct simple_children *simple_children; - - simple_children =kzalloc (sizeof (struct simple_children ), -GFP_KERNEL ); -if (!simple_children) -return ERR_PTR (-ENOMEM ); - -config_group_init_type_name (&simple_children->group, name, - &simple_children_type); - -return &simple_children->group; -} - -static struct configfs_attribute group_children_attr_description = { - .ca_owner =THIS_MODULE , - .ca_name ="description" , - .ca_mode =S_IRUGO , -}; - -static struct configfs_attribute *group_children_attrs[] = { - &group_children_attr_description, -NULL , -}; - -static ssize_t group_children_attr_show (struct config_item *item, -struct configfs_attribute *attr, -char *page) -{ -return sprintf (page, -"[03-group-children]\n" -"\n" -"This subsystem allows the creation of child config_groups. These\n" -"groups are like the subsystem simple-children.\n" ); -} - -static struct configfs_item_operations group_children_item_ops = { - .show_attribute = group_children_attr_show, -}; - -/* -* Note that, since no extra work is required on ->drop_item(), -* no ->drop_item() is provided. -*/ -static struct configfs_group_operations group_children_group_ops = { - .make_group = group_children_make_group, -}; - -static struct config_item_type group_children_type = { - .ct_item_ops = &group_children_item_ops, - .ct_group_ops = &group_children_group_ops, - .ct_attrs = group_children_attrs, - .ct_owner =THIS_MODULE , -}; - -static struct configfs_subsystem group_children_subsys = { - .su_group = { - .cg_item = { - .ci_namebuf ="03-group-children" , - .ci_type = &group_children_type, - }, - }, -}; - -/* ----------------------------------------------------------------- */ - -/* -* We're now done with our subsystem definitions. -* For convenience in this module, here's a list of them all. It -* allows the init function to easily register them. Most modules -* will only have one subsystem, and will only call register_subsystem -* on it directly. -*/ -static struct configfs_subsystem *example_subsys[] = { - &childless_subsys.subsys, - &simple_children_subsys, - &group_children_subsys, -NULL , -}; - -static int __init configfs_example_init (void ) -{ -int ret; -int i; -struct configfs_subsystem *subsys; - -for (i =0 ; example_subsys[i]; i++) { - subsys = example_subsys[i]; - -config_group_init (&subsys->su_group); -mutex_init (&subsys->su_mutex); - ret =configfs_register_subsystem (subsys); -if (ret) { -printk (KERN_ERR "Error %d while registering subsystem %s\n" , - ret, - subsys->su_group.cg_item.ci_namebuf); - goto out_unregister; - } - } - -return 0 ; - -out_unregister: -for (i--; i >=0 ; i--) -configfs_unregister_subsystem (example_subsys[i]); - -return ret; -} - -static void __exit configfs_example_exit(void) -{ -int i; - -for (i =0 ; example_subsys[i]; i++) -configfs_unregister_subsystem (example_subsys[i]); -} - -module_init (configfs_example_init); -module_exit (configfs_example_exit); -MODULE_LICENSE ("GPL" );fs/configfs/file.c +3
-12@@ -65,7 +65,6 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * buf {struct configfs_attribute * attr =to_attr (dentry);struct config_item * item =to_item (dentry->d_parent); -struct configfs_item_operations * ops = buffer->ops;int ret =0 ;ssize_t count;@@ -74,10 +73,7 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * bufif (!buffer->page)return -ENOMEM ; -if (ops->show_attribute) - count = ops->show_attribute (item, attr, buffer->page); -else - count = attr->show (item, buffer->page); + count = attr->show (item, buffer->page); buffer->needs_read_fill =0 ;BUG_ON (count > (ssize_t )SIMPLE_ATTR_SIZE );@@ -175,10 +171,7 @@ flush_write_buffer(struct dentry * dentry, struct configfs_buffer * buffer, size {struct configfs_attribute * attr =to_attr (dentry);struct config_item * item =to_item (dentry->d_parent); -struct configfs_item_operations * ops = buffer->ops; -if (ops->store_attribute) -return ops->store_attribute (item, attr, buffer->page, count);return attr->store (item, buffer->page, count); }@@ -243,8 +236,7 @@ static int check_perm(struct inode * inode, struct file * file)* and we must have a store method. */ if (file->f_mode &FMODE_WRITE ) { -if (!(inode->i_mode &S_IWUGO ) || - (!ops->store_attribute && !attr->store)) +if (!(inode->i_mode &S_IWUGO ) || !attr->store) goto Eaccess; }@@ -254,8 +246,7 @@ static int check_perm(struct inode * inode, struct file * file)* must be a show method for it. */ if (file->f_mode &FMODE_READ ) { -if (!(inode->i_mode &S_IRUGO ) || - (!ops->show_attribute && !attr->show)) +if (!(inode->i_mode &S_IRUGO ) || !attr->show) goto Eaccess; }include/linux/configfs.h +0
-82@@ -155,86 +155,6 @@ static struct configfs_attribute _pfx##attr_##_name = { \ }/* -* Users often need to create attribute structures for their configurable -* attributes, containing a configfs_attribute member and function pointers -* for the show() and store() operations on that attribute. If they don't -* need anything else on the extended attribute structure, they can use -* this macro to define it The argument _item is the name of the -* config_item structure. -*/ -#define CONFIGFS_ATTR_STRUCT (_item) \ -struct _item##_attribute { \ - struct configfs_attribute attr; \ - ssize_t (*show)(struct _item *, char *); \ - ssize_t (*store)(struct _item *, const char *, size_t); \ -} - -/* -* With the extended attribute structure, users can use this macro -* (similar to sysfs' __ATTR) to make defining attributes easier. -* An example: -* #define MYITEM_ATTR(_name, _mode, _show, _store) \ -* struct myitem_attribute childless_attr_##_name = \ -* __CONFIGFS_ATTR(_name, _mode, _show, _store) -*/ -#define __CONFIGFS_ATTR (_name, _mode, _show, _store) \ -{ \ - .attr = { \ - .ca_name = __stringify(_name), \ - .ca_mode = _mode, \ - .ca_owner = THIS_MODULE, \ - }, \ - .show = _show, \ - .store = _store, \ -} -/* Here is a readonly version, only requiring a show() operation */ -#define __CONFIGFS_ATTR_RO (_name, _show) \ -{ \ - .attr = { \ - .ca_name = __stringify(_name), \ - .ca_mode = 0444, \ - .ca_owner = THIS_MODULE, \ - }, \ - .show = _show, \ -} - -/* -* With these extended attributes, the simple show_attribute() and -* store_attribute() operations need to call the show() and store() of the -* attributes. This is a common pattern, so we provide a macro to define -* them. The argument _item is the name of the config_item structure. -* This macro expects the attributes to be named "struct <name>_attribute" -* and the function to_<name>() to exist; -*/ -#define CONFIGFS_ATTR_OPS (_item) \ -static ssize_t _item##_attr_show(struct config_item *item, \ - struct configfs_attribute *attr, \ - char *page) \ -{ \ - struct _item *_item = to_##_item(item); \ - struct _item##_attribute *_item##_attr = \ - container_of(attr, struct _item##_attribute, attr); \ - ssize_t ret = 0; \ - \ - if (_item##_attr->show) \ - ret = _item##_attr->show(_item, page); \ - return ret; \ -} \ -static ssize_t _item##_attr_store(struct config_item *item, \ - struct configfs_attribute *attr, \ - const char *page, size_t count) \ -{ \ - struct _item *_item = to_##_item(item); \ - struct _item##_attribute *_item##_attr = \ - container_of(attr, struct _item##_attribute, attr); \ - ssize_t ret = -EINVAL; \ - \ - if (_item##_attr->store) \ - ret = _item##_attr->store(_item, page, count); \ - return ret; \ -} - -/* * If allow_link() exists, the item can symlink(2) out to other * items. If the item is a group, it may support mkdir(2). * Groups supply one of make_group() and make_item(). If the @@ -250,8 +170,6 @@ static ssize_t _item##_attr_store(struct config_item *item, \*/ struct configfs_item_operations {void (*release)(struct config_item *); -ssize_t (*show_attribute)(struct config_item *,struct configfs_attribute *,char *); -ssize_t (*store_attribute)(struct config_item *,struct configfs_attribute *,const char *,size_t );int (*allow_link)(struct config_item *src,struct config_item *target);int (*drop_link)(struct config_item *src,struct config_item *target); };samples/Makefile +2
-1@@ -1,4 +1,5 @@ # Makefile for Linux samples code obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \ - hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ + hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ \ + configfs/samples/configfs/Makefile new file +2
-0@@ -0,0 +1,2 @@ + +obj-m += configfs_sample.osamples/configfs/configfs_sample.c new file +404
-0@@ -0,0 +1,404 @@ +/* +* vim: noexpandtab ts=8 sts=0 sw=8: +* +* configfs_example_macros.c - This file is a demonstration module +* containing a number of configfs subsystems. It uses the helper +* macros defined by configfs.h +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 021110-1307, USA. +* +* Based on sysfs: +* sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel +* +* configfs Copyright (C) 2005 Oracle. All rights reserved. +*/ + +#include <linux/init.h> +#include <linux/module.h> +#include <linux/slab.h> + +#include <linux/configfs.h> + + + +/* +* 01-childless +* +* This first example is a childless subsystem. It cannot create +* any config_items. It just has attributes. +* +* Note that we are enclosing the configfs_subsystem inside a container. +* This is not necessary if a subsystem has no attributes directly +* on the subsystem. See the next example, 02-simple-children, for +* such a subsystem. +*/ + +struct childless { +struct configfs_subsystem subsys; +int showme; +int storeme; +}; + +static inline struct childless *to_childless (struct config_item *item) +{ +return item ?container_of (to_configfs_subsystem (to_config_group (item)), + struct childless, subsys) : NULL; +} + +static ssize_t childless_showme_show (struct config_item *item,char *page) +{ +struct childless *childless =to_childless (item); +ssize_t pos; + + pos =sprintf (page,"%d\n" , childless->showme); + childless->showme++; + +return pos; +} + +static ssize_t childless_storeme_show (struct config_item *item,char *page) +{ +return sprintf (page,"%d\n" ,to_childless (item)->storeme); +} + +static ssize_t childless_storeme_store (struct config_item *item, +const char *page,size_t count) +{ +struct childless *childless =to_childless (item); +unsigned long tmp; +char *p = (char *) page; + + tmp =simple_strtoul (p, &p,10 ); +if (!p || (*p && (*p !='\n' ))) +return -EINVAL ; + +if (tmp >INT_MAX ) +return -ERANGE ; + + childless->storeme = tmp; + +return count; +} + +static ssize_t childless_description_show (struct config_item *item,char *page) +{ +return sprintf (page, +"[01-childless]\n" +"\n" +"The childless subsystem is the simplest possible subsystem in\n" +"configfs. It does not support the creation of child config_items.\n" +"It only has a few attributes. In fact, it isn't much different\n" +"than a directory in /proc.\n" ); +} + +CONFIGFS_ATTR_RO (childless_, showme); +CONFIGFS_ATTR (childless_, storeme); +CONFIGFS_ATTR_RO (childless_, description); + +static struct configfs_attribute *childless_attrs[] = { + &childless_attr_showme, + &childless_attr_storeme, + &childless_attr_description, +NULL , +}; + +static struct config_item_type childless_type = { + .ct_attrs = childless_attrs, + .ct_owner =THIS_MODULE , +}; + +static struct childless childless_subsys = { + .subsys = { + .su_group = { + .cg_item = { + .ci_namebuf ="01-childless" , + .ci_type = &childless_type, + }, + }, + }, +}; + + +/* ----------------------------------------------------------------- */ + +/* +* 02-simple-children +* +* This example merely has a simple one-attribute child. Note that +* there is no extra attribute structure, as the child's attribute is +* known from the get-go. Also, there is no container for the +* subsystem, as it has no attributes of its own. +*/ + +struct simple_child { +struct config_item item; +int storeme; +}; + +static inline struct simple_child *to_simple_child (struct config_item *item) +{ + return item ? container_of(item, struct simple_child, item) : NULL; +} + +static ssize_t simple_child_storeme_show (struct config_item *item,char *page) +{ +return sprintf (page,"%d\n" ,to_simple_child (item)->storeme); +} + +static ssize_t simple_child_storeme_store (struct config_item *item, +const char *page,size_t count) +{ +struct simple_child *simple_child =to_simple_child (item); +unsigned long tmp; +char *p = (char *) page; + + tmp =simple_strtoul (p, &p,10 ); +if (!p || (*p && (*p !='\n' ))) +return -EINVAL ; + +if (tmp >INT_MAX ) +return -ERANGE ; + + simple_child->storeme = tmp; + +return count; +} + +CONFIGFS_ATTR (simple_child_, storeme); + +static struct configfs_attribute *simple_child_attrs[] = { + &simple_child_attr_storeme, +NULL , +}; + +static void simple_child_release (struct config_item *item) +{ +kfree (to_simple_child (item)); +} + +static struct configfs_item_operations simple_child_item_ops = { + .release = simple_child_release, +}; + +static struct config_item_type simple_child_type = { + .ct_item_ops = &simple_child_item_ops, + .ct_attrs = simple_child_attrs, + .ct_owner =THIS_MODULE , +}; + + +struct simple_children { +struct config_group group; +}; + +static inline struct simple_children *to_simple_children (struct config_item *item) +{ +return item ?container_of (to_config_group (item), + struct simple_children, group) : NULL; +} + +static struct config_item *simple_children_make_item (struct config_group *group, +const char *name) +{ +struct simple_child *simple_child; + + simple_child =kzalloc (sizeof (struct simple_child ),GFP_KERNEL ); +if (!simple_child) +return ERR_PTR (-ENOMEM ); + +config_item_init_type_name (&simple_child->item, name, + &simple_child_type); + + simple_child->storeme =0 ; + +return &simple_child->item; +} + +static ssize_t simple_children_description_show (struct config_item *item, +char *page) +{ +return sprintf (page, +"[02-simple-children]\n" +"\n" +"This subsystem allows the creation of child config_items. These\n" +"items have only one attribute that is readable and writeable.\n" ); +} + +CONFIGFS_ATTR_RO (simple_children_, description); + +static struct configfs_attribute *simple_children_attrs[] = { + &simple_children_attr_description, +NULL , +}; + +static void simple_children_release (struct config_item *item) +{ +kfree (to_simple_children (item)); +} + +static struct configfs_item_operations simple_children_item_ops = { + .release = simple_children_release, +}; + +/* +* Note that, since no extra work is required on ->drop_item(), +* no ->drop_item() is provided. +*/ +static struct configfs_group_operations simple_children_group_ops = { + .make_item = simple_children_make_item, +}; + +static struct config_item_type simple_children_type = { + .ct_item_ops = &simple_children_item_ops, + .ct_group_ops = &simple_children_group_ops, + .ct_attrs = simple_children_attrs, + .ct_owner =THIS_MODULE , +}; + +static struct configfs_subsystem simple_children_subsys = { + .su_group = { + .cg_item = { + .ci_namebuf ="02-simple-children" , + .ci_type = &simple_children_type, + }, + }, +}; + + +/* ----------------------------------------------------------------- */ + +/* +* 03-group-children +* +* This example reuses the simple_children group from above. However, +* the simple_children group is not the subsystem itself, it is a +* child of the subsystem. Creation of a group in the subsystem creates +* a new simple_children group. That group can then have simple_child +* children of its own. +*/ + +static struct config_group *group_children_make_group ( +struct config_group *group,const char *name) +{ +struct simple_children *simple_children; + + simple_children =kzalloc (sizeof (struct simple_children ), +GFP_KERNEL ); +if (!simple_children) +return ERR_PTR (-ENOMEM ); + +config_group_init_type_name (&simple_children->group, name, + &simple_children_type); + +return &simple_children->group; +} + +static ssize_t group_children_description_show (struct config_item *item, +char *page) +{ +return sprintf (page, +"[03-group-children]\n" +"\n" +"This subsystem allows the creation of child config_groups. These\n" +"groups are like the subsystem simple-children.\n" ); +} + +CONFIGFS_ATTR_RO (group_children_, description); + +static struct configfs_attribute *group_children_attrs[] = { + &group_children_attr_description, +NULL , +}; + +/* +* Note that, since no extra work is required on ->drop_item(), +* no ->drop_item() is provided. +*/ +static struct configfs_group_operations group_children_group_ops = { + .make_group = group_children_make_group, +}; + +static struct config_item_type group_children_type = { + .ct_group_ops = &group_children_group_ops, + .ct_attrs = group_children_attrs, + .ct_owner =THIS_MODULE , +}; + +static struct configfs_subsystem group_children_subsys = { + .su_group = { + .cg_item = { + .ci_namebuf ="03-group-children" , + .ci_type = &group_children_type, + }, + }, +}; + +/* ----------------------------------------------------------------- */ + +/* +* We're now done with our subsystem definitions. +* For convenience in this module, here's a list of them all. It +* allows the init function to easily register them. Most modules +* will only have one subsystem, and will only call register_subsystem +* on it directly. +*/ +static struct configfs_subsystem *example_subsys[] = { + &childless_subsys.subsys, + &simple_children_subsys, + &group_children_subsys, +NULL , +}; + +static int __init configfs_example_init (void ) +{ +int ret; +int i; +struct configfs_subsystem *subsys; + +for (i =0 ; example_subsys[i]; i++) { + subsys = example_subsys[i]; + +config_group_init (&subsys->su_group); +mutex_init (&subsys->su_mutex); + ret =configfs_register_subsystem (subsys); +if (ret) { +printk (KERN_ERR "Error %d while registering subsystem %s\n" , + ret, + subsys->su_group.cg_item.ci_namebuf); + goto out_unregister; + } + } + +return 0 ; + +out_unregister: +for (i--; i >=0 ; i--) +configfs_unregister_subsystem (example_subsys[i]); + +return ret; +} + +static void __exit configfs_example_exit(void) +{ +int i; + +for (i =0 ; example_subsys[i]; i++) +configfs_unregister_subsystem (example_subsys[i]); +} + +module_init (configfs_example_init); +module_exit (configfs_example_exit); +MODULE_LICENSE ("GPL" );
Re: [PATCH 23/23] configfs: remove old API
Quoted 2 lines
Haven't you just removed
show_attribute()andstore_attribute()fromconfigfs_item_operations?
Oops, looks like the old text manage to slip back in. I'll fix it up.
Quoted 6 lines · Christoph Hellwig
This series consolidates the code to implement configfs attributes by providing the ->show and ->store method in common code and using
container_ofin the methods to access the containing structure.This reduces source and binary size of configfs consumers a lot.
Looking at the complete series, the subsystem it touches the most is target-core + fabric driver code, which is not surprising considering it's the largest consumer of configfs.
That said, it would probably make sense to merge via target-pending.git and get this series into linux-next ASAP.
--nab
Quoted 2 lines · Nicholas A. Bellinger
That said, it would probably make sense to merge via target-pending.git and get this series into linux-next ASAP.
Sounds good to me!
Hi Christoph,
W dniu 25.09.2015 o 15:49, Christoph Hellwig pisze:
Quoted 6 lines
This series consolidates the code to implement configfs attributes by providing the ->show and ->store method in common code and using
container_ofin the methods to access the containing structure.This reduces source and binary size of configfs consumers a lot.
Thank you for this series. It is definitely the way to go. I reviewed it as far as the configfs consumers which I wrote or have experience with are concerned. There are some minor issues which you perhaps can call nitpicks. In the last patch (23/23) I think you meant something different when changing the documentation - please see my response to that patch.
But otherwise this series is very welcome.
AP