Commit cce99cf9 authored by Antti Palosaari's avatar Antti Palosaari Committed by Mauro Carvalho Chehab

[media] dvb_usb_v2: unregister all frontends in error case

Unregister all if there is any error meet during
frontend initialization.
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 96ffea88
...@@ -324,32 +324,36 @@ static int dvb_usb_fe_sleep(struct dvb_frontend *fe) ...@@ -324,32 +324,36 @@ static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap) int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap)
{ {
int ret, i; int ret, i, count_registered = 0;
pr_debug("%s:\n", __func__);
memset(adap->fe, 0, sizeof(adap->fe)); memset(adap->fe, 0, sizeof(adap->fe));
adap->active_fe = -1; adap->active_fe = -1;
if (adap->props.frontend_attach == NULL) { if (adap->props.frontend_attach) {
err("strange: '%s' doesn't want to attach a frontend.", ret = adap->props.frontend_attach(adap);
adap->dev->name); if (ret < 0) {
pr_debug("%s: frontend_attach() failed=%d\n", __func__,
ret);
goto err_dvb_frontend_detach;
}
} else {
pr_debug("%s: frontend_attach() do not exists\n", __func__);
ret = 0; ret = 0;
goto err; goto err;
} }
/* attach all given adapter frontends */ if (adap->props.tuner_attach) {
ret = adap->props.frontend_attach(adap); ret = adap->props.tuner_attach(adap);
if (ret < 0) if (ret < 0) {
goto err; pr_debug("%s: tuner_attach() failed=%d\n", __func__,
ret);
if (adap->fe[0] == NULL) { goto err_dvb_frontend_detach;
err("no frontend was attached by '%s'", adap->dev->name); }
goto err;
} }
for (i = 0; i < MAX_NO_OF_FE_PER_ADAP; i++) { for (i = 0; i < MAX_NO_OF_FE_PER_ADAP && adap->fe[i]; i++) {
if (adap->fe[i] == NULL)
break;
adap->fe[i]->id = i; adap->fe[i]->id = i;
/* re-assign sleep and wakeup functions */ /* re-assign sleep and wakeup functions */
...@@ -360,28 +364,28 @@ int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap) ...@@ -360,28 +364,28 @@ int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap)
ret = dvb_register_frontend(&adap->dvb_adap, adap->fe[i]); ret = dvb_register_frontend(&adap->dvb_adap, adap->fe[i]);
if (ret < 0) { if (ret < 0) {
err("Frontend %d registration failed.", i); pr_err("%s: frontend%d registration failed\n",
dvb_frontend_detach(adap->fe[i]); KBUILD_MODNAME, i);
adap->fe[i] = NULL; goto err_dvb_unregister_frontend;
/* In error case, do not try register more FEs,
* still leaving already registered FEs alive. */
if (i == 0)
goto err;
else
break;
} }
adap->num_frontends_initialized++; count_registered++;
} }
/* attach all given adapter tuners */ adap->num_frontends_initialized = count_registered;
if (adap->props.tuner_attach) {
ret = adap->props.tuner_attach(adap);
if (ret < 0)
err("tuner attach failed - will continue");
}
return 0; return 0;
err_dvb_unregister_frontend:
for (i = count_registered - 1; i >= 0; i--)
dvb_unregister_frontend(adap->fe[i]);
err_dvb_frontend_detach:
for (i = MAX_NO_OF_FE_PER_ADAP - 1; i >= 0; i--) {
if (adap->fe[i])
dvb_frontend_detach(adap->fe[i]);
}
err: err:
pr_debug("%s: failed=%d\n", __func__, ret); pr_debug("%s: failed=%d\n", __func__, ret);
return ret; return ret;
...@@ -389,15 +393,17 @@ int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap) ...@@ -389,15 +393,17 @@ int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap)
int dvb_usb_adapter_frontend_exit(struct dvb_usb_adapter *adap) int dvb_usb_adapter_frontend_exit(struct dvb_usb_adapter *adap)
{ {
int i = adap->num_frontends_initialized - 1; int i;
pr_debug("%s:\n", __func__);
/* unregister all given adapter frontends */ for (i = adap->num_frontends_initialized - 1; i >= 0; i--) {
for (; i >= 0; i--) { if (adap->fe[i]) {
if (adap->fe[i] != NULL) {
dvb_unregister_frontend(adap->fe[i]); dvb_unregister_frontend(adap->fe[i]);
dvb_frontend_detach(adap->fe[i]); dvb_frontend_detach(adap->fe[i]);
} }
} }
adap->num_frontends_initialized = 0; adap->num_frontends_initialized = 0;
return 0; return 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