diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c index 87f5af454751..df5e3d3cbf6c 100644 --- a/drivers/pnp/card.c +++ b/drivers/pnp/card.c @@ -254,9 +254,16 @@ int pnp_add_card(struct pnp_card *card) /* we wait until now to add devices in order to ensure the drivers * will be able to use all of the related devices on the card * without waiting an unreasonable length of time */ - list_for_each(pos, &card->devices) { + list_for_each_safe(pos, temp, &card->devices) { struct pnp_dev *dev = card_to_pnp_dev(pos); - __pnp_add_device(dev); + error = __pnp_add_device(dev); + if (error) { + mutex_lock(&pnp_lock); + list_del(&dev->card_list); + dev->card = NULL; + mutex_unlock(&pnp_lock); + put_device(&dev->dev); + } } /* match with card drivers */