• Nicolai Stange's avatar
    lib/mpi: mpi_read_raw_from_sgl(): don't include leading zero SGEs in nbytes · ab1e912e
    Nicolai Stange authored
    At the very beginning of mpi_read_raw_from_sgl(), the leading zeros of
    the input scatterlist are counted:
    
      lzeros = 0;
      for_each_sg(sgl, sg, ents, i) {
        ...
        if (/* sg contains nonzero bytes */)
          break;
    
        /* sg contains nothing but zeros here */
        ents--;
        lzeros = 0;
      }
    
    Later on, the total number of trailing nonzero bytes is calculated by
    subtracting the number of leading zero bytes from the total number of input
    bytes:
    
      nbytes -= lzeros;
    
    However, since lzeros gets reset to zero for each completely zero leading
    sg in the loop above, it doesn't include those.
    
    Besides wasting resources by allocating a too large output buffer,
    this mistake propagates into the calculation of x, the number of
    leading zeros within the most significant output limb:
    
      x = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
    
    What's more, the low order bytes of the output, equal in number to the
    extra bytes in nbytes, are left uninitialized.
    
    Fix this by adjusting nbytes for each completely zero leading scatterlist
    entry.
    
    Fixes: 2d4d1eea ("lib/mpi: Add mpi sgl helpers")
    Signed-off-by: default avatarNicolai Stange <nicstange@gmail.com>
    Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    ab1e912e
Name
Last commit
Last update
..
Makefile Loading commit data...
generic_mpih-add1.c Loading commit data...
generic_mpih-lshift.c Loading commit data...
generic_mpih-mul1.c Loading commit data...
generic_mpih-mul2.c Loading commit data...
generic_mpih-mul3.c Loading commit data...
generic_mpih-rshift.c Loading commit data...
generic_mpih-sub1.c Loading commit data...
longlong.h Loading commit data...
mpi-bit.c Loading commit data...
mpi-cmp.c Loading commit data...
mpi-inline.h Loading commit data...
mpi-internal.h Loading commit data...
mpi-pow.c Loading commit data...
mpicoder.c Loading commit data...
mpih-cmp.c Loading commit data...
mpih-div.c Loading commit data...
mpih-mul.c Loading commit data...
mpiutil.c Loading commit data...