On Mon, Dec 15, 2025 at 03:36:25PM -0600, Ben Cheatham wrote:
snip
>
> +const struct cxl_protocol_error cxl_protocol_errors[] = {
> + CXL_PROTOCOL_ERROR(12, "cache-correctable"),
> + CXL_PROTOCOL_ERROR(13, "cache-uncorrectable"),
> + CXL_PROTOCOL_ERROR(14, "cache-fatal"),
> + CXL_PROTOCOL_ERROR(15, "mem-correctable"),
> + CXL_PROTOCOL_ERROR(16, "mem-uncorrectable"),
> + CXL_PROTOCOL_ERROR(17, "mem-fatal")
> +};
Can the above 'num' fields be the same nums as sysfs emits?
ie. s/12/0x00001000
Then no BIT(X) needed in the look ups and reads as more obvious
mapping from sysfs, where it looks like this:
0x00001000 CXL.cache Protocol Correctable
0x00002000 CXL.cache Protocol Uncorrectable non-fatal
0x00004000 CXL.cache Protocol Uncorrectable fatal
0x00008000 CXL.mem Protocol Correctable
0x00010000 CXL.mem Protocol Uncorrectable non-fatal
0x00020000 CXL.mem Protocol Uncorrectable fatal
A spec reference for those would be useful too.
I notice that the cxl list emit of einj_types reverses the order that
is presented in sysfs. Would be nice to match.
snip
> +
> +CXL_EXPORT int cxl_dport_protocol_error_inject(struct cxl_dport *dport,
> + unsigned int error)
> +{
> + struct cxl_ctx *ctx = dport->port->ctx;
> + char buf[32] = { 0 };
> + size_t path_len, len;
> + char *path;
> + int rc;
> +
> + if (!ctx->debugfs)
> + return -ENOENT;
> +
> + path_len = strlen(ctx->debugfs) + 100;
> + path = calloc(path_len, sizeof(char));
> + if (!path)
> + return -ENOMEM;
> +
> + len = snprintf(path, path_len, "%s/cxl/%s/einj_inject", ctx->debugfs,
> + cxl_dport_get_devname(dport));
> + if (len >= path_len) {
> + err(ctx, "%s: buffer too small\n",
> cxl_dport_get_devname(dport));
> + free(path);
> + return -ENOMEM;
> + }
> +
> + rc = access(path, F_OK);
> + if (rc) {
> + err(ctx, "failed to access %s: %s\n", path, strerror(errno));
> + free(path);
> + return -errno;
> + }
> +
> + len = snprintf(buf, sizeof(buf), "0x%lx\n", BIT(error));
> + if (len >= sizeof(buf)) {
> + err(ctx, "%s: buffer too small\n",
> cxl_dport_get_devname(dport));
> + free(path);
> + return -ENOMEM;
> + }
> +
> + rc = sysfs_write_attr(ctx, path, buf);
> + if (rc) {
> + err(ctx, "failed to write %s: %s\n", path, strerror(-rc));
> + free(path);
> + return -errno;
> + }
Coverity scan reports missing free(path) before return.
> +
> + return 0;
> +}
> +