[media] af9013: fix error handling

Use typical (return 0/goto err/return err) error handling everywhere.
Add missing error handling where missing.

Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
This commit is contained in:
Antti Palosaari 2017-06-12 14:32:36 -03:00 committed by Mauro Carvalho Chehab
parent f458a1bc67
commit bf69e07262
1 changed files with 49 additions and 35 deletions

View File

@ -94,7 +94,7 @@ static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval)
if (ret) if (ret)
goto err; goto err;
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -147,7 +147,7 @@ static int af9013_power_ctrl(struct af9013_state *state, u8 onoff)
goto err; goto err;
} }
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -166,7 +166,7 @@ static int af9013_statistics_ber_unc_start(struct dvb_frontend *fe)
if (ret) if (ret)
goto err; goto err;
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -199,7 +199,7 @@ static int af9013_statistics_ber_unc_result(struct dvb_frontend *fe)
state->ber = (buf[2] << 16) | (buf[1] << 8) | buf[0]; state->ber = (buf[2] << 16) | (buf[1] << 8) | buf[0];
state->ucblocks += (buf[4] << 8) | buf[3]; state->ucblocks += (buf[4] << 8) | buf[3];
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -218,7 +218,7 @@ static int af9013_statistics_snr_start(struct dvb_frontend *fe)
if (ret) if (ret)
goto err; goto err;
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -283,7 +283,7 @@ static int af9013_statistics_snr_result(struct dvb_frontend *fe)
} }
state->snr = utmp * 10; /* dB/10 */ state->snr = utmp * 10; /* dB/10 */
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -321,7 +321,7 @@ static int af9013_statistics_signal_strength(struct dvb_frontend *fe)
state->signal_strength = signal_strength; state->signal_strength = signal_strength;
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -399,8 +399,11 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
c->frequency, c->bandwidth_hz); c->frequency, c->bandwidth_hz);
/* program tuner */ /* program tuner */
if (fe->ops.tuner_ops.set_params) if (fe->ops.tuner_ops.set_params) {
fe->ops.tuner_ops.set_params(fe); ret = fe->ops.tuner_ops.set_params(fe);
if (ret)
goto err;
}
/* program CFOE coefficients */ /* program CFOE coefficients */
if (c->bandwidth_hz != state->bandwidth_hz) { if (c->bandwidth_hz != state->bandwidth_hz) {
@ -412,8 +415,10 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
} }
/* Return an error if can't find bandwidth or the right clock */ /* Return an error if can't find bandwidth or the right clock */
if (i == ARRAY_SIZE(coeff_lut)) if (i == ARRAY_SIZE(coeff_lut)) {
return -EINVAL; ret = -EINVAL;
goto err;
}
ret = regmap_bulk_write(state->regmap, 0xae00, coeff_lut[i].val, ret = regmap_bulk_write(state->regmap, 0xae00, coeff_lut[i].val,
sizeof(coeff_lut[i].val)); sizeof(coeff_lut[i].val));
@ -424,10 +429,14 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
/* program frequency control */ /* program frequency control */
if (c->bandwidth_hz != state->bandwidth_hz || state->first_tune) { if (c->bandwidth_hz != state->bandwidth_hz || state->first_tune) {
/* get used IF frequency */ /* get used IF frequency */
if (fe->ops.tuner_ops.get_if_frequency) if (fe->ops.tuner_ops.get_if_frequency) {
fe->ops.tuner_ops.get_if_frequency(fe, &if_frequency); ret = fe->ops.tuner_ops.get_if_frequency(fe,
else &if_frequency);
if (ret)
goto err;
} else {
if_frequency = state->if_frequency; if_frequency = state->if_frequency;
}
dev_dbg(&client->dev, "if_frequency %u\n", if_frequency); dev_dbg(&client->dev, "if_frequency %u\n", if_frequency);
@ -662,7 +671,7 @@ static int af9013_set_frontend(struct dvb_frontend *fe)
state->set_frontend_jiffies = jiffies; state->set_frontend_jiffies = jiffies;
state->first_tune = false; state->first_tune = false;
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -780,7 +789,7 @@ static int af9013_get_frontend(struct dvb_frontend *fe,
break; break;
} }
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -831,7 +840,7 @@ static int af9013_read_status(struct dvb_frontend *fe, enum fe_status *status)
state->fe_status = *status; state->fe_status = *status;
state->read_status_jiffies = jiffies; state->read_status_jiffies = jiffies;
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -1090,7 +1099,7 @@ static int af9013_init(struct dvb_frontend *fe)
state->first_tune = true; state->first_tune = true;
schedule_delayed_work(&state->statistics_work, msecs_to_jiffies(400)); schedule_delayed_work(&state->statistics_work, msecs_to_jiffies(400));
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -1117,7 +1126,7 @@ static int af9013_sleep(struct dvb_frontend *fe)
if (ret) if (ret)
goto err; goto err;
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -1146,7 +1155,7 @@ static int af9013_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
state->i2c_gate_state = enable; state->i2c_gate_state = enable;
return ret; return 0;
err: err:
dev_dbg(&client->dev, "failed %d\n", ret); dev_dbg(&client->dev, "failed %d\n", ret);
return ret; return ret;
@ -1167,7 +1176,7 @@ static const struct dvb_frontend_ops af9013_ops;
static int af9013_download_firmware(struct af9013_state *state) static int af9013_download_firmware(struct af9013_state *state)
{ {
struct i2c_client *client = state->client; struct i2c_client *client = state->client;
int i, len, remaining, ret; int ret, i, len, remaining;
unsigned int utmp; unsigned int utmp;
const struct firmware *fw; const struct firmware *fw;
u16 checksum = 0; u16 checksum = 0;
@ -1179,11 +1188,11 @@ static int af9013_download_firmware(struct af9013_state *state)
ret = regmap_read(state->regmap, 0x98be, &utmp); ret = regmap_read(state->regmap, 0x98be, &utmp);
if (ret) if (ret)
goto err; goto err;
else
dev_dbg(&client->dev, "firmware status %02x\n", utmp); dev_dbg(&client->dev, "firmware status %02x\n", utmp);
if (utmp == 0x0c) /* fw is running, no need for download */ if (utmp == 0x0c) /* fw is running, no need for download */
goto exit; return 0;
dev_info(&client->dev, "found a '%s' in cold state, will try to load a firmware\n", dev_info(&client->dev, "found a '%s' in cold state, will try to load a firmware\n",
af9013_ops.info.name); af9013_ops.info.name);
@ -1213,7 +1222,7 @@ static int af9013_download_firmware(struct af9013_state *state)
sizeof(fw_params)); sizeof(fw_params));
if (ret) if (ret)
goto err_release; goto err_release_firmware;
#define FW_ADDR 0x5100 /* firmware start address */ #define FW_ADDR 0x5100 /* firmware start address */
#define LEN_MAX 16 /* max packet size */ #define LEN_MAX 16 /* max packet size */
@ -1228,39 +1237,44 @@ static int af9013_download_firmware(struct af9013_state *state)
if (ret) { if (ret) {
dev_err(&client->dev, "firmware download failed %d\n", dev_err(&client->dev, "firmware download failed %d\n",
ret); ret);
goto err_release; goto err_release_firmware;
} }
} }
release_firmware(fw);
/* request boot firmware */ /* request boot firmware */
ret = regmap_write(state->regmap, 0xe205, 0x01); ret = regmap_write(state->regmap, 0xe205, 0x01);
if (ret) if (ret)
goto err_release; goto err;
/* Check firmware status. 0c=OK, 04=fail */ /* Check firmware status. 0c=OK, 04=fail */
ret = regmap_read_poll_timeout(state->regmap, 0x98be, utmp, ret = regmap_read_poll_timeout(state->regmap, 0x98be, utmp,
(utmp == 0x0c || utmp == 0x04), (utmp == 0x0c || utmp == 0x04),
5000, 1000000); 5000, 1000000);
if (ret) if (ret)
goto err_release; goto err;
dev_dbg(&client->dev, "firmware status %02x\n", utmp); dev_dbg(&client->dev, "firmware status %02x\n", utmp);
if (utmp == 0x04) { if (utmp == 0x04) {
ret = -ENODEV;
dev_err(&client->dev, "firmware did not run\n"); dev_err(&client->dev, "firmware did not run\n");
ret = -ENODEV; goto err;
} else if (utmp != 0x0c) { } else if (utmp != 0x0c) {
dev_err(&client->dev, "firmware boot timeout\n");
ret = -ENODEV; ret = -ENODEV;
dev_err(&client->dev, "firmware boot timeout\n");
goto err;
} }
err_release: dev_info(&client->dev, "found a '%s' in warm state\n",
af9013_ops.info.name);
return 0;
err_release_firmware:
release_firmware(fw); release_firmware(fw);
err: err:
exit: dev_dbg(&client->dev, "failed %d\n", ret);
if (!ret)
dev_info(&client->dev, "found a '%s' in warm state\n",
af9013_ops.info.name);
return ret; return ret;
} }