linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftest: sync: Use common error handling code in sync_file_info()
@ 2017-11-20 21:25 SF Markus Elfring
  2017-11-21 15:46 ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: SF Markus Elfring @ 2017-11-20 21:25 UTC (permalink / raw)
  To: linux-kselftest, Emilio López, Shuah Khan; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 20 Nov 2017 22:20:37 +0100

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 tools/testing/selftests/sync/sync.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/sync/sync.c b/tools/testing/selftests/sync/sync.c
index f3d599f249b9..d0d55377f6f8 100644
--- a/tools/testing/selftests/sync/sync.c
+++ b/tools/testing/selftests/sync/sync.c
@@ -92,10 +92,8 @@ static struct sync_file_info *sync_file_info(int fd)
 		return NULL;
 
 	err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
-	if (err < 0) {
-		free(info);
-		return NULL;
-	}
+	if (err < 0)
+		goto free_info;
 
 	num_fences = info->num_fences;
 
@@ -104,22 +102,23 @@ static struct sync_file_info *sync_file_info(int fd)
 		info->num_fences = num_fences;
 
 		fence_info = calloc(num_fences, sizeof(*fence_info));
-		if (!fence_info) {
-			free(info);
-			return NULL;
-		}
+		if (!fence_info)
+			goto free_info;
 
 		info->sync_fence_info = (uint64_t)fence_info;
 
 		err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
 		if (err < 0) {
 			free(fence_info);
-			free(info);
-			return NULL;
+			goto free_info;
 		}
 	}
 
 	return info;
+
+free_info:
+	free(info);
+	return NULL;
 }
 
 static void sync_file_info_free(struct sync_file_info *info)
-- 
2.15.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftest: sync: Use common error handling code in sync_file_info()
  2017-11-20 21:25 [PATCH] selftest: sync: Use common error handling code in sync_file_info() SF Markus Elfring
@ 2017-11-21 15:46 ` Shuah Khan
  2017-11-21 18:55   ` SF Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2017-11-21 15:46 UTC (permalink / raw)
  To: SF Markus Elfring, linux-kselftest, Emilio López
  Cc: LKML, kernel-janitors, Shuah Khan, Shuah Khan

On 11/20/2017 02:25 PM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 20 Nov 2017 22:20:37 +0100
> 
> Add a jump target so that a bit of exception handling can be better reused
> at the end of this function.
> 
> This issue was detected by using the Coccinelle software.

I would like to see the Coccinelle log included in the commit log

> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  tools/testing/selftests/sync/sync.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/testing/selftests/sync/sync.c b/tools/testing/selftests/sync/sync.c
> index f3d599f249b9..d0d55377f6f8 100644
> --- a/tools/testing/selftests/sync/sync.c
> +++ b/tools/testing/selftests/sync/sync.c
> @@ -92,10 +92,8 @@ static struct sync_file_info *sync_file_info(int fd)
>  		return NULL;
>  
>  	err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
> -	if (err < 0) {
> -		free(info);
> -		return NULL;
> -	}
> +	if (err < 0)
> +		goto free_info;
>  
>  	num_fences = info->num_fences;
>  
> @@ -104,22 +102,23 @@ static struct sync_file_info *sync_file_info(int fd)
>  		info->num_fences = num_fences;
>  
>  		fence_info = calloc(num_fences, sizeof(*fence_info));
> -		if (!fence_info) {
> -			free(info);
> -			return NULL;
> -		}
> +		if (!fence_info)
> +			goto free_info;
>  
>  		info->sync_fence_info = (uint64_t)fence_info;
>  
>  		err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
>  		if (err < 0) {
>  			free(fence_info);

Why not add a free_fence_info to make it consistent?

> -			free(info);
> -			return NULL;
> +			goto free_info;
>  		}
>  	}
>  
>  	return info;
> +
> +free_info:
> +	free(info);
> +	return NULL;
>  }
>  
>  static void sync_file_info_free(struct sync_file_info *info)
> 

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftest: sync: Use common error handling code in sync_file_info()
  2017-11-21 15:46 ` Shuah Khan
@ 2017-11-21 18:55   ` SF Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-11-21 18:55 UTC (permalink / raw)
  To: shuah, linux-kselftest, Emilio López
  Cc: LKML, kernel-janitors, Shuah Khan

>> Add a jump target so that a bit of exception handling can be better reused
>> at the end of this function.
>>
>> This issue was detected by using the Coccinelle software.
> 
> I would like to see the Coccinelle log included in the commit log

I guess that I can not append the kind of report you might be looking for
so far. This small update suggestion is just another result from one
of my evolving scripts for the semantic patch language.

It was discussed under the topic “Comparing statement lists with SmPL”
to some degree.
https://systeme.lip6.fr/pipermail/cocci/2017-August/004388.html


>> @@ -104,22 +102,23 @@ static struct sync_file_info *sync_file_info(int fd)
>>  		info->num_fences = num_fences;
>>  
>>  		fence_info = calloc(num_fences, sizeof(*fence_info));
>> -		if (!fence_info) {
>> -			free(info);
>> -			return NULL;
>> -		}
>> +		if (!fence_info)
>> +			goto free_info;
>>  
>>  		info->sync_fence_info = (uint64_t)fence_info;
>>  
>>  		err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
>>  		if (err < 0) {
>>  			free(fence_info);
> 
> Why not add a free_fence_info to make it consistent?

It did not add another jump label because it would be used only once
for this if branch (according to your enquiry).


>> -			free(info);
>> -			return NULL;
>> +			goto free_info;

Do you expect a second update approach for this source code place?

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-21 18:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-20 21:25 [PATCH] selftest: sync: Use common error handling code in sync_file_info() SF Markus Elfring
2017-11-21 15:46 ` Shuah Khan
2017-11-21 18:55   ` SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).