Skip to contentSkip to conversation

util/error: Trivial cleanup

PATCH In review Philippe Mathieu-Daudé 3 participants 6 messages Mar 2, 2019 – Mar 4, 2019

lore
Share & tools
lore
#0 lore raw

cover util/error: Trivial cleanup

Trivial cleanups suggested by Daniel and Thomas.

Philippe Mathieu-Daudé (2):
util/error: Remove an unnecessary NULL check
util/error: Remove unnecessary saved_errno

 util/error.c | 7 -------
 1 file changed, 7 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 util/error: Remove an unnecessary NULL check

This NULL check was required while introduced in 680d16dcb79f. Later refactor added a NULL check in error_setv(), so this check is now redundant.

---
 util/error.c | 4 ----
 1 file changed, 4 deletions(-)
util/error.c +0 -4
index b5ccbd8eac..934a78e1b1 100644
@@ -103,10 +103,6 @@ void error_setg_errno_internal(Error **errp,
     va_list ap;
     int saved_errno = errno;
 
-    if (errp == NULL) {
-        return;
-    }
-
     va_start(ap, fmt);
     error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap,
                os_errno != 0 ? strerror(os_errno) : NULL);
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/2 util/error: Remove unnecessary saved_errno

In reply to Philippe Mathieu-Daudé

Since 552375088a8, error_set_errno() calls error_setv() which already protect errno for clobbering.
Remove the now unnecessary saved_errno.

---
 util/error.c | 3 ---
 1 file changed, 3 deletions(-)
util/error.c +0 -3
index 934a78e1b1..0402fa1b9d 100644
@@ -101,14 +101,11 @@ void error_setg_errno_internal(Error **errp,
                                int os_errno, const char *fmt, ...)
 {
     va_list ap;
-    int saved_errno = errno;
 
     va_start(ap, fmt);
     error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap,
                os_errno != 0 ? strerror(os_errno) : NULL);
     va_end(ap);
-
-    errno = saved_errno;
 }
 
 void error_setg_file_open_internal(Error **errp,
Signature · 1 line
2.20.1
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] util/error: Remove unnecessary saved_errno

Quoted 16 lines · Philippe Mathieu-Daudé

Since 552375088a8, error_set_errno() calls error_setv() which already protect errno for clobbering.
Remove the now unnecessary saved_errno.

---
 util/error.c | 3 ---
 1 file changed, 3 deletions(-)
util/error.c +0 -0
index 934a78e1b1..0402fa1b9d 100644
@@ -101,14 +101,11 @@ void error_setg_errno_internal(Error **errp,
                                int os_errno, const char *fmt, ...)

util/error.c void error_setg_errno_internal(Error **errp, · line 111

Quoted 10 lines
util/error.c +0 -3
 {
     va_list ap;
-    int saved_errno = errno;
 
     va_start(ap, fmt);
     error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap,
                os_errno != 0 ? strerror(os_errno) : NULL);
     va_end(ap);
-
-    errno = saved_errno;

NACK. strerror() can clobber errno, so you still need to restore saved_errno, regardless of what error_setv() does internally.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] util/error: Remove unnecessary saved_errno

Quoted 21 lines · Eric Blake
Quoted 20 lines · Philippe Mathieu-Daudé

Since 552375088a8, error_set_errno() calls error_setv() which already protect errno for clobbering.
Remove the now unnecessary saved_errno.

---
 util/error.c | 3 ---
 1 file changed, 3 deletions(-)
util/error.c +0 -1
index 934a78e1b1..0402fa1b9d 100644
@@ -101,14 +101,11 @@ void error_setg_errno_internal(Error **errp,
                                int os_errno, const char *fmt, ...)
 {
     va_list ap;
-    int saved_errno = errno;
 
Quoted 9 lines

util/error.c void error_setg_errno_internal(Error **errp, · line 111

Quoted 6 lines
util/error.c +0 -2
     va_start(ap, fmt);
     error_setv(errp, src, line, func, ERROR_CLASS_GENERIC_ERROR, fmt, ap,
                os_errno != 0 ? strerror(os_errno) : NULL);
     va_end(ap);
-
-    errno = saved_errno;

NACK. strerror() can clobber errno, so you still need to restore saved_errno, regardless of what error_setv() does internally.

Oops, I thought only strerror_r() would change errno, but checking the man page I now see you are right:

POSIX.1-2001 and POSIX.1-2008 require that a successful call to strerror() or strerror_l() shall leave errno unchanged, and note that, since no function return value is reserved to indicate an error, an application that wishes to check for errors should initialize errno to zero before the call, and then check errno after the call.

Thanks for catching that!

Phil.

#5 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé

Trivial cleanups suggested by Daniel and Thomas.

Philippe Mathieu-Daudé (2):
util/error: Remove an unnecessary NULL check
util/error: Remove unnecessary saved_errno

Queuing PATCH 1/2, thanks!