public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage
@ 2026-06-01  9:53 Hongling Zeng
  2026-06-01  9:53 ` [PATCH v2 1/5] nouveau/gsp/rpc: Document RPC function return value contracts Hongling Zeng
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Hongling Zeng @ 2026-06-01  9:53 UTC (permalink / raw)
  To: lyude, dakr, maarten.lankhorst, mripard, tzimmermann, airlied,
	simona, airlied, ttabi, bskeggs, dri-devel
  Cc: nouveau, linux-kernel, zhongling0719, Hongling Zeng

This series addresses feedback from Danilo Krummrich and Timur Tabi
regarding the use of IS_ERR() vs IS_ERR_OR_NULL() in the nouveau
GSP RPC code.

The key insight is that we should align error checking with the actual
return value contracts of each function:
- Functions that never return NULL should use IS_ERR()
- Functions that can return NULL should use IS_ERR_OR_NULL()

This version adds documentation to clarify the return value contracts,
making it easier for maintainers to validate future changes.

Return Value Analysis

After thorough code analysis, the RPC functions are categorized as:

Never return NULL (use IS_ERR):**
- r535_gsp_msgq_peek()
- r535_gsp_msgq_recv_one_elem()
- r535_gsp_rpc_get()

CAN return NULL (use IS_ERR_OR_NULL):**
- r535_gsp_msgq_recv() - returns NULL when RPC length is invalid
- r535_gsp_msg_recv() - returns NULL when queue drained
- r535_gsp_rpc_handle_reply() - returns NULL for NOWAIT/NOSEQ policies
- r535_gsp_rpc_send() - can return NULL via handle_reply
- r535_gsp_rpc_push() - can return NULL via handle_reply

Changes in v2

- Added kernel-doc comments documenting return value contracts for all
  RPC functions
- Cleaned up incorrect IS_ERR_OR_NULL() usage for functions that never
  return NULL
- Kept IS_ERR_OR_NULL() in places where NULL is actually possible
- Added Fixes tags to all patches

Testing

This fixes the NULL pointer dereference oops that occurs during
nouveau initialization on some systems.

Patches

Hongling Zeng (5):
  nouveau/gsp/rpc: Document RPC function return value contracts
  nouveau/gsp/rpc: Cleanup incorrect IS_ERR_OR_NULL in rpc.c
  nouveau/gsp/rm/alloc: Cleanup IS_ERR_OR_NULL usage
  nouveau/gsp/rm/bar: Cleanup IS_ERR_OR_NULL usage
  nouveau/gsp: Cleanup IS_ERR_OR_NULL in nvkm_gsp_rpc_rd()

 drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h   | 2 +-
 .../gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/alloc.c | 2 +-
 .../gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/bar.c  | 2 +-
 .../gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c  | 81 ++++++++++++++++++-
 4 files changed, 81 insertions(+), 6 deletions(-)

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/5] nouveau/gsp/rpc: Document RPC function return value contracts
  2026-06-01  9:53 [PATCH v2 0/5] nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage Hongling Zeng
@ 2026-06-01  9:53 ` Hongling Zeng
  2026-06-04  4:22   ` Claude review: " Claude Code Review Bot
  2026-06-01  9:54 ` [PATCH v2 2/5] nouveau/gsp/rpc: Cleanup incorrect IS_ERR_OR_NULL in rpc.c Hongling Zeng
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Hongling Zeng @ 2026-06-01  9:53 UTC (permalink / raw)
  To: lyude, dakr, maarten.lankhorst, mripard, tzimmermann, airlied,
	simona, airlied, ttabi, bskeggs, dri-devel
  Cc: nouveau, linux-kernel, zhongling0719, Hongling Zeng

Add kernel-doc comments to document the return value semantics of
RPC functions in r535/rpc.c. This clarifies which functions can return
NULL, error pointers, or both, helping maintainers validate future
changes.

Return value analysis:
- r535_gsp_msgq_peek(): Never returns NULL
- r535_gsp_msgq_recv_one_elem(): Never returns NULL
- r535_gsp_msgq_recv(): CAN return NULL (when RPC length invalid)
- r535_gsp_msg_recv(): CAN return NULL (queue drained/no matching message)
- r535_gsp_rpc_get(): Never returns NULL
- r535_gsp_rpc_handle_reply(): CAN return NULL (NOWAIT/NOSEQ policies)
- r535_gsp_rpc_send(): CAN return NULL (via handle_reply)
- r535_gsp_rpc_push(): CAN return NULL (via handle_reply)

Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
 .../drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c
index 3ca3de8f4340..7dd43fa38c41 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c
@@ -204,6 +204,15 @@ r535_gsp_msgq_get_entry(struct nvkm_gsp *gsp)
  *   The user is responsible for freeing the memory allocated for the GSP
  *   message pages after they have been processed.
  */
+/**
+ * r535_gsp_msgq_peek - Peek at next message in GSP command queue
+ * @gsp: GSP device
+ * @gsp_rpc_len: Expected RPC length
+ * @retries: Retry counter
+ *
+ * Return: Pointer to RPC message on success, or ERR_PTR() on error.
+ *         Never returns NULL.
+ */
 static void *
 r535_gsp_msgq_peek(struct nvkm_gsp *gsp, u32 gsp_rpc_len, int *retries)
 {
@@ -229,6 +238,14 @@ struct r535_gsp_msg_info {
 static void
 r535_gsp_msg_dump(struct nvkm_gsp *gsp, struct nvfw_gsp_rpc *msg, int lvl);
 
+/**
+ * r535_gsp_msgq_recv_one_elem - Receive one message element from GSP queue
+ * @gsp: GSP device
+ * @info: Message queue information
+ *
+ * Return: Pointer to received buffer on success, or ERR_PTR() on error.
+ *         Never returns NULL.
+ */
 static void *
 r535_gsp_msgq_recv_one_elem(struct nvkm_gsp *gsp,
 			    struct r535_gsp_msg_info *info)
@@ -283,6 +300,15 @@ r535_gsp_msgq_recv_one_elem(struct nvkm_gsp *gsp,
 	return buf;
 }
 
+/**
+ * r535_gsp_msgq_recv - Receive RPC message(s) from GSP queue
+ * @gsp: GSP device
+ * @gsp_rpc_len: Expected RPC length
+ * @retries: Retry counter
+ *
+ * Return: Pointer to received buffer on success, ERR_PTR() on error,
+ *         or NULL if RPC length is invalid.
+ */
 static void *
 r535_gsp_msgq_recv(struct nvkm_gsp *gsp, u32 gsp_rpc_len, int *retries)
 {
@@ -450,6 +476,15 @@ r535_gsp_msg_dump(struct nvkm_gsp *gsp, struct nvfw_gsp_rpc *msg, int lvl)
 	}
 }
 
+/**
+ * r535_gsp_msg_recv - Receive RPC message from GSP message queue
+ * @gsp: GSP device
+ * @fn: Expected RPC function number (0 to accept any)
+ * @gsp_rpc_len: Expected RPC length
+ *
+ * Return: Pointer to RPC message on success, ERR_PTR() on error,
+ *         or NULL if queue is drained or no matching message found.
+ */
 struct nvfw_gsp_rpc *
 r535_gsp_msg_recv(struct nvkm_gsp *gsp, int fn, u32 gsp_rpc_len)
 {
@@ -547,6 +582,17 @@ r535_gsp_rpc_poll(struct nvkm_gsp *gsp, u32 fn)
 	return 0;
 }
 
+/**
+ * r535_gsp_rpc_handle_reply - Handle RPC reply based on policy
+ * @gsp: GSP device
+ * @fn: RPC function number
+ * @policy: Reply policy (NOWAIT, NOSEQ, RECV, or POLL)
+ * @gsp_rpc_len: Expected RPC length
+ *
+ * Return: NULL when policy is NOWAIT or NOSEQ (no reply expected),
+ *         pointer to reply data on success, ERR_PTR() on error,
+ *         or NULL if no message available.
+ */
 static void *
 r535_gsp_rpc_handle_reply(struct nvkm_gsp *gsp, u32 fn,
 			  enum nvkm_gsp_rpc_reply_policy policy,
@@ -574,6 +620,16 @@ r535_gsp_rpc_handle_reply(struct nvkm_gsp *gsp, u32 fn,
 	return repv;
 }
 
+/**
+ * r535_gsp_rpc_send - Send RPC message and handle reply
+ * @gsp: GSP device
+ * @payload: RPC payload to send
+ * @policy: Reply policy (NOWAIT, NOSEQ, RECV, or POLL)
+ * @gsp_rpc_len: Expected RPC length for reply
+ *
+ * Return: NULL if policy is NOWAIT/NOSEQ (no reply expected),
+ *         pointer to reply data on success, or ERR_PTR() on error.
+ */
 static void *
 r535_gsp_rpc_send(struct nvkm_gsp *gsp, void *payload,
 		  enum nvkm_gsp_rpc_reply_policy policy, u32 gsp_rpc_len)
@@ -601,6 +657,15 @@ r535_gsp_rpc_send(struct nvkm_gsp *gsp, void *payload,
 	return r535_gsp_rpc_handle_reply(gsp, fn, policy, gsp_rpc_len);
 }
 
+/**
+ * r535_gsp_rpc_get - Allocate and initialize an RPC message
+ * @gsp: GSP device
+ * @fn: RPC function number
+ * @payload_size: Size of the payload
+ *
+ * Return: Pointer to RPC payload data on success, or ERR_PTR() on error.
+ *         Never returns NULL.
+ */
 static void
 r535_gsp_rpc_done(struct nvkm_gsp *gsp, void *repv)
 {
@@ -628,6 +693,16 @@ r535_gsp_rpc_get(struct nvkm_gsp *gsp, u32 fn, u32 payload_size)
 	return rpc->data;
 }
 
+/**
+ * r535_gsp_rpc_push - Push RPC message to GSP and wait for reply
+ * @gsp: GSP device
+ * @payload: RPC payload to send
+ * @policy: Reply policy (NOWAIT, NOSEQ, RECV, or POLL)
+ * @gsp_rpc_len: Expected RPC length in the reply
+ *
+ * Return: NULL when policy is NOWAIT/NOSEQ (no reply expected),
+ *         pointer to reply data on success, or ERR_PTR() on error.
+ */
 static void *
 r535_gsp_rpc_push(struct nvkm_gsp *gsp, void *payload,
 		  enum nvkm_gsp_rpc_reply_policy policy, u32 gsp_rpc_len)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/5] nouveau/gsp/rpc: Cleanup incorrect IS_ERR_OR_NULL in rpc.c
  2026-06-01  9:53 [PATCH v2 0/5] nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage Hongling Zeng
  2026-06-01  9:53 ` [PATCH v2 1/5] nouveau/gsp/rpc: Document RPC function return value contracts Hongling Zeng
@ 2026-06-01  9:54 ` Hongling Zeng
  2026-06-04  4:22   ` Claude review: " Claude Code Review Bot
  2026-06-01  9:54 ` [PATCH v2 3/5] nouveau/gsp/rm/alloc: Cleanup IS_ERR_OR_NULL usage Hongling Zeng
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Hongling Zeng @ 2026-06-01  9:54 UTC (permalink / raw)
  To: lyude, dakr, maarten.lankhorst, mripard, tzimmermann, airlied,
	simona, airlied, ttabi, bskeggs, dri-devel
  Cc: nouveau, linux-kernel, zhongling0719, Hongling Zeng

Clean up incorrect IS_ERR_OR_NULL() usage for functions that never
return NULL:
- r535_gsp_msgq_peek() never returns NULL
- r535_gsp_msgq_recv_one_elem() never returns NULL

These functions should be checked with IS_ERR() instead.

Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c
index 7dd43fa38c41..73f4aee9aa3f 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c
@@ -350,7 +350,7 @@ r535_gsp_msgq_recv(struct nvkm_gsp *gsp, u32 gsp_rpc_len, int *retries)
 		u32 size;
 
 		rpc = r535_gsp_msgq_peek(gsp, sizeof(*rpc), info.retries);
-		if (IS_ERR_OR_NULL(rpc)) {
+		if (IS_ERR(rpc)) {
 			kvfree(buf);
 			return rpc;
 		}
@@ -359,7 +359,7 @@ r535_gsp_msgq_recv(struct nvkm_gsp *gsp, u32 gsp_rpc_len, int *retries)
 		info.continuation = true;
 
 		rpc = r535_gsp_msgq_recv_one_elem(gsp, &info);
-		if (IS_ERR_OR_NULL(rpc)) {
+		if (IS_ERR(rpc)) {
 			kvfree(buf);
 			return rpc;
 		}
@@ -494,7 +494,7 @@ r535_gsp_msg_recv(struct nvkm_gsp *gsp, int fn, u32 gsp_rpc_len)
 
 retry:
 	rpc = r535_gsp_msgq_peek(gsp, sizeof(*rpc), &retries);
-	if (IS_ERR_OR_NULL(rpc))
+	if (IS_ERR(rpc))
 		return rpc;
 
 	rpc = r535_gsp_msgq_recv(gsp, gsp_rpc_len, &retries);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 3/5] nouveau/gsp/rm/alloc: Cleanup IS_ERR_OR_NULL usage
  2026-06-01  9:53 [PATCH v2 0/5] nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage Hongling Zeng
  2026-06-01  9:53 ` [PATCH v2 1/5] nouveau/gsp/rpc: Document RPC function return value contracts Hongling Zeng
  2026-06-01  9:54 ` [PATCH v2 2/5] nouveau/gsp/rpc: Cleanup incorrect IS_ERR_OR_NULL in rpc.c Hongling Zeng
@ 2026-06-01  9:54 ` Hongling Zeng
  2026-06-04  4:22   ` Claude review: " Claude Code Review Bot
  2026-06-01  9:54 ` [PATCH v2 4/5] nouveau/gsp/rm/bar: " Hongling Zeng
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Hongling Zeng @ 2026-06-01  9:54 UTC (permalink / raw)
  To: lyude, dakr, maarten.lankhorst, mripard, tzimmermann, airlied,
	simona, airlied, ttabi, bskeggs, dri-devel
  Cc: nouveau, linux-kernel, zhongling0719, Hongling Zeng

r535_gsp_rpc_rm_free() calls nvkm_gsp_rpc_get() which never returns
NULL, only valid pointers or error pointers. Clean up by using IS_ERR()
instead, matching the actual return value contract.

Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/alloc.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/alloc.c
index 46e3a29f2ad7..c9f86c0e9b25 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/alloc.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/alloc.c
@@ -35,7 +35,7 @@ r535_gsp_rpc_rm_free(struct nvkm_gsp_object *object)
 		   client->object.handle, object->handle);
 
 	rpc = nvkm_gsp_rpc_get(gsp, NV_VGPU_MSG_FUNCTION_FREE, sizeof(*rpc));
-	if (WARN_ON(IS_ERR_OR_NULL(rpc)))
+	if (WARN_ON(IS_ERR(rpc)))
 		return -EIO;
 
 	rpc->params.hRoot = client->object.handle;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 4/5] nouveau/gsp/rm/bar: Cleanup IS_ERR_OR_NULL usage
  2026-06-01  9:53 [PATCH v2 0/5] nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage Hongling Zeng
                   ` (2 preceding siblings ...)
  2026-06-01  9:54 ` [PATCH v2 3/5] nouveau/gsp/rm/alloc: Cleanup IS_ERR_OR_NULL usage Hongling Zeng
@ 2026-06-01  9:54 ` Hongling Zeng
  2026-06-04  4:22   ` Claude review: " Claude Code Review Bot
  2026-06-01  9:54 ` [PATCH v2 5/5] nouveau/gsp: Cleanup IS_ERR_OR_NULL in nvkm_gsp_rpc_rd() Hongling Zeng
  2026-06-04  4:22 ` Claude review: nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage Claude Code Review Bot
  5 siblings, 1 reply; 12+ messages in thread
From: Hongling Zeng @ 2026-06-01  9:54 UTC (permalink / raw)
  To: lyude, dakr, maarten.lankhorst, mripard, tzimmermann, airlied,
	simona, airlied, ttabi, bskeggs, dri-devel
  Cc: nouveau, linux-kernel, zhongling0719, Hongling Zeng

r535_bar_bar2_update_pde() calls nvkm_gsp_rpc_get() which never
returns NULL, only valid pointers or error pointers. Clean up by
using IS_ERR() instead, matching the actual return value contract.

Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/bar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/bar.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/bar.c
index fae08ac3b18c..9cd68f8622d3 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/bar.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/bar.c
@@ -55,7 +55,7 @@ r535_bar_bar2_update_pde(struct nvkm_gsp *gsp, u8 page_shift, u64 pdbe)
 	rpc_update_bar_pde_v15_00 *rpc;
 
 	rpc = nvkm_gsp_rpc_get(gsp, NV_VGPU_MSG_FUNCTION_UPDATE_BAR_PDE, sizeof(*rpc));
-	if (WARN_ON(IS_ERR_OR_NULL(rpc)))
+	if (WARN_ON(IS_ERR(rpc)))
 		return -EIO;
 
 	rpc->info.barType = NV_RPC_UPDATE_PDE_BAR_2;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 5/5] nouveau/gsp: Cleanup IS_ERR_OR_NULL in nvkm_gsp_rpc_rd()
  2026-06-01  9:53 [PATCH v2 0/5] nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage Hongling Zeng
                   ` (3 preceding siblings ...)
  2026-06-01  9:54 ` [PATCH v2 4/5] nouveau/gsp/rm/bar: " Hongling Zeng
@ 2026-06-01  9:54 ` Hongling Zeng
  2026-06-04  4:22   ` Claude review: " Claude Code Review Bot
  2026-06-04  4:22 ` Claude review: nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage Claude Code Review Bot
  5 siblings, 1 reply; 12+ messages in thread
From: Hongling Zeng @ 2026-06-01  9:54 UTC (permalink / raw)
  To: lyude, dakr, maarten.lankhorst, mripard, tzimmermann, airlied,
	simona, airlied, ttabi, bskeggs, dri-devel
  Cc: nouveau, linux-kernel, zhongling0719, Hongling Zeng

nvkm_gsp_rpc_rd() calls nvkm_gsp_rpc_get() which never returns NULL,
only valid pointers or error pointers. Clean up by using IS_ERR()
instead, matching the actual return value contract.

Note: nvkm_gsp_rpc_push() can return NULL when policy is NOWAIT or
NOSEQ, but nvkm_gsp_rpc_rd() uses RECV policy which expects a reply.
If the RPC fails to get a reply, it should return an error pointer,
not NULL.

Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
 drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
index 64fed208e4cf..a061779e0107 100644
--- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
+++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
@@ -293,7 +293,7 @@ nvkm_gsp_rpc_rd(struct nvkm_gsp *gsp, u32 fn, u32 argc)
 {
 	void *argv = nvkm_gsp_rpc_get(gsp, fn, argc);
 
-	if (IS_ERR_OR_NULL(argv))
+	if (IS_ERR(argv))
 		return argv;
 
 	return nvkm_gsp_rpc_push(gsp, argv, NVKM_GSP_RPC_REPLY_RECV, argc);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Claude review: nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage
  2026-06-01  9:53 [PATCH v2 0/5] nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage Hongling Zeng
                   ` (4 preceding siblings ...)
  2026-06-01  9:54 ` [PATCH v2 5/5] nouveau/gsp: Cleanup IS_ERR_OR_NULL in nvkm_gsp_rpc_rd() Hongling Zeng
@ 2026-06-04  4:22 ` Claude Code Review Bot
  5 siblings, 0 replies; 12+ messages in thread
From: Claude Code Review Bot @ 2026-06-04  4:22 UTC (permalink / raw)
  To: dri-devel-reviews

Overall Series Review

Subject: nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage
Author: Hongling Zeng <zenghongling@kylinos.cn>
Patches: 6
Reviewed: 2026-06-04T14:22:53.821924

---

This is a 5-patch series cleaning up `IS_ERR()` vs `IS_ERR_OR_NULL()` usage in the nouveau GSP RPC code, targeting alignment between error checks and actual function return-value contracts.

**The functional changes (patches 2-5) are already applied on drm-next**, which is why the patches don't apply cleanly. These may have been applied from an earlier version or independently. Only patch 1 (documentation) would be additive, but it contains a significant misplacement bug.

**The cover letter claims "Added Fixes tags to all patches"** in the v2 changelog, but none of the patches actually carry any `Fixes:` tags.

The return-value analysis in the cover letter is largely correct. One concern: the cover letter correctly identifies `r535_gsp_msgq_recv()` as able to return NULL (via the `WARN_ON(rpc->length > max_rpc_size)` path at rpc.c:299-300), but the series doesn't address the existing `IS_ERR()` check of its return value in `r535_gsp_msg_recv()` (rpc.c:465-466 on drm-next). If that NULL path ever fires, the subsequent `rpc->rpc_result` access would be a NULL pointer dereference. This is a pre-existing latent issue, not introduced by this series, but it's worth noting given the series explicitly analyzed this function's return contract.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Claude review: nouveau/gsp/rpc: Document RPC function return value contracts
  2026-06-01  9:53 ` [PATCH v2 1/5] nouveau/gsp/rpc: Document RPC function return value contracts Hongling Zeng
@ 2026-06-04  4:22   ` Claude Code Review Bot
  0 siblings, 0 replies; 12+ messages in thread
From: Claude Code Review Bot @ 2026-06-04  4:22 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

This patch adds kernel-doc comments documenting return value semantics. The analysis is mostly correct, but there is a **major placement bug**:

The doc comment for `r535_gsp_rpc_get` is placed before `r535_gsp_rpc_done()`, not before `r535_gsp_rpc_get()`:

```c
+/**
+ * r535_gsp_rpc_get - Allocate and initialize an RPC message
+ * @gsp: GSP device
+ * @fn: RPC function number
+ * @payload_size: Size of the payload
+ *
+ * Return: Pointer to RPC payload data on success, or ERR_PTR() on error.
+ *         Never returns NULL.
+ */
 static void
 r535_gsp_rpc_done(struct nvkm_gsp *gsp, void *repv)
```

In the source, `r535_gsp_rpc_done()` (line 604) comes before `r535_gsp_rpc_get()` (line 612). The doc comment is attached to the wrong function. The kernel-doc tooling would associate this `@gsp`, `@fn`, `@payload_size` documentation with `r535_gsp_rpc_done`, which only takes `(gsp, repv)` — a parameter mismatch that would produce kernel-doc warnings.

Minor: these are all `static` functions, so kernel-doc comments are somewhat unconventional here — inline `/* */` comments noting the return contract would suffice and be less maintenance burden.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Claude review: nouveau/gsp/rpc: Cleanup incorrect IS_ERR_OR_NULL in rpc.c
  2026-06-01  9:54 ` [PATCH v2 2/5] nouveau/gsp/rpc: Cleanup incorrect IS_ERR_OR_NULL in rpc.c Hongling Zeng
@ 2026-06-04  4:22   ` Claude Code Review Bot
  0 siblings, 0 replies; 12+ messages in thread
From: Claude Code Review Bot @ 2026-06-04  4:22 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

**Already applied on drm-next.** The changes are correct:

- `r535_gsp_msgq_peek()` only returns `ERR_PTR(ret)` (rpc.c:215) or a valid data pointer (rpc.c:219) — never NULL.
- `r535_gsp_msgq_recv_one_elem()` only returns `ERR_PTR(ret)` (rpc.c:246, 258) or `buf` from kvmalloc which was NULL-checked earlier — never NULL.

All three call sites correctly narrowed from `IS_ERR_OR_NULL()` to `IS_ERR()`.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Claude review: nouveau/gsp/rm/alloc: Cleanup IS_ERR_OR_NULL usage
  2026-06-01  9:54 ` [PATCH v2 3/5] nouveau/gsp/rm/alloc: Cleanup IS_ERR_OR_NULL usage Hongling Zeng
@ 2026-06-04  4:22   ` Claude Code Review Bot
  0 siblings, 0 replies; 12+ messages in thread
From: Claude Code Review Bot @ 2026-06-04  4:22 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

**Already applied on drm-next.** The change is correct:

```c
 	rpc = nvkm_gsp_rpc_get(gsp, NV_VGPU_MSG_FUNCTION_FREE, sizeof(*rpc));
-	if (WARN_ON(IS_ERR_OR_NULL(rpc)))
+	if (WARN_ON(IS_ERR(rpc)))
 		return -EIO;
```

`nvkm_gsp_rpc_get()` wraps `r535_gsp_rpc_get()`, which returns `ERR_CAST(rpc)` on error or `rpc->data` on success — never NULL.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Claude review: nouveau/gsp/rm/bar: Cleanup IS_ERR_OR_NULL usage
  2026-06-01  9:54 ` [PATCH v2 4/5] nouveau/gsp/rm/bar: " Hongling Zeng
@ 2026-06-04  4:22   ` Claude Code Review Bot
  0 siblings, 0 replies; 12+ messages in thread
From: Claude Code Review Bot @ 2026-06-04  4:22 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

**Already applied on drm-next.** Same rationale as patch 3 — `nvkm_gsp_rpc_get()` never returns NULL.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Claude review: nouveau/gsp: Cleanup IS_ERR_OR_NULL in nvkm_gsp_rpc_rd()
  2026-06-01  9:54 ` [PATCH v2 5/5] nouveau/gsp: Cleanup IS_ERR_OR_NULL in nvkm_gsp_rpc_rd() Hongling Zeng
@ 2026-06-04  4:22   ` Claude Code Review Bot
  0 siblings, 0 replies; 12+ messages in thread
From: Claude Code Review Bot @ 2026-06-04  4:22 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

**Already applied on drm-next.** The change to the `nvkm_gsp_rpc_get()` check is correct for the same reason.

The commit message notes that `nvkm_gsp_rpc_push()` can return NULL for NOWAIT/NOSEQ policies but `nvkm_gsp_rpc_rd()` uses RECV policy. This analysis is correct — the existing `IS_ERR_OR_NULL` was overly cautious for the `rpc_get` call, and the subsequent `rpc_push` with RECV policy should not return NULL either (RECV goes through `r535_gsp_msg_recv` with non-zero `gsp_rpc_len` and non-zero `fn`, which only returns NULL when `gsp_rpc_len == 0`).

---

**Summary:** Patches 2-5 are already in drm-next and are correct. Patch 1 has a misplaced doc comment (documenting `r535_gsp_rpc_get` but attached to `r535_gsp_rpc_done`). The promised `Fixes:` tags are absent from all patches.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-06-04  4:22 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-01  9:53 [PATCH v2 0/5] nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage Hongling Zeng
2026-06-01  9:53 ` [PATCH v2 1/5] nouveau/gsp/rpc: Document RPC function return value contracts Hongling Zeng
2026-06-04  4:22   ` Claude review: " Claude Code Review Bot
2026-06-01  9:54 ` [PATCH v2 2/5] nouveau/gsp/rpc: Cleanup incorrect IS_ERR_OR_NULL in rpc.c Hongling Zeng
2026-06-04  4:22   ` Claude review: " Claude Code Review Bot
2026-06-01  9:54 ` [PATCH v2 3/5] nouveau/gsp/rm/alloc: Cleanup IS_ERR_OR_NULL usage Hongling Zeng
2026-06-04  4:22   ` Claude review: " Claude Code Review Bot
2026-06-01  9:54 ` [PATCH v2 4/5] nouveau/gsp/rm/bar: " Hongling Zeng
2026-06-04  4:22   ` Claude review: " Claude Code Review Bot
2026-06-01  9:54 ` [PATCH v2 5/5] nouveau/gsp: Cleanup IS_ERR_OR_NULL in nvkm_gsp_rpc_rd() Hongling Zeng
2026-06-04  4:22   ` Claude review: " Claude Code Review Bot
2026-06-04  4:22 ` Claude review: nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage Claude Code Review Bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox