drivers/md/dm-vdo/errors.c

Source file repositories/reference/linux-study-clean/drivers/md/dm-vdo/errors.c

File Facts

System
Linux kernel
Corpus path
drivers/md/dm-vdo/errors.c
Extension
.c
Size
8616 bytes
Lines
308
Domain
Driver Families
Bucket
drivers/md
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 error_block {
	const char *name;
	int base;
	int last;
	int max;
	const struct error_info *infos;
};

#define MAX_ERROR_BLOCKS 6

static struct {
	int allocated;
	int count;
	struct error_block blocks[MAX_ERROR_BLOCKS];
} registered_errors = {
	.allocated = MAX_ERROR_BLOCKS,
	.count = 1,
	.blocks = { {
			.name = "UDS Error",
			.base = UDS_ERROR_CODE_BASE,
			.last = UDS_ERROR_CODE_LAST,
			.max = UDS_ERROR_CODE_BLOCK_END,
			.infos = error_list,
		  } },
};

/* Get the error info for an error number. Also returns the name of the error block, if known. */
static const char *get_error_info(int errnum, const struct error_info **info_ptr)
{
	struct error_block *block;

	if (errnum == UDS_SUCCESS) {
		*info_ptr = &successful;
		return NULL;
	}

	for (block = registered_errors.blocks;
	     block < registered_errors.blocks + registered_errors.count;
	     block++) {
		if ((errnum >= block->base) && (errnum < block->last)) {
			*info_ptr = block->infos + (errnum - block->base);
			return block->name;
		} else if ((errnum >= block->last) && (errnum < block->max)) {
			*info_ptr = NULL;
			return block->name;
		}
	}

	return NULL;
}

/* Return a string describing a system error message. */
static const char *system_string_error(int errnum, char *buf, size_t buflen)
{
	size_t len;
	const char *error_string = NULL;

	if ((errnum > 0) && (errnum < ARRAY_SIZE(message_table)))
		error_string = message_table[errnum];

	len = ((error_string == NULL) ?
		 snprintf(buf, buflen, "Unknown error %d", errnum) :
		 snprintf(buf, buflen, "%s", error_string));
	if (len < buflen)
		return buf;

	buf[0] = '\0';
	return "System error";
}

/* Convert an error code to a descriptive string. */
const char *uds_string_error(int errnum, char *buf, size_t buflen)
{
	char *buffer = buf;
	char *buf_end = buf + buflen;
	const struct error_info *info = NULL;
	const char *block_name;

	if (buf == NULL)
		return NULL;

	if (errnum < 0)
		errnum = -errnum;

	block_name = get_error_info(errnum, &info);
	if (block_name != NULL) {
		if (info != NULL) {
			buffer = vdo_append_to_buffer(buffer, buf_end, "%s: %s",
						      block_name, info->message);
		} else {

Annotation

Implementation Notes