Skip to contentSkip to conversation

cxl/hdm: Fix potential infinite loop in __cxl_dpa_reserve()

PATCH Applied Li Ming 4 participants 5 messages Jan 12 CXL

lore
Share & tools
lore

Li Ming

author reviewer
#0 lore raw

PATCH 1/1 cxl/hdm: Fix potential infinite loop in __cxl_dpa_reserve()

In __cxl_dpa_reserve(), it will check if the new resource range is included in one of paritions of the cxl memory device. cxlds->nr_paritions is used to represent how many partitions information the cxl memory device has. In the loop, if driver cannot find a partition including the new resource range, it will be an infinite loop.

Fixes be5cbd084027 ("cxl: Kill enum cxl_decoder_mode")
---
 drivers/cxl/core/hdm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/hdm.c +1 -1
index 1c5d2022c87a..a470099a69f1 100644
@@ -403,7 +403,7 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
 	 * is not set.
 	 */
 	if (cxled->part < 0)
-		for (int i = 0; cxlds->nr_partitions; i++)
+		for (int i = 0; i < cxlds->nr_partitions; i++)
 			if (resource_contains(&cxlds->part[i].res, res)) {
 				cxled->part = i;
 				break;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Li Ming

In __cxl_dpa_reserve(), it will check if the new resource range is included in one of paritions of the cxl memory device. cxlds->nr_paritions is used to represent how many partitions information the cxl memory device has. In the loop, if driver cannot find a partition including the new resource range, it will be an infinite loop.

Fixes be5cbd084027 ("cxl: Kill enum cxl_decoder_mode")
Quoted 17 lines
---
 drivers/cxl/core/hdm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/hdm.c +1 -1
index 1c5d2022c87a..a470099a69f1 100644
@@ -403,7 +403,7 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
 	 * is not set.
 	 */
 	if (cxled->part < 0)
-		for (int i = 0; cxlds->nr_partitions; i++)
+		for (int i = 0; i < cxlds->nr_partitions; i++)
 			if (resource_contains(&cxlds->part[i].res, res)) {
 				cxled->part = i;
 				break;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Li Ming
Quoted 7 lines · Li Ming

In __cxl_dpa_reserve(), it will check if the new resource range is included in one of paritions of the cxl memory device. cxlds->nr_paritions is used to represent how many partitions information the cxl memory device has. In the loop, if driver cannot find a partition including the new resource range, it will be an infinite loop.

Fixes be5cbd084027 ("cxl: Kill enum cxl_decoder_mode")

Technically the bug was introduced in:

Fixes 991d98f17d31 ("cxl: Make cxl_dpa_alloc() DPA partition number agnostic")

With that,

[snip]

maintainer Applied
#3 lore raw
In reply to Li Ming
Quoted 8 lines · Li Ming

In __cxl_dpa_reserve(), it will check if the new resource range is included in one of paritions of the cxl memory device. cxlds->nr_paritions is used to represent how many partitions information the cxl memory device has. In the loop, if driver cannot find a partition including the new resource range, it will be an infinite loop.

Fixes be5cbd084027 ("cxl: Kill enum cxl_decoder_mode")

Applied to cxl/fixes with Fixes tag fixed
d4026a44626490dc4eca4dd2c4d0816338fa179b

Quoted 17 lines
---
 drivers/cxl/core/hdm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/hdm.c +1 -1
index 1c5d2022c87a..a470099a69f1 100644
@@ -403,7 +403,7 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
 	 * is not set.
 	 */
 	if (cxled->part < 0)
-		for (int i = 0; cxlds->nr_partitions; i++)
+		for (int i = 0; i < cxlds->nr_partitions; i++)
 			if (resource_contains(&cxlds->part[i].res, res)) {
 				cxled->part = i;
 				break;
#4 lore raw
Quoted 3 lines
Quoted 3 lines

In __cxl_dpa_reserve(), it will check if the new resource range is included in one of paritions of the cxl memory device. cxlds->nr_paritions is used to represent how many partitions information

…

How do you think about to avoid typos in such a change description?

Quoted 2 lines

Applied to cxl/fixes with Fixes tag fixed
d4026a44626490dc4eca4dd2c4d0816338fa179b

Is this adjustment still improvable?

Regards,
Markus