diff options
author | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-10-07 12:44:09 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-10-14 11:41:58 -0400 |
commit | ba705a629ceee28f7ee4a5f977da52278b683eb0 (patch) | |
tree | b85bd41298695264a612d7f4bec9d2e511bc4947 | |
parent | 89919b518863e7dac98d4d6d4b08ed2113d91d27 (diff) |
[media] dtt200u-fe: handle errors on USB control messages
If something goes wrong, return an error code, instead of
assuming that everything went fine.
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r-- | drivers/media/usb/dvb-usb/dtt200u-fe.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/drivers/media/usb/dvb-usb/dtt200u-fe.c b/drivers/media/usb/dvb-usb/dtt200u-fe.c index 7f7f64be6353..f5c042baa254 100644 --- a/drivers/media/usb/dvb-usb/dtt200u-fe.c +++ b/drivers/media/usb/dvb-usb/dtt200u-fe.c | |||
@@ -27,11 +27,17 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe, | |||
27 | enum fe_status *stat) | 27 | enum fe_status *stat) |
28 | { | 28 | { |
29 | struct dtt200u_fe_state *state = fe->demodulator_priv; | 29 | struct dtt200u_fe_state *state = fe->demodulator_priv; |
30 | int ret; | ||
30 | 31 | ||
31 | mutex_lock(&state->data_mutex); | 32 | mutex_lock(&state->data_mutex); |
32 | state->data[0] = GET_TUNE_STATUS; | 33 | state->data[0] = GET_TUNE_STATUS; |
33 | 34 | ||
34 | dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0); | 35 | ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0); |
36 | if (ret < 0) { | ||
37 | *stat = 0; | ||
38 | mutex_unlock(&state->data_mutex); | ||
39 | return ret; | ||
40 | } | ||
35 | 41 | ||
36 | switch (state->data[0]) { | 42 | switch (state->data[0]) { |
37 | case 0x01: | 43 | case 0x01: |
@@ -53,25 +59,30 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe, | |||
53 | static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber) | 59 | static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber) |
54 | { | 60 | { |
55 | struct dtt200u_fe_state *state = fe->demodulator_priv; | 61 | struct dtt200u_fe_state *state = fe->demodulator_priv; |
62 | int ret; | ||
56 | 63 | ||
57 | mutex_lock(&state->data_mutex); | 64 | mutex_lock(&state->data_mutex); |
58 | state->data[0] = GET_VIT_ERR_CNT; | 65 | state->data[0] = GET_VIT_ERR_CNT; |
59 | 66 | ||
60 | dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0); | 67 | ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0); |
61 | *ber = (state->data[0] << 16) | (state->data[1] << 8) | state->data[2]; | 68 | if (ret >= 0) |
69 | *ber = (state->data[0] << 16) | (state->data[1] << 8) | state->data[2]; | ||
62 | 70 | ||
63 | mutex_unlock(&state->data_mutex); | 71 | mutex_unlock(&state->data_mutex); |
64 | return 0; | 72 | return ret; |
65 | } | 73 | } |
66 | 74 | ||
67 | static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc) | 75 | static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc) |
68 | { | 76 | { |
69 | struct dtt200u_fe_state *state = fe->demodulator_priv; | 77 | struct dtt200u_fe_state *state = fe->demodulator_priv; |
78 | int ret; | ||
70 | 79 | ||
71 | mutex_lock(&state->data_mutex); | 80 | mutex_lock(&state->data_mutex); |
72 | state->data[0] = GET_RS_UNCOR_BLK_CNT; | 81 | state->data[0] = GET_RS_UNCOR_BLK_CNT; |
73 | 82 | ||
74 | dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0); | 83 | ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0); |
84 | if (ret >= 0) | ||
85 | *unc = (state->data[0] << 8) | state->data[1]; | ||
75 | 86 | ||
76 | mutex_unlock(&state->data_mutex); | 87 | mutex_unlock(&state->data_mutex); |
77 | return ret; | 88 | return ret; |
@@ -80,11 +91,14 @@ static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc) | |||
80 | static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength) | 91 | static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength) |
81 | { | 92 | { |
82 | struct dtt200u_fe_state *state = fe->demodulator_priv; | 93 | struct dtt200u_fe_state *state = fe->demodulator_priv; |
94 | int ret; | ||
83 | 95 | ||
84 | mutex_lock(&state->data_mutex); | 96 | mutex_lock(&state->data_mutex); |
85 | state->data[0] = GET_AGC; | 97 | state->data[0] = GET_AGC; |
86 | 98 | ||
87 | dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0); | 99 | ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0); |
100 | if (ret >= 0) | ||
101 | *strength = (state->data[0] << 8) | state->data[0]; | ||
88 | 102 | ||
89 | mutex_unlock(&state->data_mutex); | 103 | mutex_unlock(&state->data_mutex); |
90 | return ret; | 104 | return ret; |
@@ -93,11 +107,14 @@ static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strengt | |||
93 | static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr) | 107 | static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr) |
94 | { | 108 | { |
95 | struct dtt200u_fe_state *state = fe->demodulator_priv; | 109 | struct dtt200u_fe_state *state = fe->demodulator_priv; |
110 | int ret; | ||
96 | 111 | ||
97 | mutex_lock(&state->data_mutex); | 112 | mutex_lock(&state->data_mutex); |
98 | state->data[0] = GET_SNR; | 113 | state->data[0] = GET_SNR; |
99 | 114 | ||
100 | dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0); | 115 | ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0); |
116 | if (ret >= 0) | ||
117 | *snr = ~((state->data[0] << 8) | state->data[0]); | ||
101 | 118 | ||
102 | mutex_unlock(&state->data_mutex); | 119 | mutex_unlock(&state->data_mutex); |
103 | return ret; | 120 | return ret; |
@@ -134,6 +151,7 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend *fe) | |||
134 | { | 151 | { |
135 | struct dtv_frontend_properties *fep = &fe->dtv_property_cache; | 152 | struct dtv_frontend_properties *fep = &fe->dtv_property_cache; |
136 | struct dtt200u_fe_state *state = fe->demodulator_priv; | 153 | struct dtt200u_fe_state *state = fe->demodulator_priv; |
154 | int ret; | ||
137 | u16 freq = fep->frequency / 250000; | 155 | u16 freq = fep->frequency / 250000; |
138 | 156 | ||
139 | mutex_lock(&state->data_mutex); | 157 | mutex_lock(&state->data_mutex); |
@@ -153,12 +171,16 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend *fe) | |||
153 | goto ret; | 171 | goto ret; |
154 | } | 172 | } |
155 | 173 | ||
156 | dvb_usb_generic_write(state->d, state->data, 2); | 174 | ret = dvb_usb_generic_write(state->d, state->data, 2); |
175 | if (ret < 0) | ||
176 | goto ret; | ||
157 | 177 | ||
158 | state->data[0] = SET_RF_FREQ; | 178 | state->data[0] = SET_RF_FREQ; |
159 | state->data[1] = freq & 0xff; | 179 | state->data[1] = freq & 0xff; |
160 | state->data[2] = (freq >> 8) & 0xff; | 180 | state->data[2] = (freq >> 8) & 0xff; |
161 | dvb_usb_generic_write(state->d, state->data, 3); | 181 | ret = dvb_usb_generic_write(state->d, state->data, 3); |
182 | if (ret < 0) | ||
183 | goto ret; | ||
162 | 184 | ||
163 | ret: | 185 | ret: |
164 | mutex_unlock(&state->data_mutex); | 186 | mutex_unlock(&state->data_mutex); |