drivers/usb/mon/mon_text.c

Source file repositories/reference/linux-study-clean/drivers/usb/mon/mon_text.c

File Facts

System
Linux kernel
Corpus path
drivers/usb/mon/mon_text.c
Extension
.c
Size
19469 bytes
Lines
754
Domain
Driver Families
Bucket
drivers/usb
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

static const struct file_operations mon_fops_text_t = {
	.owner =	THIS_MODULE,
	.open =		mon_text_open,
	.read =		mon_text_read_t,
	.release =	mon_text_release,
};

static const struct file_operations mon_fops_text_u = {
	.owner =	THIS_MODULE,
	.open =		mon_text_open,
	.read =		mon_text_read_u,
	.release =	mon_text_release,
};

int mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus)
{
	enum { NAMESZ = 12 };
	char name[NAMESZ];
	int busnum = ubus? ubus->busnum: 0;

	if (mon_dir == NULL)
		return 0;

	if (ubus != NULL) {
		scnprintf(name, NAMESZ, "%dt", busnum);
		mbus->dent_t = debugfs_create_file(name, 0600, mon_dir, mbus,
							     &mon_fops_text_t);
	}

	scnprintf(name, NAMESZ, "%du", busnum);
	mbus->dent_u = debugfs_create_file(name, 0600, mon_dir, mbus,
					   &mon_fops_text_u);

	scnprintf(name, NAMESZ, "%ds", busnum);
	mbus->dent_s = debugfs_create_file(name, 0600, mon_dir, mbus,
					   &mon_fops_stat);

	return 1;
}

void mon_text_del(struct mon_bus *mbus)
{
	debugfs_remove(mbus->dent_u);
	debugfs_remove(mbus->dent_t);
	debugfs_remove(mbus->dent_s);
}

/*
 * Slab interface: constructor.
 */
static void mon_text_ctor(void *mem)
{
	/*
	 * Nothing to initialize. No, really!
	 * So, we fill it with garbage to emulate a reused object.
	 */
	memset(mem, 0xe5, sizeof(struct mon_event_text));
}

int __init mon_text_init(void)
{
	mon_dir = debugfs_create_dir("usbmon", usb_debug_root);
	return 0;
}

void mon_text_exit(void)
{
	debugfs_remove(mon_dir);
}

Annotation

Implementation Notes