OSDN Git Service

bridge: Fix error path for kobject_init_and_add()
authorTobin C. Harding <tobin@kernel.org>
Fri, 10 May 2019 02:52:12 +0000 (12:52 +1000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 10 May 2019 22:05:08 +0000 (15:05 -0700)
commitbdfad5aec1392b93495b77b864d58d7f101dc1c1
tree80b4f8a200754f34129e8c2ac6f409fcb1ae56e5
parente711ab936a44ee9f63f1746c09029543f1b29dd2
bridge: Fix error path for kobject_init_and_add()

Currently error return from kobject_init_and_add() is not followed by a
call to kobject_put().  This means there is a memory leak.  We currently
set p to NULL so that kfree() may be called on it as a noop, the code is
arguably clearer if we move the kfree() up closer to where it is
called (instead of after goto jump).

Remove a goto label 'err1' and jump to call to kobject_put() in error
return from kobject_init_and_add() fixing the memory leak.  Re-name goto
label 'put_back' to 'err1' now that we don't use err1, following current
nomenclature (err1, err2 ...).  Move call to kfree out of the error
code at bottom of function up to closer to where memory was allocated.
Add comment to clarify call to kfree().

Signed-off-by: Tobin C. Harding <tobin@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/bridge/br_if.c