[dpdk-dev] eal: Fix resource leak of pci_uio_map_secondary()

Message ID 1465961172-28253-1-git-send-email-mukawa@igel.co.jp (mailing list archive)
State Changes Requested, archived
Headers

Commit Message

Tetsuya Mukawa June 15, 2016, 3:26 a.m. UTC
  If pci_map_resource() succeeds but mapped address is different from an
address primary process mapped, this should be error.
Then the address secondary process mapped should be freed.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/common/eal_common_pci_uio.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

David Marchand June 15, 2016, 2:45 p.m. UTC | #1
Hello Tetsuya,

On Wed, Jun 15, 2016 at 5:26 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
> If pci_map_resource() succeeds but mapped address is different from an
> address primary process mapped, this should be error.
> Then the address secondary process mapped should be freed.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>

The title should not contain the function name.


> ---
>  lib/librte_eal/common/eal_common_pci_uio.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
> index f062e81..e718643 100644
> --- a/lib/librte_eal/common/eal_common_pci_uio.c
> +++ b/lib/librte_eal/common/eal_common_pci_uio.c
> @@ -85,6 +85,9 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>                                         "Cannot mmap device resource file %s to address: %p\n",
>                                         uio_res->maps[i].path,
>                                         uio_res->maps[i].addr);
> +                               if (mapaddr != MAP_FAILED)
> +                                       pci_unmap_resource(mapaddr,
> +                                               (size_t)uio_res->maps[i].size);
>                                 return -1;
>                         }
>                 }

What of the previous mappings that might have succeeded earlier in this loop ?
  
Tetsuya Mukawa June 16, 2016, 2:03 a.m. UTC | #2
On 2016/06/15 23:45, David Marchand wrote:
> Hello Tetsuya,
> 
> On Wed, Jun 15, 2016 at 5:26 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>> If pci_map_resource() succeeds but mapped address is different from an
>> address primary process mapped, this should be error.
>> Then the address secondary process mapped should be freed.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> 
> The title should not contain the function name.

Hi David,

Thanks, I will change the title of all patches.

> 
> 
>> ---
>>  lib/librte_eal/common/eal_common_pci_uio.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
>> index f062e81..e718643 100644
>> --- a/lib/librte_eal/common/eal_common_pci_uio.c
>> +++ b/lib/librte_eal/common/eal_common_pci_uio.c
>> @@ -85,6 +85,9 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
>>                                         "Cannot mmap device resource file %s to address: %p\n",
>>                                         uio_res->maps[i].path,
>>                                         uio_res->maps[i].addr);
>> +                               if (mapaddr != MAP_FAILED)
>> +                                       pci_unmap_resource(mapaddr,
>> +                                               (size_t)uio_res->maps[i].size);
>>                                 return -1;
>>                         }
>>                 }
> 
> What of the previous mappings that might have succeeded earlier in this loop ?

I will unmap all addresses mapped before.

Thanks,
Tetsuya
  

Patch

diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
index f062e81..e718643 100644
--- a/lib/librte_eal/common/eal_common_pci_uio.c
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -85,6 +85,9 @@  pci_uio_map_secondary(struct rte_pci_device *dev)
 					"Cannot mmap device resource file %s to address: %p\n",
 					uio_res->maps[i].path,
 					uio_res->maps[i].addr);
+				if (mapaddr != MAP_FAILED)
+					pci_unmap_resource(mapaddr,
+						(size_t)uio_res->maps[i].size);
 				return -1;
 			}
 		}