cxl/list: handle missing debugfs when reporting protocol injection
Subsystems (2)
Alison Schofield
maintainerPATCH 1/1 cxl/list: handle missing debugfs when reporting protocol injection
When debugfs is not mounted or CONFIG_DEBUG_FS is disabled, 'cxl list -v' crashes while generating the protocol_injectable attribute for downstream ports.
The crash occurs because cxl_dport_get_einj_path() passes a NULL debugfs path to strlen().
Return NULL from cxl_dport_get_einj_path() when debugfs is unavailable, and omit protocol_injectable from the JSON output, consistent with other debugfs-dependent attributes. Update the documentation to match.
Thanks to Christopher Kim who reported and provided the fixup.
--- Documentation/cxl/cxl-inject-protocol-error.txt | 5 ++--- cxl/json.c | 15 +++++++++------ cxl/lib/libcxl.c | 3 +++ 3 files changed, 14 insertions(+), 9 deletions(-)
Documentation/cxl/cxl-inject-protocol-error.txt +2 -3
@@ -81,9 +81,8 @@ must be enabled. For more information, view the Linux kernel documentation on EI This command depends on the CXL debug filesystem (normally mounted at "/sys/kernel/debug/cxl") to inject protocol errors. If the CXL debugfs is not -accessible the "protocol_injectable" attribute of dports will always be -set to false, and the "injectable_protocol_errors" attribute of CXL busses -will always be empty. +accessible, the "protocol_injectable" attribute of dports and the +"injectable_protocol_errors" attribute of CXL buses are omitted. OPTIONS -------
cxl/json.c +9 -6
@@ -746,12 +746,15 @@ void util_cxl_dports_append_json(struct json_object *jport,if (jobj)json_object_object_add (jdport,"id" , jobj); - einj_path =cxl_dport_get_einj_path (dport); - jobj =json_object_new_boolean (einj_path !=NULL ); -if (jobj) -json_object_object_add (jdport,"protocol_injectable" , - jobj); -free (einj_path); +if (cxl_debugfs_exists (cxl_port_get_ctx (port))) { + einj_path =cxl_dport_get_einj_path (dport); + jobj =json_object_new_boolean (einj_path !=NULL ); +if (jobj) +json_object_object_add (jdport, +"protocol_injectable" , + jobj); +free (einj_path); + }json_object_array_add (jdports, jdport);json_object_set_userdata (jdport, dport,NULL );
cxl/lib/libcxl.c +3 -0
@@ -3589,6 +3589,9 @@ CXL_EXPORT char *cxl_dport_get_einj_path(struct cxl_dport *dport)char *path;int rc; +if (!ctx->cxl_debugfs) +return NULL ; + path_len =strlen (ctx->cxl_debugfs) +100 ; path =calloc (path_len,sizeof (char ));if (!path)
Signature · 1 line
2.37.3
Quoted 11 lines · Alison Schofield
When debugfs is not mounted or
CONFIG_DEBUG_FSis disabled, 'cxl list -v' crashes while generating theprotocol_injectableattribute for downstream ports.The crash occurs because
cxl_dport_get_einj_path()passes a NULL debugfs path tostrlen().Return NULL from
cxl_dport_get_einj_path()when debugfs is unavailable, and omitprotocol_injectablefrom the JSON output, consistent with other debugfs-dependent attributes. Update the documentation to match.
Quoted 6 lines
Thanks to Christopher Kim who reported and provided the fixup.
Originally-by Christopher KimFixes 5d596866f8c5 ("cxl/list: add injectable errors in output")Signed-off-by Alison Schofield <[email protected]>
LGTM,
Quoted 11 lines · Alison Schofield
When debugfs is not mounted or
CONFIG_DEBUG_FSis disabled, 'cxl list -v' crashes while generating theprotocol_injectableattribute for downstream ports.The crash occurs because
cxl_dport_get_einj_path()passes a NULL debugfs path tostrlen().Return NULL from
cxl_dport_get_einj_path()when debugfs is unavailable, and omitprotocol_injectablefrom the JSON output, consistent with other debugfs-dependent attributes. Update the documentation to match.
Quoted 6 lines
Thanks to Christopher Kim who reported and provided the fixup.
Originally-by Christopher KimFixes 5d596866f8c5 ("cxl/list: add injectable errors in output")Signed-off-by Alison Schofield <[email protected]>
Applied to pending for NDCTL v86
https://github.com/pmem/ndctl/commit/1b126bf930c5