drivers/platform/surface/aggregator/ssh_parser.h

Source file repositories/reference/linux-study-clean/drivers/platform/surface/aggregator/ssh_parser.h

File Facts

System
Linux kernel
Corpus path
drivers/platform/surface/aggregator/ssh_parser.h
Extension
.h
Size
4480 bytes
Lines
155
Domain
Driver Families
Bucket
drivers/platform
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 sshp_buf {
	u8    *ptr;
	size_t len;
	size_t cap;
};

/**
 * sshp_buf_init() - Initialize a SSH parser buffer.
 * @buf: The buffer to initialize.
 * @ptr: The memory backing the buffer.
 * @cap: The length of the memory backing the buffer, i.e. its capacity.
 *
 * Initializes the buffer with the given memory as backing and set its used
 * length to zero.
 */
static inline void sshp_buf_init(struct sshp_buf *buf, u8 *ptr, size_t cap)
{
	buf->ptr = ptr;
	buf->len = 0;
	buf->cap = cap;
}

/**
 * sshp_buf_alloc() - Allocate and initialize a SSH parser buffer.
 * @buf:   The buffer to initialize/allocate to.
 * @cap:   The desired capacity of the buffer.
 * @flags: The flags used for allocating the memory.
 *
 * Allocates @cap bytes and initializes the provided buffer struct with the
 * allocated memory.
 *
 * Return: Returns zero on success and %-ENOMEM if allocation failed.
 */
static inline int sshp_buf_alloc(struct sshp_buf *buf, size_t cap, gfp_t flags)
{
	u8 *ptr;

	ptr = kzalloc(cap, flags);
	if (!ptr)
		return -ENOMEM;

	sshp_buf_init(buf, ptr, cap);
	return 0;
}

/**
 * sshp_buf_free() - Free a SSH parser buffer.
 * @buf: The buffer to free.
 *
 * Frees a SSH parser buffer by freeing the memory backing it and then
 * resetting its pointer to %NULL and length and capacity to zero. Intended to
 * free a buffer previously allocated with sshp_buf_alloc().
 */
static inline void sshp_buf_free(struct sshp_buf *buf)
{
	kfree(buf->ptr);
	buf->ptr = NULL;
	buf->len = 0;
	buf->cap = 0;
}

/**
 * sshp_buf_drop() - Drop data from the beginning of the buffer.
 * @buf: The buffer to drop data from.
 * @n:   The number of bytes to drop.
 *
 * Drops the first @n bytes from the buffer. Re-aligns any remaining data to
 * the beginning of the buffer.
 */
static inline void sshp_buf_drop(struct sshp_buf *buf, size_t n)
{
	memmove(buf->ptr, buf->ptr + n, buf->len - n);
	buf->len -= n;
}

/**
 * sshp_buf_read_from_fifo() - Transfer data from a fifo to the buffer.
 * @buf:  The buffer to write the data into.
 * @fifo: The fifo to read the data from.
 *
 * Transfers the data contained in the fifo to the buffer, removing it from
 * the fifo. This function will try to transfer as much data as possible,
 * limited either by the remaining space in the buffer or by the number of
 * bytes available in the fifo.
 *
 * Return: Returns the number of bytes transferred.
 */
static inline size_t sshp_buf_read_from_fifo(struct sshp_buf *buf,
					     struct kfifo *fifo)
{

Annotation

Implementation Notes