2024-06-06 20:51:48

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 1/1] ACPI/IORT: Switch to use kmemdup_array()

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

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/acpi/arm64/iort.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index c0b1c2c19444..e596dff20f1e 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -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;
--
2.43.0.rc1.1336.g36b5255a03ac



2024-06-11 10:43:25

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v1 1/1] ACPI/IORT: Switch to use kmemdup_array()

On 2024/6/7 0:50, Andy Shevchenko wrote:
> Let the kememdup_array() take care about multiplication and possible
> overflows.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
> drivers/acpi/arm64/iort.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> index c0b1c2c19444..e596dff20f1e 100644
> --- a/drivers/acpi/arm64/iort.c
> +++ b/drivers/acpi/arm64/iort.c
> @@ -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,

Acked-by: Hanjun Guo <[email protected]>

2024-06-14 00:54:59

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v1 1/1] ACPI/IORT: Switch to use kmemdup_array()

+Cc Catalin

On 2024/6/11 18:42, Hanjun Guo wrote:
> On 2024/6/7 0:50, Andy Shevchenko wrote:
>> Let the kememdup_array() take care about multiplication and possible
>> overflows.
>>
>> Signed-off-by: Andy Shevchenko <[email protected]>
>> ---
>>   drivers/acpi/arm64/iort.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
>> index c0b1c2c19444..e596dff20f1e 100644
>> --- a/drivers/acpi/arm64/iort.c
>> +++ b/drivers/acpi/arm64/iort.c
>> @@ -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,
>
> Acked-by: Hanjun Guo <[email protected]>

Catalin, would you mind pick this up as well?

Thanks
Hanjun