Skip to contentSkip to conversation

ACPI/IORT: Switch to use kmemdup_array()

PATCH Applied Andy Shevchenko 4 participants 9 messages Jun 6, 2024 – Aug 16, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI/IORT: Switch to use kmemdup_array()

Let the kememdup_array() take care about multiplication and possible overflows.

---
 drivers/acpi/arm64/iort.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/arm64/iort.c +1 -1
index c0b1c2c19444..e596dff20f1e 100644
@@ -822,7 +822,7 @@ static struct iommu_iort_rmr_data *iort_rmr_alloc(
 		return NULL;
 
 	/* Create a copy of SIDs array to associate with this rmr_data */
-	sids_copy = kmemdup(sids, num_sids * sizeof(*sids), GFP_KERNEL);
+	sids_copy = kmemdup_array(sids, num_sids, sizeof(*sids), GFP_KERNEL);
 	if (!sids_copy) {
 		kfree(rmr_data);
 		return NULL;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Andy Shevchenko

Let the kememdup_array() take care about multiplication and possible overflows.

---
  drivers/acpi/arm64/iort.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/arm64/iort.c +0 -0
index c0b1c2c19444..e596dff20f1e 100644

drivers/acpi/arm64/iort.c static struct iommu_iort_rmr_data *iort_rmr_alloc( · line 828

Quoted 8 lines
drivers/acpi/arm64/iort.c +1 -1
@@ -822,7 +822,7 @@ static struct iommu_iort_rmr_data *iort_rmr_alloc(
  		return NULL;
 
  	/* Create a copy of SIDs array to associate with this rmr_data */
-	sids_copy = kmemdup(sids, num_sids * sizeof(*sids), GFP_KERNEL);
+	sids_copy = kmemdup_array(sids, num_sids, sizeof(*sids), GFP_KERNEL);
  	if (!sids_copy) {
  		kfree(rmr_data);
  		return NULL;

Looks good to me,

maintainer
#2 lore raw

+Cc Catalin

Quoted 25 lines · Hanjun Guo
Quoted 13 lines · Andy Shevchenko

Let the kememdup_array() take care about multiplication and possible overflows.

---
  drivers/acpi/arm64/iort.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/arm64/iort.c +0 -0
index c0b1c2c19444..e596dff20f1e 100644

drivers/acpi/arm64/iort.c static struct iommu_iort_rmr_data *iort_rmr_alloc( · line 828

Quoted 8 lines
drivers/acpi/arm64/iort.c +1 -1
@@ -822,7 +822,7 @@ static struct iommu_iort_rmr_data *iort_rmr_alloc(
           return NULL;
       /* Create a copy of SIDs array to associate with this rmr_data */
-    sids_copy = kmemdup(sids, num_sids * sizeof(*sids), GFP_KERNEL);
+    sids_copy = kmemdup_array(sids, num_sids, sizeof(*sids), 
 GFP_KERNEL);
       if (!sids_copy) {
           kfree(rmr_data);
           return NULL;

Looks good to me,

Quoted 1 line

Catalin, would you mind pick this up as well?

Thanks
Hanjun

#3 lore raw
Quoted 28 lines · Hanjun Guo

+Cc Catalin

Quoted 25 lines · Hanjun Guo
Quoted 13 lines · Andy Shevchenko

Let the kememdup_array() take care about multiplication and possible overflows.

---
  drivers/acpi/arm64/iort.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/arm64/iort.c +0 -0
index c0b1c2c19444..e596dff20f1e 100644

drivers/acpi/arm64/iort.c static struct iommu_iort_rmr_data *iort_rmr_alloc( · line 828

Quoted 8 lines
drivers/acpi/arm64/iort.c +1 -1
@@ -822,7 +822,7 @@ static struct iommu_iort_rmr_data *iort_rmr_alloc(
           return NULL;
       /* Create a copy of SIDs array to associate with this rmr_data */
-    sids_copy = kmemdup(sids, num_sids * sizeof(*sids), GFP_KERNEL);
+    sids_copy = kmemdup_array(sids, num_sids, sizeof(*sids),
 GFP_KERNEL);
       if (!sids_copy) {
           kfree(rmr_data);
           return NULL;

Looks good to me,

Quoted 3 lines
Quoted 1 line

Catalin, would you mind pick this up as well?

Any news?

I do not see this even in Linux Next...

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw
Quoted 29 lines · Andy Shevchenko
Quoted 28 lines · Hanjun Guo

+Cc Catalin

Quoted 25 lines · Hanjun Guo
Quoted 13 lines · Andy Shevchenko

Let the kememdup_array() take care about multiplication and possible overflows.

---
  drivers/acpi/arm64/iort.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/arm64/iort.c +0 -0
index c0b1c2c19444..e596dff20f1e 100644

drivers/acpi/arm64/iort.c static struct iommu_iort_rmr_data *iort_rmr_alloc( · line 828

Quoted 8 lines
drivers/acpi/arm64/iort.c +1 -1
@@ -822,7 +822,7 @@ static struct iommu_iort_rmr_data *iort_rmr_alloc(
           return NULL;
       /* Create a copy of SIDs array to associate with this rmr_data */
-    sids_copy = kmemdup(sids, num_sids * sizeof(*sids), GFP_KERNEL);
+    sids_copy = kmemdup_array(sids, num_sids, sizeof(*sids),
 GFP_KERNEL);
       if (!sids_copy) {
           kfree(rmr_data);
           return NULL;

Looks good to me,

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Catalin, would you mind pick this up as well?

Any news?

I do not see this even in Linux Next...

Ah, sorry, I missed this. Since it doesn't look like a fix, I guess it's fine to go in 6.12. Adding Will since he's handling the upcoming merging window.

Signature · 1 line
Catalin
maintainer
#5 lore raw
Quoted 34 lines · Catalin Marinas
Quoted 33 lines · Andy Shevchenko
Quoted 31 lines · Hanjun Guo

+Cc Catalin

Quoted 25 lines · Hanjun Guo
Quoted 13 lines · Andy Shevchenko

Let the kememdup_array() take care about multiplication and possible overflows.

---
   drivers/acpi/arm64/iort.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/arm64/iort.c +0 -0
index c0b1c2c19444..e596dff20f1e 100644

drivers/acpi/arm64/iort.c static struct iommu_iort_rmr_data *iort_rmr_alloc( · line 828

Quoted 8 lines
drivers/acpi/arm64/iort.c +1 -1
@@ -822,7 +822,7 @@ static struct iommu_iort_rmr_data *iort_rmr_alloc(
           return NULL;
       /* Create a copy of SIDs array to associate with this rmr_data */
-    sids_copy = kmemdup(sids, num_sids * sizeof(*sids), GFP_KERNEL);
+    sids_copy = kmemdup_array(sids, num_sids, sizeof(*sids),
 GFP_KERNEL);
       if (!sids_copy) {
           kfree(rmr_data);
           return NULL;

Looks good to me,

Quoted 1 line

Catalin, would you mind pick this up as well?

Quoted 7 lines
Quoted 3 lines

Any news?

I do not see this even in Linux Next...

Ah, sorry, I missed this. Since it doesn't look like a fix, I guess it's fine to go in 6.12. Adding Will since he's handling the upcoming merging window.

Sorry, I sent another email almost at the same time, so missed this one.

Thanks
Hanjun

#6 lore raw
In reply to Catalin Marinas
Quoted 1 line · Catalin Marinas

On Fri, Aug 09, 2024 at 03:16:34PM +0300, Andy Shevchenko wrote:

...

Quoted 2 lines

Ah, sorry, I missed this. Since it doesn't look like a fix, I guess it's fine to go in 6.12.

No, it's definitely not a fix, it's a simple cleanup. Hence v6.12 is quite okay, thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#7 lore raw
In reply to Andy Shevchenko
Quoted 29 lines · Andy Shevchenko
Quoted 28 lines · Hanjun Guo

+Cc Catalin

Quoted 25 lines · Hanjun Guo
Quoted 13 lines · Andy Shevchenko

Let the kememdup_array() take care about multiplication and possible overflows.

---
   drivers/acpi/arm64/iort.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/arm64/iort.c +0 -0
index c0b1c2c19444..e596dff20f1e 100644

drivers/acpi/arm64/iort.c static struct iommu_iort_rmr_data *iort_rmr_alloc( · line 828

Quoted 8 lines
drivers/acpi/arm64/iort.c +1 -1
@@ -822,7 +822,7 @@ static struct iommu_iort_rmr_data *iort_rmr_alloc(
           return NULL;
       /* Create a copy of SIDs array to associate with this rmr_data */
-    sids_copy = kmemdup(sids, num_sids * sizeof(*sids), GFP_KERNEL);
+    sids_copy = kmemdup_array(sids, num_sids, sizeof(*sids),
 GFP_KERNEL);
       if (!sids_copy) {
           kfree(rmr_data);
           return NULL;

Looks good to me,

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Catalin, would you mind pick this up as well?

Any news?

I do not see this even in Linux Next...

Sudeep, Lorenzo, would you mind giving it a go?

Thanks
Hanjun