static int counter_avail_attr_create()

in counter-sysfs.c [392:425]


static int counter_avail_attr_create(struct device *const dev,
	struct counter_attribute_group *const group,
	const struct counter_comp *const comp, void *const parent)
{
	struct counter_attribute *counter_attr;
	struct device_attribute *dev_attr;

	counter_attr = devm_kzalloc(dev, sizeof(*counter_attr), GFP_KERNEL);
	if (!counter_attr)
		return -ENOMEM;

	/* Configure Counter attribute */
	counter_attr->comp.type = comp->type;
	counter_attr->comp.priv = comp->priv;
	counter_attr->parent = parent;

	/* Initialize sysfs attribute */
	dev_attr = &counter_attr->dev_attr;
	sysfs_attr_init(&dev_attr->attr);

	/* Configure device attribute */
	dev_attr->attr.name = devm_kasprintf(dev, GFP_KERNEL, "%s_available",
					     comp->name);
	if (!dev_attr->attr.name)
		return -ENOMEM;
	dev_attr->attr.mode = 0444;
	dev_attr->show = counter_comp_available_show;

	/* Store list node */
	list_add(&counter_attr->l, &group->attr_list);
	group->num_attr++;

	return 0;
}