1、f_usb_function_root_type
该结构变量就是实现创建新设备和给添加全局属性的关键。
c
static struct config_group *f_usb_function_sub_device_make(struct config_group *group, const char *name)
{
}
static void f_usb_function_sub_device_drop(struct config_group *group, struct config_item *item)
{
}
static const struct config_group_operations f_usb_function_root_group_ops = {
.make_gorup = f_usb_function_sub_device_make,
.drop_item = f_usb_function_sub_device_drop,
}
static void f_usb_device_root_release(struct config_item *item)
{
struct f_usb_function_device_opts *opts = container_of(to_config_group(item), struct f_usb_function_device_opts, inst.group);
usb_put_function_instance(&opts->inst);
}
static ssize_t f_usb_function_bufsize_show(struct config_item *item, char *buf)
{
struct f_usb_function_device_opts *opts = container_of(to_config_group(item), struct f_usb_function_device_opts, inst.group);
sprintf(buf, "%d\n", opts->bufsize);
}
static ssize_t f_usb_function_bufsize_show(struct config_item *item, const char *buf, size_t size)
{
struct f_usb_function_device_opts *opts = container_of(to_config_group(item), struct f_usb_function_device_opts, inst.group);
unsigned long val;
int ret;
ret = kstrtoul(buf, 0, &val);
if (ret)
return ret;
opts->bufsize = val;
return size;
}
CONFIGFS_ATTR(f_usb_function_, bufsize);
static const struct configfs_item_operations f_usb_function_root_ops = {
.release = f_usb_device_root_release,
};
static const struct configfs_attribute *f_usb_function_root_attrs[] = {
&f_usb_function_attr_bufsize,
NULL,
};
struct config_item_type f_usb_function_root_type {
.ct_group_ops = &f_usb_function_root_group_ops,
.ct_item_ops = &f_usb_function_root_ops,
.ct_attrs = f_usb_function_root_attrs,
.owner = THIS_MODULE,
};
在f_usb_device_root_release中调用usb_put_function_instance,在跟进去之后
就会发现,是调用了f_usb_function_device_instance_free,以此实现功能移除时
资源的释放。
属性的配置通过f_usb_function_root_attrs的回调函数实现。