can: j1939: warn if resources are still linked on destroy
authorOleksij Rempel <o.rempel@pengutronix.de>
Fri, 8 Nov 2019 12:57:14 +0000 (13:57 +0100)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 13 Nov 2019 09:42:34 +0000 (10:42 +0100)
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 <o.rempel@pengutronix.de>
net/can/j1939/main.c
net/can/j1939/transport.c

index 2afcf27c72c83bb370089f0551ed808ced6c828b..137054bff9ec72b4bc4795b3446ff853ae1c6f13 100644 (file)
@@ -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);
 }
index 0c62b8fc4b20cc00d9c0d65b376e723fcc8ae4ba..9f99af5b0b11e74b7718be8fa3300e01fc36a4dc 100644 (file)
@@ -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);