Skip to contentSkip to conversation

remoteproc: Fix potential null pointer dereference in pru_rproc_set_ctable()

PATCH Superseded Zhen Ni 3 participants 6 messages Sep 23, 2025

Subsystems (2)
lore
Share & tools
lore

Zhen Ni

author
#0 lore raw

PATCH 1/1 remoteproc: Fix potential null pointer dereference in pru_rproc_set_ctable()

pru_rproc_set_ctable() accessed rproc->priv before the IS_ERR_OR_NULL check, which could lead to a null pointer dereference. Move the pru assignment, ensuring we never dereference a NULL rproc pointer.

Fixes 102853400321 ("remoteproc: pru: Add pru_rproc_set_ctable() function")
---
 drivers/remoteproc/pru_rproc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/remoteproc/pru_rproc.c +2 -1
index 842e4b6cc5f9..5e3eb7b86a0e 100644
@@ -340,7 +340,7 @@ EXPORT_SYMBOL_GPL(pru_rproc_put);
  */
 int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
 {
-	struct pru_rproc *pru = rproc->priv;
+	struct pru_rproc *pru;
 	unsigned int reg;
 	u32 mask, set;
 	u16 idx;
@@ -352,6 +352,7 @@ int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
 	if (!rproc->dev.parent || !is_pru_rproc(rproc->dev.parent))
 		return -ENODEV;
 
+	pru = rproc->priv;
 	/* pointer is 16 bit and index is 8-bit so mask out the rest */
 	idx_mask = (c >= PRU_C28) ? 0xFFFF : 0xFF;
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Zhen Ni

pru_rproc_set_ctable() accessed rproc->priv before the IS_ERR_OR_NULL check, which could lead to a null pointer dereference. Move the pru assignment, ensuring we never dereference a NULL rproc pointer.

Fixes 102853400321 ("remoteproc: pru: Add pru_rproc_set_ctable() function")

LGTM. Minor style suggestion: consider changing "null" to "NULL" in the subject/commit message for consistency with kernel coding style and terminology.

FWIW. Please feel free to comment or override if needed.

Quoted 25 lines
---
  drivers/remoteproc/pru_rproc.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/remoteproc/pru_rproc.c +2 -1
index 842e4b6cc5f9..5e3eb7b86a0e 100644
@@ -340,7 +340,7 @@ EXPORT_SYMBOL_GPL(pru_rproc_put);
   */
  int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
  {
-	struct pru_rproc *pru = rproc->priv;
+	struct pru_rproc *pru;
  	unsigned int reg;
  	u32 mask, set;
  	u16 idx;
@@ -352,6 +352,7 @@ int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
  	if (!rproc->dev.parent || !is_pru_rproc(rproc->dev.parent))
  		return -ENODEV;
 
+	pru = rproc->priv;
  	/* pointer is 16 bit and index is 8-bit so mask out the rest */
  	idx_mask = (c >= PRU_C28) ? 0xFFFF : 0xFF;
 
Signature · 2 lines
Thx and BRs,
Zhongqiu Han
#2 lore raw
Quoted 5 lines · Zhongqiu Han
Quoted 4 lines · Zhen Ni

pru_rproc_set_ctable() accessed rproc->priv before the IS_ERR_OR_NULL check, which could lead to a null pointer dereference. Move the pru assignment, ensuring we never dereference a NULL rproc pointer.

Quoted 9 lines
Quoted 3 lines
Fixes 102853400321 ("remoteproc: pru: Add pru_rproc_set_ctable() function")

LGTM. Minor style suggestion: consider changing "null" to "NULL" in the subject/commit message for consistency with kernel coding style and terminology.

Also, for consistency with subsystem tagging conventions, please consider updating the subject line to:

remoteproc: pru: Fix potential NULL pointer dereference in pru_rproc_set_ctable()

This makes it clearer that the change is specific to the PRU driver under remoteproc.

Quoted 31 lines

FWIW. Please feel free to comment or override if needed.

Quoted 24 lines

---
  drivers/remoteproc/pru_rproc.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/remoteproc/pru_rproc.c +2 -1
index 842e4b6cc5f9..5e3eb7b86a0e 100644
@@ -340,7 +340,7 @@ EXPORT_SYMBOL_GPL(pru_rproc_put);
    */
   int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
   {
-    struct pru_rproc *pru = rproc->priv;
+    struct pru_rproc *pru;
       unsigned int reg;
       u32 mask, set;
       u16 idx;
@@ -352,6 +352,7 @@ int pru_rproc_set_ctable(struct rproc *rproc, enum 
 pru_ctable_idx c, u32 addr)
       if (!rproc->dev.parent || !is_pru_rproc(rproc->dev.parent))
           return -ENODEV;
+    pru = rproc->priv;
       /* pointer is 16 bit and index is 8-bit so mask out the rest */
       idx_mask = (c >= PRU_C28) ? 0xFFFF : 0xFF;
Signature · 2 lines
Thx and BRs,
Zhongqiu Han
author
#3 lore raw

PATCH v2 1/1 remoteproc: pru: Fix potential NULL pointer dereference in pru_rproc_set_ctable()

In reply to Zhen Ni

pru_rproc_set_ctable() accessed rproc->priv before the IS_ERR_OR_NULL check, which could lead to a null pointer dereference. Move the pru assignment, ensuring we never dereference a NULL rproc pointer.

Fixes 102853400321 ("remoteproc: pru: Add pru_rproc_set_ctable() function")

---
v2:
- Changed "null" to "NULL"
- Added " pru:" prefix

---
 drivers/remoteproc/pru_rproc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/remoteproc/pru_rproc.c +2 -1
index 842e4b6cc5f9..5e3eb7b86a0e 100644
@@ -340,7 +340,7 @@ EXPORT_SYMBOL_GPL(pru_rproc_put);
  */
 int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
 {
-	struct pru_rproc *pru = rproc->priv;
+	struct pru_rproc *pru;
 	unsigned int reg;
 	u32 mask, set;
 	u16 idx;
@@ -352,6 +352,7 @@ int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
 	if (!rproc->dev.parent || !is_pru_rproc(rproc->dev.parent))
 		return -ENODEV;
 
+	pru = rproc->priv;
 	/* pointer is 16 bit and index is 8-bit so mask out the rest */
 	idx_mask = (c >= PRU_C28) ? 0xFFFF : 0xFF;
 
Signature · 1 line
2.20.1
#4 lore raw

Re: [PATCH v2] remoteproc: pru: Fix potential NULL pointer dereference in pru_rproc_set_ctable()

Quoted 11 lines · Zhen Ni

pru_rproc_set_ctable() accessed rproc->priv before the IS_ERR_OR_NULL check, which could lead to a null pointer dereference. Move the pru assignment, ensuring we never dereference a NULL rproc pointer.

Fixes 102853400321 ("remoteproc: pru: Add pru_rproc_set_ctable() function")

---
v2:
- Changed "null" to "NULL"
- Added " pru:" prefix

- Link to v1:
https://lore.kernel.org/all/[email protected]/

Quoted 25 lines
---
  drivers/remoteproc/pru_rproc.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/remoteproc/pru_rproc.c +2 -1
index 842e4b6cc5f9..5e3eb7b86a0e 100644
@@ -340,7 +340,7 @@ EXPORT_SYMBOL_GPL(pru_rproc_put);
   */
  int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
  {
-	struct pru_rproc *pru = rproc->priv;
+	struct pru_rproc *pru;
  	unsigned int reg;
  	u32 mask, set;
  	u16 idx;
@@ -352,6 +352,7 @@ int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
  	if (!rproc->dev.parent || !is_pru_rproc(rproc->dev.parent))
  		return -ENODEV;
 
+	pru = rproc->priv;
  	/* pointer is 16 bit and index is 8-bit so mask out the rest */
  	idx_mask = (c >= PRU_C28) ? 0xFFFF : 0xFF;
 
Signature · 2 lines
Thx and BRs,
Zhongqiu Han
maintainer Applied
#5 lore raw

Re: [PATCH v2] remoteproc: pru: Fix potential NULL pointer dereference in pru_rproc_set_ctable()

In reply to Zhen Ni
Quoted 7 lines · Zhen Ni

pru_rproc_set_ctable() accessed rproc->priv before the IS_ERR_OR_NULL check, which could lead to a null pointer dereference. Move the pru assignment, ensuring we never dereference a NULL rproc pointer.

Fixes 102853400321 ("remoteproc: pru: Add pru_rproc_set_ctable() function")

Applied.

Thanks,
Mathieu

Quoted 32 lines

---
v2:
- Changed "null" to "NULL"
- Added " pru:" prefix

---
 drivers/remoteproc/pru_rproc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/remoteproc/pru_rproc.c +2 -1
index 842e4b6cc5f9..5e3eb7b86a0e 100644
@@ -340,7 +340,7 @@ EXPORT_SYMBOL_GPL(pru_rproc_put);
  */
 int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
 {
-	struct pru_rproc *pru = rproc->priv;
+	struct pru_rproc *pru;
 	unsigned int reg;
 	u32 mask, set;
 	u16 idx;
@@ -352,6 +352,7 @@ int pru_rproc_set_ctable(struct rproc *rproc, enum pru_ctable_idx c, u32 addr)
 	if (!rproc->dev.parent || !is_pru_rproc(rproc->dev.parent))
 		return -ENODEV;
 
+	pru = rproc->priv;
 	/* pointer is 16 bit and index is 8-bit so mask out the rest */
 	idx_mask = (c >= PRU_C28) ? 0xFFFF : 0xFF;
 
Signature · 1 line
2.20.1