batman-adv: Check ptr for NULL before reducing its refcnt
commit 6340dcbd619450c1bb55eb999e554e4f0e6dab0a upstream. The commit b37a46683739 ("netdevice: add the case if dev is NULL") changed the way how the NULL check for net_devices have to be handled when trying to reduce its reference counter. Before this commit, it was the responsibility of the caller to check whether the object is NULL or not. But it was changed to behave more like kfree. Now the callee has to handle the NULL-case. The batman-adv code was scanned via cocinelle for similar places. These were changed to use the paradigm @@ identifier E, T, R, C; identifier put; @@ void put(struct T *E) { + if (!E) + return; kref_put(&E->C, R); } Functions which were used in other sources files were moved to the header to allow the compiler to inline the NULL check and the kref_put call. Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
f6da750bfa
commit
73f7cbb151
@@ -222,6 +222,9 @@ static void batadv_nc_node_release(struct kref *ref)
|
||||
*/
|
||||
static void batadv_nc_node_put(struct batadv_nc_node *nc_node)
|
||||
{
|
||||
if (!nc_node)
|
||||
return;
|
||||
|
||||
kref_put(&nc_node->refcount, batadv_nc_node_release);
|
||||
}
|
||||
|
||||
@@ -246,6 +249,9 @@ static void batadv_nc_path_release(struct kref *ref)
|
||||
*/
|
||||
static void batadv_nc_path_put(struct batadv_nc_path *nc_path)
|
||||
{
|
||||
if (!nc_path)
|
||||
return;
|
||||
|
||||
kref_put(&nc_path->refcount, batadv_nc_path_release);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user