[dpdk-dev,2/2] eal: fix not checking unlock result

Message ID 19c4033ae0d07a666f8142c8dd06b9ac0eb45af3.1523977960.git.anatoly.burakov@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Anatoly Burakov April 17, 2018, 3:42 p.m. UTC
  Coverity issue: 272607

Fixes: 66cc45e293ed ("mem: replace memseg with memseg lists")
Cc: anatoly.burakov@intel.com

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Comments

Jianfeng Tan April 25, 2018, 7:09 a.m. UTC | #1
On 4/17/2018 11:42 PM, Anatoly Burakov wrote:
> Coverity issue: 272607
>
> Fixes: 66cc45e293ed ("mem: replace memseg with memseg lists")
> Cc: anatoly.burakov@intel.com
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
>   lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
> index 009f963..01fee51 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
> @@ -304,8 +304,11 @@ clear_hugedir(const char * hugedir)
>   		/* if lock succeeds, unlock and remove the file */
>   		if (lck_result != -1) {
>   			lck.l_type = F_UNLCK;
> -			fcntl(fd, F_SETLK, &lck);
> -			unlinkat(dir_fd, dirent->d_name, 0);
> +			if (fcntl(fd, F_SETLK, &lck) < 0)
> +				RTE_LOG(ERR, EAL, "Couldn't unlock %s: %s\n",
> +					dirent->d_name, strerror(errno));

It seems that we shall return error if this nearly-impossible error 
happens, no?

> +			else
> +				unlinkat(dir_fd, dirent->d_name, 0);
>   		}
>   		close (fd);
>   		dirent = readdir(dir);
  
Anatoly Burakov April 25, 2018, 8:53 a.m. UTC | #2
On 25-Apr-18 8:09 AM, Tan, Jianfeng wrote:
> 
> 
> On 4/17/2018 11:42 PM, Anatoly Burakov wrote:
>> Coverity issue: 272607
>>
>> Fixes: 66cc45e293ed ("mem: replace memseg with memseg lists")
>> Cc: anatoly.burakov@intel.com
>>
>> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
>> ---
>>   lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 7 +++++--
>>   1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c 
>> b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
>> index 009f963..01fee51 100644
>> --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
>> +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
>> @@ -304,8 +304,11 @@ clear_hugedir(const char * hugedir)
>>           /* if lock succeeds, unlock and remove the file */
>>           if (lck_result != -1) {
>>               lck.l_type = F_UNLCK;
>> -            fcntl(fd, F_SETLK, &lck);
>> -            unlinkat(dir_fd, dirent->d_name, 0);
>> +            if (fcntl(fd, F_SETLK, &lck) < 0)
>> +                RTE_LOG(ERR, EAL, "Couldn't unlock %s: %s\n",
>> +                    dirent->d_name, strerror(errno));
> 
> It seems that we shall return error if this nearly-impossible error 
> happens, no?

I'm not sure if we should. In any case, lock will be dropped by close(), 
so the proper fix would've been just remove the fcntl() call altogether.

I'll respin.

> 
>> +            else
>> +                unlinkat(dir_fd, dirent->d_name, 0);
>>           }
>>           close (fd);
>>           dirent = readdir(dir);
> 
>
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
index 009f963..01fee51 100644
--- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
+++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
@@ -304,8 +304,11 @@  clear_hugedir(const char * hugedir)
 		/* if lock succeeds, unlock and remove the file */
 		if (lck_result != -1) {
 			lck.l_type = F_UNLCK;
-			fcntl(fd, F_SETLK, &lck);
-			unlinkat(dir_fd, dirent->d_name, 0);
+			if (fcntl(fd, F_SETLK, &lck) < 0)
+				RTE_LOG(ERR, EAL, "Couldn't unlock %s: %s\n",
+					dirent->d_name, strerror(errno));
+			else
+				unlinkat(dir_fd, dirent->d_name, 0);
 		}
 		close (fd);
 		dirent = readdir(dir);