sound/virtio/virtio_kctl.c

Source file repositories/reference/linux-study-clean/sound/virtio/virtio_kctl.c

File Facts

System
Linux kernel
Corpus path
sound/virtio/virtio_kctl.c
Extension
.c
Size
14911 bytes
Lines
528
Domain
Driver Families
Bucket
sound/virtio
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

if (!rc) {
			if (copy_to_user(utlv, tlv, size))
				rc = -EFAULT;
		}

		break;
	case SNDRV_CTL_TLV_OP_WRITE:
	case SNDRV_CTL_TLV_OP_CMD:
		if (op_flag == SNDRV_CTL_TLV_OP_WRITE)
			hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_TLV_WRITE);
		else
			hdr->hdr.code =
				cpu_to_le32(VIRTIO_SND_R_CTL_TLV_COMMAND);

		if (copy_from_user(tlv, utlv, size)) {
			rc = -EFAULT;
			goto on_msg_unref;
		} else {
			rc = virtsnd_ctl_msg_send(snd, msg, &sg, NULL, false);
		}

		break;
	default:
		rc = -EINVAL;
		/* We never get here - we listed all values for op_flag */
		WARN_ON(1);
		goto on_msg_unref;
	}
	kfree(tlv);
	return rc;

on_msg_unref:
	virtsnd_ctl_msg_unref(msg);
	kfree(tlv);

	return rc;
}

/**
 * virtsnd_kctl_get_enum_items() - Query items for the ENUMERATED element type.
 * @snd: VirtIO sound device.
 * @cid: Control element ID.
 *
 * This function is called during initial device initialization.
 *
 * Context: Any context that permits to sleep.
 * Return: 0 on success, -errno on failure.
 */
static int virtsnd_kctl_get_enum_items(struct virtio_snd *snd, unsigned int cid)
{
	struct virtio_device *vdev = snd->vdev;
	struct virtio_snd_ctl_info *kinfo = &snd->kctl_infos[cid];
	struct virtio_kctl *kctl = &snd->kctls[cid];
	struct virtio_snd_msg *msg;
	struct virtio_snd_ctl_hdr *hdr;
	unsigned int n = le32_to_cpu(kinfo->value.enumerated.items);
	struct scatterlist sg;

	msg = virtsnd_ctl_msg_alloc(sizeof(*hdr),
				    sizeof(struct virtio_snd_hdr), GFP_KERNEL);
	if (!msg)
		return -ENOMEM;

	kctl->items = devm_kcalloc(&vdev->dev, n, sizeof(*kctl->items),
				   GFP_KERNEL);
	if (!kctl->items) {
		virtsnd_ctl_msg_unref(msg);
		return -ENOMEM;
	}

	sg_init_one(&sg, kctl->items, n * sizeof(*kctl->items));

	hdr = virtsnd_ctl_msg_request(msg);
	hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_ENUM_ITEMS);
	hdr->control_id = cpu_to_le32(cid);

	return virtsnd_ctl_msg_send(snd, msg, NULL, &sg, false);
}

/**
 * virtsnd_kctl_parse_cfg() - Parse the control element configuration.
 * @snd: VirtIO sound device.
 *
 * This function is called during initial device initialization.
 *
 * Context: Any context that permits to sleep.
 * Return: 0 on success, -errno on failure.
 */
int virtsnd_kctl_parse_cfg(struct virtio_snd *snd)
{

Annotation

Implementation Notes