• Herbert Xu's avatar
    crypto: api - Retain alg refcount in crypto_grab_spawn · 5f567fff
    Herbert Xu authored
    This patch changes crypto_grab_spawn to retain the reference count
    on the algorithm.  This is because the caller needs to access the
    algorithm parameters and without the reference count the algorithm
    can be freed at any time.
    
    The reference count will be subsequently dropped by the crypto API
    once the instance has been registered.  The helper crypto_drop_spawn
    will also conditionally drop the reference count depending on whether
    it has been registered.
    
    Note that the code is actually added to crypto_init_spawn.  However,
    unless the caller activates this by setting spawn->dropref beforehand
    then nothing happens.  The only caller that sets dropref is currently
    crypto_grab_spawn.
    
    Once all legacy users of crypto_init_spawn disappear, then we can
    kill the dropref flag.
    
    Internally each instance will maintain a list of its spawns prior
    to registration.  This memory used by this list is shared with
    other fields that are only used after registration.  In order for
    this to work a new flag spawn->registered is added to indicate
    whether spawn->inst can be used.
    
    Fixes: d6ef2f19 ("crypto: api - Add crypto_grab_spawn primitive")
    Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    5f567fff
algapi.c 29.6 KB