net: ena: fix: set freed objects to NULL to avoid failing future allocations
authorSameeh Jubran <sameehj@amazon.com>
Wed, 1 May 2019 13:47:04 +0000 (16:47 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sat, 4 May 2019 04:14:46 +0000 (00:14 -0400)
commit8ee8ee7fe87bf64738ab4e31be036a7165608b27
treeae13a1cf879eeca8a20b31d777a7140cd40a699f
parent3c6eeff295f01bdf1c6c3addcb0a04c0c6c029e9
net: ena: fix: set freed objects to NULL to avoid failing future allocations

In some cases when a queue related allocation fails, successful past
allocations are freed but the pointer that pointed to them is not
set to NULL. This is a problem for 2 reasons:
1. This is generally a bad practice since this pointer might be
accidentally accessed in the future.
2. Future allocations using the same pointer check if the pointer
is NULL and fail if it is not.

Fixed this by setting such pointers to NULL in the allocation of
queue related objects.

Also refactored the code of ena_setup_tx_resources() to goto-style
error handling to avoid code duplication of resource freeing.

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/amazon/ena/ena_netdev.c