Skip to contentSkip to conversation

ntb_tool: check null return of devm_kcalloc in tool_init_mws

PATCH Superseded Kang Chen 3 participants 7 messages Feb 26, 2023 – Mar 7, 2023 NTB driver core

lore
Share & tools
lore

Kang Chen

author
#0 lore raw

PATCH 1/1 ntb_tool: check null return of devm_kcalloc in tool_init_mws

devm_kcalloc may fails, tc->peers[pidx].outmws might be null and will cause null pointer dereference later.

---
 drivers/ntb/test/ntb_tool.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/ntb/test/ntb_tool.c +2 -0
index 5ee0afa62..eeeb4b1c9 100644
@@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
 		tc->peers[pidx].outmws =
 			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
 				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
+		if (tc->peers[pidx].outmws == NULL)
+			return -ENOMEM;
 
 		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
 			tc->peers[pidx].outmws[widx].pidx = pidx;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Kang Chen

devm_kcalloc may fails, tc->peers[pidx].outmws might be null and will cause null pointer dereference later.

Quoted 17 lines
---
  drivers/ntb/test/ntb_tool.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/ntb/test/ntb_tool.c +2 -0
index 5ee0afa62..eeeb4b1c9 100644
@@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
  		tc->peers[pidx].outmws =
  			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
  				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
+		if (tc->peers[pidx].outmws == NULL)
+			return -ENOMEM;
 
  		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
  			tc->peers[pidx].outmws[widx].pidx = pidx;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Kang Chen
Quoted 4 lines · Kang Chen

devm_kcalloc may fails, tc->peers[pidx].outmws might be null and will cause null pointer dereference later.

Please add the fixes tag:

Fixes 7f46c8b3a552 ("NTB: ntb_tool: Add full multi-port NTB API support")

so the patch could be noticeable by the stable kernel maintainers.

Other than that looks good.

* Please don't forget to add the Rb-tags on v2.

-Serge(y)

Quoted 21 lines
---
 drivers/ntb/test/ntb_tool.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/ntb/test/ntb_tool.c +2 -0
index 5ee0afa62..eeeb4b1c9 100644
@@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
 		tc->peers[pidx].outmws =
 			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
 				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
+		if (tc->peers[pidx].outmws == NULL)
+			return -ENOMEM;
 
 		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
 			tc->peers[pidx].outmws[widx].pidx = pidx;
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v2 1/1 ntb_tool: check null return of devm_kcalloc in tool_init_mws

devm_kcalloc may fails, tc->peers[pidx].outmws might be null and will cause null pointer dereference later.

Fixes 7f46c8b3a552 ("NTB: ntb_tool: Add full multi-port NTB API support")

---
v2 -> v1: add Fixes and Reviewed-by tags

 drivers/ntb/test/ntb_tool.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/ntb/test/ntb_tool.c +2 -0
index 5ee0afa62..eeeb4b1c9 100644
@@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
 		tc->peers[pidx].outmws =
 			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
 				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
+		if (tc->peers[pidx].outmws == NULL)
+			return -ENOMEM;
 
 		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
 			tc->peers[pidx].outmws[widx].pidx = pidx;
Signature · 1 line
2.34.1
maintainer
#4 lore raw
Quoted 6 lines · Kang Chen

devm_kcalloc may fails, tc->peers[pidx].outmws might be null and will cause null pointer dereference later.

Fixes 7f46c8b3a552 ("NTB: ntb_tool: Add full multi-port NTB API support")

You forgot to pick up my review tag. I do recommend using the tool 'b4'. It picks up all the tags for you and works rather well.

Quoted 19 lines

---
v2 -> v1: add Fixes and Reviewed-by tags

  drivers/ntb/test/ntb_tool.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/ntb/test/ntb_tool.c +2 -0
index 5ee0afa62..eeeb4b1c9 100644
@@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
  		tc->peers[pidx].outmws =
  			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
  				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
+		if (tc->peers[pidx].outmws == NULL)
+			return -ENOMEM;
 
  		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
  			tc->peers[pidx].outmws[widx].pidx = pidx;
author
#5 lore raw

What a cool tool, thanks for your suggestions.

Quoted 33 lines · Dave Jiang
Quoted 6 lines · Kang Chen

devm_kcalloc may fails, tc->peers[pidx].outmws might be null and will cause null pointer dereference later.

Fixes 7f46c8b3a552 ("NTB: ntb_tool: Add full multi-port NTB API support")

You forgot to pick up my review tag. I do recommend using the tool 'b4'. It picks up all the tags for you and works rather well.

Quoted 19 lines

---
v2 -> v1: add Fixes and Reviewed-by tags

  drivers/ntb/test/ntb_tool.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/ntb/test/ntb_tool.c +2 -0
index 5ee0afa62..eeeb4b1c9 100644
@@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
              tc->peers[pidx].outmws =
                      devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
                                 sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
+             if (tc->peers[pidx].outmws == NULL)
+                     return -ENOMEM;
 
              for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
                      tc->peers[pidx].outmws[widx].pidx = pidx;
author
#6 lore raw

PATCH v3 1/1 ntb_tool: check null return of devm_kcalloc in tool_init_mws

From: Kang Chen <[email protected]>

devm_kcalloc may fails, tc->peers[pidx].outmws might be null and will cause null pointer dereference later.

Fixes 7f46c8b3a552 ("NTB: ntb_tool: Add full multi-port NTB API support")

---
v3 -> v2: add Reviewed-by tag
v2 -> v1: add Fixes and Reviewed-by tags

 drivers/ntb/test/ntb_tool.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/ntb/test/ntb_tool.c +2 -0
index 5ee0afa62..eeeb4b1c9 100644
@@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
 		tc->peers[pidx].outmws =
 			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
 				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
+		if (tc->peers[pidx].outmws == NULL)
+			return -ENOMEM;
 
 		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
 			tc->peers[pidx].outmws[widx].pidx = pidx;
Signature · 1 line
2.34.1