diff mbox series

[01/12] selftests: gpio-mockup-chardev: Check asprintf() for error

Message ID 20190114135144.26096-2-geert+renesas@glider.be (mailing list archive)
State New, archived
Headers show
Series selftests: Miscellaneous fixes | expand

Commit Message

Geert Uytterhoeven Jan. 14, 2019, 1:51 p.m. UTC
With gcc 7.3.0:

    gpio-mockup-chardev.c: In function ‘get_debugfs’:
    gpio-mockup-chardev.c:62:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
       asprintf(path, "%s/gpio", mnt_fs_get_target(fs));
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Handle asprintf() failures to fix this.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 tools/testing/selftests/gpio/gpio-mockup-chardev.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Shuah Jan. 16, 2019, 10:03 p.m. UTC | #1
On 1/14/19 6:51 AM, Geert Uytterhoeven wrote:
> With gcc 7.3.0:
> 
>      gpio-mockup-chardev.c: In function ‘get_debugfs’:
>      gpio-mockup-chardev.c:62:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
>         asprintf(path, "%s/gpio", mnt_fs_get_target(fs));
>         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Handle asprintf() failures to fix this.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
>   tools/testing/selftests/gpio/gpio-mockup-chardev.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/gpio/gpio-mockup-chardev.c b/tools/testing/selftests/gpio/gpio-mockup-chardev.c
> index f8d468f54e986dd0..aaa1e9f083c37215 100644
> --- a/tools/testing/selftests/gpio/gpio-mockup-chardev.c
> +++ b/tools/testing/selftests/gpio/gpio-mockup-chardev.c
> @@ -37,7 +37,7 @@ static int get_debugfs(char **path)
>   	struct libmnt_table *tb;
>   	struct libmnt_iter *itr = NULL;
>   	struct libmnt_fs *fs;
> -	int found = 0;
> +	int found = 0, ret;
>   
>   	cxt = mnt_new_context();
>   	if (!cxt)
> @@ -58,8 +58,11 @@ static int get_debugfs(char **path)
>   			break;
>   		}
>   	}
> -	if (found)
> -		asprintf(path, "%s/gpio", mnt_fs_get_target(fs));
> +	if (found) {
> +		ret = asprintf(path, "%s/gpio", mnt_fs_get_target(fs));
> +		if (ret < 0)
> +			err(EXIT_FAILURE, "failed to format string");
> +	}
>   
>   	mnt_free_iter(itr);
>   	mnt_free_context(cxt);
> 

Thanks for the patch. Applied to linux-kselftest fixes for 5.0-rc4

thanks,
-- Shuah
diff mbox series

Patch

diff --git a/tools/testing/selftests/gpio/gpio-mockup-chardev.c b/tools/testing/selftests/gpio/gpio-mockup-chardev.c
index f8d468f54e986dd0..aaa1e9f083c37215 100644
--- a/tools/testing/selftests/gpio/gpio-mockup-chardev.c
+++ b/tools/testing/selftests/gpio/gpio-mockup-chardev.c
@@ -37,7 +37,7 @@  static int get_debugfs(char **path)
 	struct libmnt_table *tb;
 	struct libmnt_iter *itr = NULL;
 	struct libmnt_fs *fs;
-	int found = 0;
+	int found = 0, ret;
 
 	cxt = mnt_new_context();
 	if (!cxt)
@@ -58,8 +58,11 @@  static int get_debugfs(char **path)
 			break;
 		}
 	}
-	if (found)
-		asprintf(path, "%s/gpio", mnt_fs_get_target(fs));
+	if (found) {
+		ret = asprintf(path, "%s/gpio", mnt_fs_get_target(fs));
+		if (ret < 0)
+			err(EXIT_FAILURE, "failed to format string");
+	}
 
 	mnt_free_iter(itr);
 	mnt_free_context(cxt);