Commit 8b5026bc authored by Julian Wiedmann's avatar Julian Wiedmann Committed by David S. Miller

s390/qeth: fix qdio teardown after early init error

qeth_l?_set_online() goes through a number of initialization steps, and
on any error uses qeth_l?_stop_card() to tear down the residual state.

The first initialization step is qeth_core_hardsetup_card(). When this
fails after having established a QDIO context on the device
(ie. somewhere after qeth_mpc_initialize()), qeth_l?_stop_card() doesn't
shut down this QDIO context again (since the card state hasn't
progressed from DOWN at this stage).

Even worse, we then call qdio_free() as final teardown step to free the
QDIO data structures - while some of them are still hooked into wider
QDIO infrastructure such as the IRQ list. This is inevitably followed by
use-after-frees and other nastyness.

Fix this by unconditionally calling qeth_qdio_clear_card() to shut down
the QDIO context, and also to halt/clear any pending activity on the
various IO channels.
Remove the naive attempt at handling the teardown in
qeth_mpc_initialize(), it clearly doesn't suffice and we're handling it
properly now in the wider teardown code.

Fixes: 4a71df50 ("qeth: new qeth device driver")
Signed-off-by: default avatarJulian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 47d0b2fe
...@@ -2482,50 +2482,46 @@ static int qeth_mpc_initialize(struct qeth_card *card) ...@@ -2482,50 +2482,46 @@ static int qeth_mpc_initialize(struct qeth_card *card)
rc = qeth_cm_enable(card); rc = qeth_cm_enable(card);
if (rc) { if (rc) {
QETH_CARD_TEXT_(card, 2, "2err%d", rc); QETH_CARD_TEXT_(card, 2, "2err%d", rc);
goto out_qdio; return rc;
} }
rc = qeth_cm_setup(card); rc = qeth_cm_setup(card);
if (rc) { if (rc) {
QETH_CARD_TEXT_(card, 2, "3err%d", rc); QETH_CARD_TEXT_(card, 2, "3err%d", rc);
goto out_qdio; return rc;
} }
rc = qeth_ulp_enable(card); rc = qeth_ulp_enable(card);
if (rc) { if (rc) {
QETH_CARD_TEXT_(card, 2, "4err%d", rc); QETH_CARD_TEXT_(card, 2, "4err%d", rc);
goto out_qdio; return rc;
} }
rc = qeth_ulp_setup(card); rc = qeth_ulp_setup(card);
if (rc) { if (rc) {
QETH_CARD_TEXT_(card, 2, "5err%d", rc); QETH_CARD_TEXT_(card, 2, "5err%d", rc);
goto out_qdio; return rc;
} }
rc = qeth_alloc_qdio_queues(card); rc = qeth_alloc_qdio_queues(card);
if (rc) { if (rc) {
QETH_CARD_TEXT_(card, 2, "5err%d", rc); QETH_CARD_TEXT_(card, 2, "5err%d", rc);
goto out_qdio; return rc;
} }
rc = qeth_qdio_establish(card); rc = qeth_qdio_establish(card);
if (rc) { if (rc) {
QETH_CARD_TEXT_(card, 2, "6err%d", rc); QETH_CARD_TEXT_(card, 2, "6err%d", rc);
qeth_free_qdio_queues(card); qeth_free_qdio_queues(card);
goto out_qdio; return rc;
} }
rc = qeth_qdio_activate(card); rc = qeth_qdio_activate(card);
if (rc) { if (rc) {
QETH_CARD_TEXT_(card, 2, "7err%d", rc); QETH_CARD_TEXT_(card, 2, "7err%d", rc);
goto out_qdio; return rc;
} }
rc = qeth_dm_act(card); rc = qeth_dm_act(card);
if (rc) { if (rc) {
QETH_CARD_TEXT_(card, 2, "8err%d", rc); QETH_CARD_TEXT_(card, 2, "8err%d", rc);
goto out_qdio; return rc;
} }
return 0; return 0;
out_qdio:
qeth_qdio_clear_card(card, !IS_IQD(card));
qdio_free(CARD_DDEV(card));
return rc;
} }
void qeth_print_status_message(struct qeth_card *card) void qeth_print_status_message(struct qeth_card *card)
......
...@@ -287,12 +287,12 @@ static void qeth_l2_stop_card(struct qeth_card *card) ...@@ -287,12 +287,12 @@ static void qeth_l2_stop_card(struct qeth_card *card)
card->state = CARD_STATE_HARDSETUP; card->state = CARD_STATE_HARDSETUP;
} }
if (card->state == CARD_STATE_HARDSETUP) { if (card->state == CARD_STATE_HARDSETUP) {
qeth_qdio_clear_card(card, 0);
qeth_drain_output_queues(card); qeth_drain_output_queues(card);
qeth_clear_working_pool_list(card); qeth_clear_working_pool_list(card);
card->state = CARD_STATE_DOWN; card->state = CARD_STATE_DOWN;
} }
qeth_qdio_clear_card(card, 0);
flush_workqueue(card->event_wq); flush_workqueue(card->event_wq);
card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
card->info.promisc_mode = 0; card->info.promisc_mode = 0;
......
...@@ -1307,12 +1307,12 @@ static void qeth_l3_stop_card(struct qeth_card *card) ...@@ -1307,12 +1307,12 @@ static void qeth_l3_stop_card(struct qeth_card *card)
card->state = CARD_STATE_HARDSETUP; card->state = CARD_STATE_HARDSETUP;
} }
if (card->state == CARD_STATE_HARDSETUP) { if (card->state == CARD_STATE_HARDSETUP) {
qeth_qdio_clear_card(card, 0);
qeth_drain_output_queues(card); qeth_drain_output_queues(card);
qeth_clear_working_pool_list(card); qeth_clear_working_pool_list(card);
card->state = CARD_STATE_DOWN; card->state = CARD_STATE_DOWN;
} }
qeth_qdio_clear_card(card, 0);
flush_workqueue(card->event_wq); flush_workqueue(card->event_wq);
card->info.promisc_mode = 0; card->info.promisc_mode = 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment