net: mvneta: fix potential double-frees in mvneta_txq_sw_deinit()
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Wed, 29 Mar 2023 12:11:17 +0000 (13:11 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 30 Mar 2023 18:43:39 +0000 (11:43 -0700)
commit2960a2d33b02345c6d710251206053678f92246b
tree6d407301b412641077b17aa457585c95bf7e2ee8
parent64fdc5f341db01200e33105265d4b8450122a82e
net: mvneta: fix potential double-frees in mvneta_txq_sw_deinit()

Reported on the Turris forum, mvneta provokes kernel warnings in the
architecture DMA mapping code when mvneta_setup_txqs() fails to
allocate memory. This happens because when mvneta_cleanup_txqs() is
called in the mvneta_stop() path, we leave pointers in the structure
that have been freed.

Then on mvneta_open(), we call mvneta_setup_txqs(), which starts
allocating memory. On memory allocation failure, mvneta_cleanup_txqs()
will walk all the queues freeing any non-NULL pointers - which includes
pointers that were previously freed in mvneta_stop().

Fix this by setting these pointers to NULL to prevent double-freeing
of the same memory.

Fixes: 2adb719d74f6 ("net: mvneta: Implement software TSO")
Link: https://forum.turris.cz/t/random-kernel-exceptions-on-hbl-tos-7-0/18865/8
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://lore.kernel.org/r/E1phUe5-00EieL-7q@rmk-PC.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/marvell/mvneta.c