[systemd-commits] 3 commits - src/libsystemd-terminal src/locale src/shared

David Herrmann dvdhrm at kemper.freedesktop.org
Mon Nov 3 23:28:38 PST 2014


 src/libsystemd-terminal/grdev-drm.c |    8 ++++----
 src/locale/localectl.c              |    2 +-
 src/shared/missing.h                |   11 +++++++++--
 src/shared/util.h                   |    9 +++++++++
 4 files changed, 23 insertions(+), 7 deletions(-)

New commits:
commit 44dd2c6e861316d26a78848eb0f6b35bd3b82d4b
Author: David Herrmann <dh.herrmann at gmail.com>
Date:   Mon Nov 3 18:23:28 2014 +0100

    util: introduce negative_errno()
    
    Imagine a constructor like this:
    
            int object_new(void **out) {
                    void *my_object;
                    int r;
    
                    ...
                    r = ioctl(...);
                    if (r < 0)
                            return -errno;
                    ...
    
                    *out = my_object;
                    return 0;
            }
    
    We have a lot of those in systemd. If you now call those, gcc might inline
    the call and optimize it. However, gcc cannot know that "errno" is
    negative if "r" is. Therefore, a caller like this will produce warnings:
    
            r = object_new(&obj);
            if (r < 0)
                    return r;
    
            obj->xyz = "foobar";
    
    In case the ioctl in the constructor fails, gcc might assume "errno" is 0
    and thus the error-handling is not triggered. Therefore, "obj" is
    uninitialized, but accessed. Gcc will warn about that.
    
    The new negative_errno() helper can be used to mitigate those warnings.
    The helper is guaranteed to return a negative integer. Furthermore, it
    spills out runtime warnings if "errno" is non-negative.
    
    Instead of returning "-errno", you can use:
            return negative_errno();
    
    gcc will no longer assume that this can return >=0, thus, it will not warn
    about it.
    
    Use this new helper in libsystemd-terminal to fix some grdev-drm warnings.

diff --git a/src/libsystemd-terminal/grdev-drm.c b/src/libsystemd-terminal/grdev-drm.c
index dba6db2..48f8e9c 100644
--- a/src/libsystemd-terminal/grdev-drm.c
+++ b/src/libsystemd-terminal/grdev-drm.c
@@ -1393,7 +1393,7 @@ static int grdrm_fb_new(grdrm_fb **out, grdrm_card *card, const struct drm_mode_
 
         r = ioctl(card->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
         if (r < 0) {
-                r = -errno;
+                r = negative_errno();
                 log_debug("grdrm: %s: cannot create dumb buffer %" PRIu32 "x%" PRIu32": %m",
                           card->base.name, fb->base.width, fb->base.height);
                 return r;
@@ -1407,7 +1407,7 @@ static int grdrm_fb_new(grdrm_fb **out, grdrm_card *card, const struct drm_mode_
 
         r = ioctl(card->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_dumb);
         if (r < 0) {
-                r = -errno;
+                r = negative_errno();
                 log_debug("grdrm: %s: cannot map dumb buffer %" PRIu32 "x%" PRIu32": %m",
                           card->base.name, fb->base.width, fb->base.height);
                 return r;
@@ -1415,7 +1415,7 @@ static int grdrm_fb_new(grdrm_fb **out, grdrm_card *card, const struct drm_mode_
 
         fb->base.maps[0] = mmap(0, fb->sizes[0], PROT_WRITE, MAP_SHARED, card->fd, map_dumb.offset);
         if (fb->base.maps[0] == MAP_FAILED) {
-                r = -errno;
+                r = negative_errno();
                 log_debug("grdrm: %s: cannot memory-map dumb buffer %" PRIu32 "x%" PRIu32": %m",
                           card->base.name, fb->base.width, fb->base.height);
                 return r;
@@ -1433,7 +1433,7 @@ static int grdrm_fb_new(grdrm_fb **out, grdrm_card *card, const struct drm_mode_
 
         r = ioctl(card->fd, DRM_IOCTL_MODE_ADDFB2, &add_fb);
         if (r < 0) {
-                r = -errno;
+                r = negative_errno();
                 log_debug("grdrm: %s: cannot add framebuffer %" PRIu32 "x%" PRIu32": %m",
                           card->base.name, fb->base.width, fb->base.height);
                 return r;
diff --git a/src/shared/util.h b/src/shared/util.h
index e405b02..af589b6 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -794,6 +794,15 @@ static inline void _reset_errno_(int *saved_errno) {
 
 #define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno
 
+static inline int negative_errno(void) {
+        /* This helper should be used to shut up gcc if you know 'errno' is
+         * negative. Instead of "return -errno;", use "return negative_errno();"
+         * It will suppress bogus gcc warnings in case it assumes 'errno' might
+         * be 0 and thus the caller's error-handling might not be triggered. */
+        assert_return(errno > 0, -EINVAL);
+        return -errno;
+}
+
 struct _umask_struct_ {
         mode_t mask;
         bool quit;

commit e6c019026b8cfd27a997e6e6ed1349f8f289b7e2
Author: Vicente Olivert Riera <Vincent.Riera at imgtec.com>
Date:   Mon Nov 3 14:48:35 2014 +0000

    Properly define the __NR_memfd_create macro for MIPS
    
    This macro exists for MIPS since v3.17:
      https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=42944521af97a3b25516f15f3149aec3779656dc

diff --git a/src/shared/missing.h b/src/shared/missing.h
index cc81c98..ecd32ba 100644
--- a/src/shared/missing.h
+++ b/src/shared/missing.h
@@ -126,8 +126,15 @@ static inline int pivot_root(const char *new_root, const char *put_old) {
 #  elif defined __arm__
 #    define __NR_memfd_create 385
 #  elif defined _MIPS_SIM
-#    warning "__NR_memfd_create not yet defined for MIPS"
-#    define __NR_memfd_create 0xffffffff
+#    if _MIPS_SIM == _MIPS_SIM_ABI32
+#      define __NR_memfd_create 4354
+#    endif
+#    if _MIPS_SIM == _MIPS_SIM_NABI32
+#      define __NR_memfd_create 6318
+#    endif
+#    if _MIPS_SIM == _MIPS_SIM_ABI64
+#      define __NR_memfd_create 5314
+#    endif
 #  else
 #    define __NR_memfd_create 356
 #  endif

commit 31cf921abbeafc9dae2d5c777f3e2285e6f4c19d
Author: Jan Synacek <jsynacek at redhat.com>
Date:   Mon Nov 3 14:01:04 2014 +0100

    localectl: fix localectl set-x11-keymap syntax description
    
    This complements the fix in:
    
        commit cd4c6fb12598435fe24431f1dd616f9582f0e3bd
        Author: Jan Synacek <jsynacek at redhat.com>
        Date:   Mon Oct 20 12:43:39 2014 +0200
    
            man: fix localectl set-x11-keymap syntax description

diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 3690f9f..d4a2d29 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -505,7 +505,7 @@ static void help(void) {
                "  list-locales             Show known locales\n"
                "  set-keymap MAP [MAP]     Set virtual console keyboard mapping\n"
                "  list-keymaps             Show known virtual console keyboard mappings\n"
-               "  set-x11-keymap LAYOUT [MODEL] [VARIANT] [OPTIONS]\n"
+               "  set-x11-keymap LAYOUT [MODEL [VARIANT [OPTIONS]]]\n"
                "                           Set X11 keyboard mapping\n"
                "  list-x11-keymap-models   Show known X11 keyboard mapping models\n"
                "  list-x11-keymap-layouts  Show known X11 keyboard mapping layouts\n"



More information about the systemd-commits mailing list