• NeilBrown's avatar
    seq_file: document how per-entry resources are managed. · b3656d82
    NeilBrown authored
    Patch series "Fix some seq_file users that were recently broken".
    
    A recent change to seq_file broke some users which were using seq_file
    in a non-"standard" way ...  though the "standard" isn't documented, so
    they can be excused.  The result is a possible leak - of memory in one
    case, of references to a 'transport' in the other.
    
    These three patches:
     1/ document and explain the problem
     2/ fix the problem user in x86
     3/ fix the problem user in net/sctp
    
    This patch (of 3):
    
    Users of seq_file will sometimes find it convenient to take a resource,
    such as a lock or memory allocation, in the ->start or ->next operations.
    These are per-entry resources, distinct from per-session resources which
    are taken in ->start and released in ->stop.
    
    The preferred management of these is release the resource on the
    subsequent call to ->next or ->stop.
    
    However prior to Commit 1f4aace6 ("fs/seq_file.c: simplify seq_file
    iteration code and interface") it happened that ->show would always be
    called after ->start or ->next, and a few users chose to release the
    resource in ->show.
    
    This is no longer reliable.  Since the mentioned commit, ->next will
    always come after a successful ->show (to ensure m->index is updated
    correctly), so the original ordering cannot be maintained.
    
    This patch updates the documentation to clearly state the required
    behaviour.  Other patches will fix the few problematic users.
    
    [akpm@linux-foundation.org: fix typo, per Willy]
    
    Link: https://lkml.kernel.org/r/161248518659.21478.2484341937387294998.stgit@noble1
    Link: https://lkml.kernel.org/r/161248539020.21478.3147971477400875336.stgit@noble1
    Fixes: 1f4aace6 ("fs/seq_file.c: simplify seq_file iteration code and interface")
    Signed-off-by: default avatarNeilBrown <neilb@suse.de>
    Cc: Xin Long <lucien.xin@gmail.com>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Vlad Yasevich <vyasevich@gmail.com>
    Cc: Neil Horman <nhorman@tuxdriver.com>
    Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
    Cc: "David S. Miller" <davem@davemloft.net>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    b3656d82
seq_file.rst 16 KB