drivers/edac/edac_device_sysfs.c

Source file repositories/reference/linux-study-clean/drivers/edac/edac_device_sysfs.c

File Facts

System
Linux kernel
Corpus path
drivers/edac/edac_device_sysfs.c
Extension
.c
Size
23316 bytes
Lines
854
Domain
Driver Families
Bucket
drivers/edac
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

const struct bus_type *edac_subsys;
	int err = -ENODEV;

	edac_dbg(1, "\n");

	/* get the /sys/devices/system/edac reference */
	edac_subsys = edac_get_sysfs_subsys();

	/* Point to the 'edac_subsys' this instance 'reports' to */
	edac_dev->edac_subsys = edac_subsys;

	/* Init the devices's kobject */
	memset(&edac_dev->kobj, 0, sizeof(struct kobject));

	/* Record which module 'owns' this control structure
	 * and bump the ref count of the module
	 */
	edac_dev->owner = THIS_MODULE;

	if (!try_module_get(edac_dev->owner))
		goto err_out;

	/* register */
	dev_root = bus_get_dev_root(edac_subsys);
	if (dev_root) {
		err = kobject_init_and_add(&edac_dev->kobj, &ktype_device_ctrl,
					   &dev_root->kobj, "%s", edac_dev->name);
		put_device(dev_root);
	}
	if (err) {
		edac_dbg(1, "Failed to register '.../edac/%s'\n",
			 edac_dev->name);
		goto err_kobj_reg;
	}
	kobject_uevent(&edac_dev->kobj, KOBJ_ADD);

	/* At this point, to 'free' the control struct,
	 * edac_device_unregister_sysfs_main_kobj() must be used
	 */

	edac_dbg(4, "Registered '.../edac/%s' kobject\n", edac_dev->name);

	return 0;

	/* Error exit stack */
err_kobj_reg:
	kobject_put(&edac_dev->kobj);
	module_put(edac_dev->owner);

err_out:
	return err;
}

/*
 * edac_device_unregister_sysfs_main_kobj:
 *	the '..../edac/<name>' kobject
 */
void edac_device_unregister_sysfs_main_kobj(struct edac_device_ctl_info *dev)
{
	edac_dbg(0, "\n");
	edac_dbg(4, "name of kobject is: %s\n", kobject_name(&dev->kobj));

	/*
	 * Unregister the edac device's kobject and
	 * allow for reference count to reach 0 at which point
	 * the callback will be called to:
	 *   a) module_put() this module
	 *   b) 'kfree' the memory
	 */
	kobject_put(&dev->kobj);
}

/* edac_dev -> instance information */

/*
 * Set of low-level instance attribute show functions
 */
static ssize_t instance_ue_count_show(struct edac_device_instance *instance,
				char *data)
{
	return sprintf(data, "%u\n", instance->counters.ue_count);
}

static ssize_t instance_ce_count_show(struct edac_device_instance *instance,
				char *data)
{
	return sprintf(data, "%u\n", instance->counters.ce_count);
}

#define to_instance(k) container_of(k, struct edac_device_instance, kobj)

Annotation

Implementation Notes