Skip to content

Commit

Permalink
can: j1939: warn if resources are still linked on destroy
Browse files Browse the repository at this point in the history
j1939_session_destroy() and __j1939_priv_release() should be called only
if session, ecu or socket are not linked or used by any one else. If at
least one of these resources is linked, then the reference counting is
broken somewhere.

This warning will be triggered before KASAN will do, and will make it
easier to debug initial issue. This works on platforms without KASAN
support.

Signed-off-by: Oleksij Rempel <[email protected]>
  • Loading branch information
olerem authored and marckleinebudde committed Nov 13, 2019
1 parent ddeeb7d commit 4a15d57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions net/can/j1939/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ static void __j1939_priv_release(struct kref *kref)

netdev_dbg(priv->ndev, "%s: 0x%p\n", __func__, priv);

WARN_ON_ONCE(!list_empty(&priv->active_session_list));
WARN_ON_ONCE(!list_empty(&priv->ecus));
WARN_ON_ONCE(!list_empty(&priv->j1939_socks));

dev_put(ndev);
kfree(priv);
}
Expand Down
3 changes: 3 additions & 0 deletions net/can/j1939/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ static void j1939_session_destroy(struct j1939_session *session)

netdev_dbg(session->priv->ndev, "%s: 0x%p\n", __func__, session);

WARN_ON_ONCE(!list_empty(&session->sk_session_queue_entry));
WARN_ON_ONCE(!list_empty(&session->active_session_list_entry));

skb_queue_purge(&session->skb_queue);
__j1939_session_drop(session);
j1939_priv_put(session->priv);
Expand Down

0 comments on commit 4a15d57

Please sign in to comment.