mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] commands: don't use stale errno when calling fb_open
@ 2019-06-03 19:05 Ahmad Fatoum
  2019-06-03 19:20 ` Andrey Smirnov
  2019-06-04  8:08 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2019-06-03 19:05 UTC (permalink / raw)
  To: barebox

fb_open returns a pointer and doesn't populate errno, which will
results in a stale errno being evaluated by perror() on failure.
Fix this by populating errno manually at call sites.

While at it, correct the typo in the prefix passed to perror().

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/fbtest.c | 5 +++--
 commands/splash.c | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/commands/fbtest.c b/commands/fbtest.c
index e5dd8ba7fabf..2c589f77d3b8 100644
--- a/commands/fbtest.c
+++ b/commands/fbtest.c
@@ -271,8 +271,9 @@ static int do_fbtest(int argc, char *argv[])
 
 	sc = fb_open(fbdev);
 	if (IS_ERR(sc)) {
-		perror("fd_open");
-		return PTR_ERR(sc);
+		errno = PTR_ERR(sc);
+		perror("fb_open");
+		return errno;
 	}
 
 	if (!pattern_name) {
diff --git a/commands/splash.c b/commands/splash.c
index 2b70b296837e..75b3ee3fadaf 100644
--- a/commands/splash.c
+++ b/commands/splash.c
@@ -54,8 +54,9 @@ static int do_splash(int argc, char *argv[])
 
 	sc = fb_open(fbdev);
 	if (IS_ERR(sc)) {
-		perror("fd_open");
-		return PTR_ERR(sc);
+		errno = PTR_ERR(sc);
+		perror("fb_open");
+		return errno;
 	}
 
 	buf = gui_screen_render_buffer(sc);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] commands: don't use stale errno when calling fb_open
  2019-06-03 19:05 [PATCH] commands: don't use stale errno when calling fb_open Ahmad Fatoum
@ 2019-06-03 19:20 ` Andrey Smirnov
  2019-06-04  8:08 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Andrey Smirnov @ 2019-06-03 19:20 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: Barebox List

On Mon, Jun 3, 2019 at 12:05 PM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
>
> fb_open returns a pointer and doesn't populate errno, which will
> results in a stale errno being evaluated by perror() on failure.
> Fix this by populating errno manually at call sites.
>

Why not just convert the code to use strerror() instead? Seems a bit
more straightforward plus changing errno outside of our "POSIX/C"
layer seems a bit out of place. Not a big deal though.

Thanks,
Andrey Smirnov

> While at it, correct the typo in the prefix passed to perror().
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  commands/fbtest.c | 5 +++--
>  commands/splash.c | 5 +++--
>  2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/commands/fbtest.c b/commands/fbtest.c
> index e5dd8ba7fabf..2c589f77d3b8 100644
> --- a/commands/fbtest.c
> +++ b/commands/fbtest.c
> @@ -271,8 +271,9 @@ static int do_fbtest(int argc, char *argv[])
>
>         sc = fb_open(fbdev);
>         if (IS_ERR(sc)) {
> -               perror("fd_open");
> -               return PTR_ERR(sc);
> +               errno = PTR_ERR(sc);
> +               perror("fb_open");
> +               return errno;
>         }
>
>         if (!pattern_name) {
> diff --git a/commands/splash.c b/commands/splash.c
> index 2b70b296837e..75b3ee3fadaf 100644
> --- a/commands/splash.c
> +++ b/commands/splash.c
> @@ -54,8 +54,9 @@ static int do_splash(int argc, char *argv[])
>
>         sc = fb_open(fbdev);
>         if (IS_ERR(sc)) {
> -               perror("fd_open");
> -               return PTR_ERR(sc);
> +               errno = PTR_ERR(sc);
> +               perror("fb_open");
> +               return errno;
>         }
>
>         buf = gui_screen_render_buffer(sc);
> --
> 2.20.1
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] commands: don't use stale errno when calling fb_open
  2019-06-03 19:05 [PATCH] commands: don't use stale errno when calling fb_open Ahmad Fatoum
  2019-06-03 19:20 ` Andrey Smirnov
@ 2019-06-04  8:08 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2019-06-04  8:08 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Jun 03, 2019 at 09:05:35PM +0200, Ahmad Fatoum wrote:
> fb_open returns a pointer and doesn't populate errno, which will
> results in a stale errno being evaluated by perror() on failure.
> Fix this by populating errno manually at call sites.
> 
> While at it, correct the typo in the prefix passed to perror().
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  commands/fbtest.c | 5 +++--
>  commands/splash.c | 5 +++--
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/commands/fbtest.c b/commands/fbtest.c
> index e5dd8ba7fabf..2c589f77d3b8 100644
> --- a/commands/fbtest.c
> +++ b/commands/fbtest.c
> @@ -271,8 +271,9 @@ static int do_fbtest(int argc, char *argv[])
>  
>  	sc = fb_open(fbdev);
>  	if (IS_ERR(sc)) {
> -		perror("fd_open");
> -		return PTR_ERR(sc);
> +		errno = PTR_ERR(sc);
> +		perror("fb_open");
> +		return errno;
>  	}

I would also prefer a printf() message along with a strerror(). Setting
a global variable when the result is only used in this function looks
odd.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2019-06-04  8:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-03 19:05 [PATCH] commands: don't use stale errno when calling fb_open Ahmad Fatoum
2019-06-03 19:20 ` Andrey Smirnov
2019-06-04  8:08 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox