Skip to contentSkip to conversation

drm/nouveau: Two fixes from Clang warning audit

PATCH New Ian Rogers 2 participants 4 messages Nov 19

Subsystems (3)
lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

cover drm/nouveau: Two fixes from Clang warning audit

Two independent fixes in drm/nouveau found while auditing Clang warnings (-Wswitch-enum and -Wconditional-uninitialized) on an x86_64 allyesconfig build:

1. Handle NVIF_CONN_TV and release nv_connector on error in nouveau_connector_create().
2. Initialize primary_crc before switching on src in crcca7d_get_crc() for GB20x RG CRC capture.

Build-tested with LLVM=1 W=1 (-Werror); not runtime-tested on Nouveau hardware.

Ian Rogers (2):
drm/nouveau: Handle NVIF_CONN_TV and fix error cleanup in
nouveau_connector_create()
drm/nouveau/kms: Initialize primary_crc for RG CRC capture on GB20x

 drivers/gpu/drm/nouveau/dispnv50/crcca7d.c  | 1 +
 drivers/gpu/drm/nouveau/nouveau_connector.c | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
author
#1 lore raw

PATCH 1/2 drm/nouveau: Handle NVIF_CONN_TV and fix error cleanup in nouveau_connector_create()

In nouveau_connector_create(), the switch translating nvif connector types (nv_connector->conn.info.type) to DCB connector types omits NVIF_CONN_TV, even though nvkm_uconn_new() maps DCB TV connectors to NVIF_CONN_V0_TV -> NVIF_CONN_TV and the rest of nouveau_connector.c handles DCB_CONNECTOR_TV_0.

Furthermore, the default branch returns NULL without destroying nv_connector->conn or freeing nv_connector, whereas both callers (nv50_display_create() and nv04_display_create()) check only IS_ERR(connector) and immediately dereference connector on NULL.

Map NVIF_CONN_TV to DCB_CONNECTOR_TV_0, and clean up nv_connector->conn and nv_connector before returning ERR_PTR(-EINVAL) in the default branch.

Found by enabling Clang's -Wswitch-enum on an x86_64 allyesconfig build, with AI coding assistant help to audit the warning and prepare the fix. Build-tested with Clang; not runtime-tested on NVIDIA GPU hardware.

Fixes 8b7d92cad953 ("drm/nouveau/kms/nv50-: create connectors based on nvkm info")
---
 drivers/gpu/drm/nouveau/nouveau_connector.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_connector.c +6 -1
index cc3caf8de64b..51580824df36 100644
@@ -1394,6 +1394,9 @@ nouveau_connector_create(struct drm_device *dev, int index)
 
 		switch (nv_connector->conn.info.type) {
 		case NVIF_CONN_VGA      : type = DCB_CONNECTOR_VGA; break;
+		case NVIF_CONN_TV:
+			type = DCB_CONNECTOR_TV_0;
+			break;
 		case NVIF_CONN_DVI_I    : type = DCB_CONNECTOR_DVI_I; break;
 		case NVIF_CONN_DVI_D    : type = DCB_CONNECTOR_DVI_D; break;
 		case NVIF_CONN_LVDS     : type = DCB_CONNECTOR_LVDS; break;
@@ -1403,7 +1406,9 @@ nouveau_connector_create(struct drm_device *dev, int index)
 		case NVIF_CONN_HDMI     : type = DCB_CONNECTOR_HDMI_0; break;
 		default:
 			WARN_ON(1);
-			return NULL;
+			nvif_conn_dtor(&nv_connector->conn);
+			kfree(nv_connector);
+			return ERR_PTR(-EINVAL);
 		}
 
 		nv_connector->type = type;
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
author
#3 lore raw

PATCH 2/2 drm/nouveau/kms: Initialize primary_crc for RG CRC capture on GB20x

In reply to Ian Rogers

In crcca7d_set_src(), selecting the "rg" CRC source passes NV50_CRC_SOURCE_TYPE_RG, hitting the default case without initializing primary_crc before packing it into HEAD_SET_CRC_CONTROL's PRIMARY_CRC field.

Initialize primary_crc to NVCA7D_HEAD_SET_CRC_CONTROL_PRIMARY_CRC_NONE in the default branch, matching crcc37d_set_src() where RG CRC capture leaves PRIMARY_CRC set to NONE.

Found via Clang -Wconditional-uninitialized on an x86_64 allyesconfig build. Verified by building drivers/gpu/drm/nouveau/dispnv50/crcca7d.o with LLVM=1 W=1 (-Werror) and -Wconditional-uninitialized; not runtime-tested on NVIDIA Blackwell (GB20x) hardware.

Fixes 6cc6e08d4542 ("drm/nouveau/kms: add support for GB20x")
---
 drivers/gpu/drm/nouveau/dispnv50/crcca7d.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/nouveau/dispnv50/crcca7d.c +1 -0
index 912f59aebe87..02db81e5c8a3 100644
@@ -65,6 +65,7 @@ crcca7d_set_src(struct nv50_head *head, int or, enum nv50_crc_source_type source
 		primary_crc = NVCA7D_HEAD_SET_CRC_CONTROL_PRIMARY_CRC_SF;
 		break;
 	default:
+		primary_crc = NVCA7D_HEAD_SET_CRC_CONTROL_PRIMARY_CRC_NONE;
 		break;
 	}
 
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
#2 lore raw

Re: [PATCH 1/2] drm/nouveau: Handle NVIF_CONN_TV and fix error cleanup in nouveau_connector_create()

In reply to Ian Rogers
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] drm/nouveau: missing…

Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [High] drm/nouveau: missing drm_connector_cleanup() in nouveau_connector_create() [1]
--

commit 35127d593c69f43f2dbfc8d677382d137440fa37
Author: Ian Rogers <[email protected]>

drm/nouveau: Handle NVIF_CONN_TV and fix error cleanup in nouveau_connector_create()

This commit maps NVIF_CONN_TV to DCB_CONNECTOR_TV_0 in nouveau_connector_create() and cleans up nv_connector->conn and nv_connector before returning ERR_PTR(-EINVAL) in the default switch case.

Quoted 15 lines
drivers/gpu/drm/nouveau/nouveau_connector.c +3 -0
index e472c23c29811..22545fd06e05b 100644
@@ -1437,6 +1437,9 @@ nouveau_connector_create(struct drm_device *dev, int index)
 
 		switch (nv_connector->conn.info.type) {
 		case NVIF_CONN_VGA      : type = DCB_CONNECTOR_VGA; break;
+		case NVIF_CONN_TV:
+			type = DCB_CONNECTOR_TV_0;
+			break;
 		case NVIF_CONN_DVI_I    : type = DCB_CONNECTOR_DVI_I; break;
 		case NVIF_CONN_DVI_D    : type = DCB_CONNECTOR_DVI_D; break;
 		case NVIF_CONN_LVDS     : type = DCB_CONNECTOR_LVDS; break;

drivers/gpu/drm/nouveau/nouveau_connector.c nouveau_connector_create(struct drm_device *dev, int index) · line 1457

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_connector.c +3 -1
@@ -1446,7 +1449,9 @@ nouveau_connector_create(struct drm_device *dev, int index)
 		case NVIF_CONN_HDMI     : type = DCB_CONNECTOR_HDMI_0; break;
 		default:
 			WARN_ON(1);
-			return NULL;
+			nvif_conn_dtor(&nv_connector->conn);
+			kfree(nv_connector);
+			return ERR_PTR(-EINVAL);
 		}
 
 		nv_connector->type = type;

[Severity: High]
This problem wasn't introduced by this patch, but later in nouveau_connector_create(), does the LVDS error path [1] free nv_connector without calling drm_connector_cleanup()?

drivers/gpu/drm/nouveau/nouveau_connector.c:nouveau_connector_create() {
    ...
	drm_connector_init(dev, connector, funcs, type);

	switch (type) {
	case DRM_MODE_CONNECTOR_LVDS:
		ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &dummy);
		if (ret) {
			NV_ERROR(drm, "Error parsing LVDS table, disabling\n");
			kfree(nv_connector);
			return ERR_PTR(ret);
		}
    ...
}

If nouveau_bios_parse_lvds_table() fails after drm_connector_init() has registered connector with the DRM core, calling kfree(nv_connector) directly leaks the connector IDA and leaves a dangling pointer on the DRM connector list, causing a use-after-free when the list is later traversed or torn down.

[1] https://sashiko.dev/#/bug/linux-5fc9af31-e33a-4535-9e9a-4dc95a2d84c3

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1