tools/testing/selftests/arm64/fp/kernel-test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/arm64/fp/kernel-test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/arm64/fp/kernel-test.c
Extension
.c
Size
6751 bytes
Lines
327
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (errno == EAFNOSUPPORT) {
			printf("AF_ALG not supported\n");
			return false;
		}

		printf("Failed to create AF_ALG socket: %s (%d)\n",
		       strerror(errno), errno);
		return false;
	}
	base = ret;

	memset(&addr, 0, sizeof(addr));
	addr.salg_family = AF_ALG;
	strncpy((char *)addr.salg_type, "hash", sizeof(addr.salg_type));

	proc = fopen("/proc/crypto", "r");
	if (!proc) {
		printf("Unable to open /proc/crypto\n");
		return false;
	}

	driver_name = NULL;
	is_shash = false;
	match = false;

	/* Look through /proc/crypto for a driver with kernel mode FP usage */
	while (!match) {
		c = fgets(buf, sizeof(buf), proc);
		if (!c) {
			if (feof(proc)) {
				printf("Nothing found in /proc/crypto\n");
				return false;
			}
			continue;
		}

		/* Algorithm descriptions are separated by a blank line */
		if (*c == '\n') {
			if (is_shash && driver_name) {
				for (i = 0; i < ARRAY_SIZE(drivers); i++) {
					if (strcmp(drivers[i],
						   driver_name) == 0) {
						match = true;
					}
				}
			}

			if (!match) {
				digest_len = 0;

				free(driver_name);
				driver_name = NULL;

				free(alg_name);
				alg_name = NULL;

				is_shash = false;
			}
			continue;
		}

		/* Remove trailing newline */
		c = strchr(buf, '\n');
		if (c)
			*c = '\0';

		/* Find the field/value separator and start of the value */
		c = strchr(buf, ':');
		if (!c)
			continue;
		c += 2;

		if (strncmp(buf, "digestsize", strlen("digestsize")) == 0)
			sscanf(c, "%d", &digest_len);

		if (strncmp(buf, "name", strlen("name")) == 0)
			alg_name = strdup(c);

		if (strncmp(buf, "driver", strlen("driver")) == 0)
			driver_name = strdup(c);

		if (strncmp(buf, "type", strlen("type")) == 0)
			if (strncmp(c, "shash", strlen("shash")) == 0)
				is_shash = true;
	}

	strncpy((char *)addr.salg_name, alg_name,
		sizeof(addr.salg_name) - 1);

	ret = bind(base, (struct sockaddr *)&addr, sizeof(addr));

Annotation

Implementation Notes