drivers/net/wireless/ath/carl9170/debug.c

Source file repositories/reference/linux-study-clean/drivers/net/wireless/ath/carl9170/debug.c

File Facts

System
Linux kernel
Corpus path
drivers/net/wireless/ath/carl9170/debug.c
Extension
.c
Size
23725 bytes
Lines
883
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: implementation source
Status
source 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

struct carl9170_debugfs_fops {
	unsigned int read_bufsize;
	umode_t attr;
	char *(*read)(struct ar9170 *ar, char *buf, size_t bufsize,
		      ssize_t *len);
	ssize_t (*write)(struct ar9170 *aru, const char *buf, size_t size);

	enum carl9170_device_state req_dev_state;
};

static ssize_t carl9170_debugfs_read(struct file *file, char __user *userbuf,
				     size_t count, loff_t *ppos)
{
	const struct carl9170_debugfs_fops *dfops;
	struct ar9170 *ar;
	char *buf = NULL, *res_buf = NULL;
	ssize_t ret = 0;
	int err = 0;

	if (!count)
		return 0;

	ar = file->private_data;

	if (!ar)
		return -ENODEV;
	dfops = debugfs_get_aux(file);

	if (!dfops->read)
		return -ENOSYS;

	if (dfops->read_bufsize) {
		buf = vmalloc(dfops->read_bufsize);
		if (!buf)
			return -ENOMEM;
	}

	mutex_lock(&ar->mutex);
	if (!CHK_DEV_STATE(ar, dfops->req_dev_state)) {
		err = -ENODEV;
		res_buf = buf;
		goto out_free;
	}

	res_buf = dfops->read(ar, buf, dfops->read_bufsize, &ret);

	if (ret > 0)
		err = simple_read_from_buffer(userbuf, count, ppos,
					      res_buf, ret);
	else
		err = ret;

	WARN_ON_ONCE(dfops->read_bufsize && (res_buf != buf));

out_free:
	vfree(res_buf);
	mutex_unlock(&ar->mutex);
	return err;
}

static ssize_t carl9170_debugfs_write(struct file *file,
	const char __user *userbuf, size_t count, loff_t *ppos)
{
	const struct carl9170_debugfs_fops *dfops;
	struct ar9170 *ar;
	char *buf = NULL;
	int err = 0;

	if (!count)
		return 0;

	if (count > PAGE_SIZE)
		return -E2BIG;

	ar = file->private_data;

	if (!ar)
		return -ENODEV;
	dfops = debugfs_get_aux(file);

	if (!dfops->write)
		return -ENOSYS;

	buf = vmalloc(count);
	if (!buf)
		return -ENOMEM;

	if (copy_from_user(buf, userbuf, count)) {
		err = -EFAULT;
		goto out_free;

Annotation

Implementation Notes