On 27-11-2026 23:47, Rodrigo Vivi wrote:
drm_ras_node_get() returns a node of any type. The telemetry handlers check the type themselves, but the error-counter ones do not, so an error-counter operation on a telemetry node fails with -EOPNOTSUPP or walks its empty counter range, instead of reporting -ENOENT. Pass the expected type to drm_ras_node_get(), so a node of another type is not found, and drop the type checks of the telemetry handlers. Suggested-by: Riana Tauro <[email protected]> Acked-by: Zack McKevitt <[email protected]> Signed-off-by: Rodrigo Vivi <[email protected]>
Reviewed-by: Riana Tauro <[email protected]>
--- drivers/gpu/drm/drm_ras.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/drm_ras.c b/drivers/gpu/drm/drm_ras.c index 82fcc766b84b..5ae6d0a3b751 100644 --- a/drivers/gpu/drm/drm_ras.c +++ b/drivers/gpu/drm/drm_ras.c @@ -169,6 +169,7 @@ static_assert(sizeof(struct drm_ras_ctx) <= NETLINK_CTX_SIZE); /** * drm_ras_node_get() - Look up a RAS node by ID and take a reference * @node_id: ID of the node to look up + * @type: Expected type of the node * * Looks the node up in the global xarray and, if found, takes a reference to * it so that it cannot be freed while the caller is using it. The lookup and @@ -179,16 +180,19 @@ static_assert(sizeof(struct drm_ras_ctx) <= NETLINK_CTX_SIZE); * * The caller must drop the returned reference with drm_ras_node_put(). * - * Return: the referenced node, or NULL if no node with @node_id is registered. + * Return: the referenced node, or NULL if no node of @type with @node_id is + * registered. */ -static struct drm_ras_node *drm_ras_node_get(u32 node_id) +static struct drm_ras_node *drm_ras_node_get(u32 node_id, enum drm_ras_node_type type) { struct drm_ras_node *node;xa_lock(&drm_ras_xa);node = xa_load(&drm_ras_xa, node_id); - if (node) + if (node && node->type == type) refcount_inc(&node->ref); + else + node = NULL; xa_unlock(&drm_ras_xa);return node;@@ -412,7 +416,7 @@ static int doit_reply_value(struct genl_info *info, u32 node_id, u32 value; int ret;- node = drm_ras_node_get(node_id);+ node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_ERROR_COUNTER); if (!node) return -ENOENT;@@ -461,7 +465,7 @@ static int doit_reply_threshold(struct genl_info *info, u32 node_id, u32 error_iu32 threshold; int ret;- node = drm_ras_node_get(node_id);+ node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_ERROR_COUNTER); if (!node) return -ENOENT;@@ -603,7 +607,7 @@ int drm_ras_nl_get_error_counter_dumpit(struct sk_buff *skb, node_id = nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID]); - node = drm_ras_node_get(node_id);+ node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_ERROR_COUNTER); if (!node) return -ENOENT;@@ -699,7 +703,7 @@ int drm_ras_nl_clear_error_counter_doit(struct sk_buff *skb,node_id = nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID]); error_id = nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_ID]);- node = drm_ras_node_get(node_id);+ node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_ERROR_COUNTER); if (!node || !node->clear_error_counter) { drm_ras_node_put(node); return -ENOENT; @@ -770,7 +774,7 @@ int drm_ras_nl_set_error_threshold_doit(struct sk_buff *skb, struct genl_info *i error_id = nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_ID]); threshold = nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_THRESHOLD]);- node = drm_ras_node_get(node_id);+ node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_ERROR_COUNTER); if (!node) return -ENOENT;@@ -808,10 +812,9 @@ int drm_ras_nl_pre_telemetry(const struct genl_split_ops *ops, struct sk_buff *sreturn -EINVAL;node_id = nla_get_u32(info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]);- node = drm_ras_node_get(node_id); - if (!node || node->type != DRM_RAS_NODE_TYPE_TELEMETRY) { + node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_TELEMETRY); + if (!node) { NL_SET_BAD_ATTR(info->extack, info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]); - drm_ras_node_put(node); return -ENOENT; }@@ -892,10 +895,9 @@ int drm_ras_nl_telemetry_list_fields_dumpit(struct sk_buff *skb, struct netlink_ node_id = nla_get_u32(info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]); - node = drm_ras_node_get(node_id);- if (!node || node->type != DRM_RAS_NODE_TYPE_TELEMETRY) { + node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_TELEMETRY); + if (!node) { NL_SET_BAD_ATTR(info->extack, info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]); - drm_ras_node_put(node); return -ENOENT; }
