• Arnd Bergmann's avatar
    rbd: avoid clang -Wuninitialized warning · d342a15b
    Arnd Bergmann authored
    clang fails to see that rbd_assert(0) ends in an unreachable code
    path and warns about a subsequent use of an uninitialized variable
    when CONFIG_PROFILE_ANNOTATED_BRANCHES is set:
    
    drivers/block/rbd.c:2402:4: error: variable 'ret' is used uninitialized whenever 'if' condition is false
          [-Werror,-Wsometimes-uninitialized]
                            rbd_assert(0);
                            ^~~~~~~~~~~~~
    drivers/block/rbd.c:563:7: note: expanded from macro 'rbd_assert'
                    if (unlikely(!(expr))) {                                \
                        ^~~~~~~~~~~~~~~~~
    include/linux/compiler.h:48:23: note: expanded from macro 'unlikely'
     #  define unlikely(x)   (__branch_check__(x, 0, __builtin_constant_p(x)))
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/block/rbd.c:2410:6: note: uninitialized use occurs here
            if (ret) {
                ^~~
    drivers/block/rbd.c:2402:4: note: remove the 'if' if its condition is always true
                            rbd_assert(0);
                            ^
    drivers/block/rbd.c:563:3: note: expanded from macro 'rbd_assert'
                    if (unlikely(!(expr))) {                                \
                    ^
    drivers/block/rbd.c:2376:9: note: initialize the variable 'ret' to silence this warning
            int ret;
                   ^
                    = 0
    1 error generated.
    
    This seems to be a bug in clang, but is easy to work around by using
    an unconditional BUG().
    Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
    Reviewed-by: default avatarIlya Dryomov <idryomov@gmail.com>
    Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
    d342a15b
rbd.c 160 KB