You need to sign in or sign up before continuing.
  • Rand Deeb's avatar
    bcache: prevent potential division by zero error · 2c7f497a
    Rand Deeb authored
    
    
    In SHOW(), the variable 'n' is of type 'size_t.' While there is a
    conditional check to verify that 'n' is not equal to zero before
    executing the 'do_div' macro, concerns arise regarding potential
    division by zero error in 64-bit environments.
    
    The concern arises when 'n' is 64 bits in size, greater than zero, and
    the lower 32 bits of it are zeros. In such cases, the conditional check
    passes because 'n' is non-zero, but the 'do_div' macro casts 'n' to
    'uint32_t,' effectively truncating it to its lower 32 bits.
    Consequently, the 'n' value becomes zero.
    
    To fix this potential division by zero error and ensure precise
    division handling, this commit replaces the 'do_div' macro with
    div64_u64(). div64_u64() is designed to work with 64-bit operands,
    guaranteeing that division is performed correctly.
    
    This change enhances the robustness of the code, ensuring that division
    operations yield accurate results in all scenarios, eliminating the
    possibility of division by zero, and improving compatibility across
    different 64-bit environments.
    
    Found by Linux Verification Center (linuxtesting.org) with SVACE.
    Signed-off-by: default avatarRand Deeb <rand.sec96@gmail.com>
    Cc:  <stable@vger.kernel.org>
    Signed-off-by: default avatarColy Li <colyli@suse.de>
    Link: https://lore.kernel.org/r/20231120052503.6122-5-colyli@suse.de
    
    Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
    2c7f497a
sysfs.c 30.2 KB