diff options
author | Alexey Klimov <klimov.linux@gmail.com> | 2008-12-27 20:30:29 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-12-30 06:40:11 -0500 |
commit | 417b7953668574ff38d3f2dc76e9fe669f121469 (patch) | |
tree | 611f484e14984857ae4568c118fdd6cbe9534531 /drivers/media/radio | |
parent | 290588e067b6710b614da4bd538197dd88158b62 (diff) |
V4L/DVB (10058): dsbr100: fix codingstyle, add dev_err messages
We should make if-constructions more clear. Introduce int retval
variables in some functions to make it this way. Also a lot of useful
dev_err messages added. And now we check every returned value after
usb_control_msg.
Signed-off-by: Alexey Klimov <klimov.linux@gmail.com>
Signed-off-by: Douglas Schilling Landgraf <dougsland@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/radio')
-rw-r--r-- | drivers/media/radio/dsbr100.c | 184 |
1 files changed, 137 insertions, 47 deletions
diff --git a/drivers/media/radio/dsbr100.c b/drivers/media/radio/dsbr100.c index e1cc369bdbd6..e0d7485226cd 100644 --- a/drivers/media/radio/dsbr100.c +++ b/drivers/media/radio/dsbr100.c | |||
@@ -197,86 +197,169 @@ static struct usb_driver usb_dsbr100_driver = { | |||
197 | /* switch on radio */ | 197 | /* switch on radio */ |
198 | static int dsbr100_start(struct dsbr100_device *radio) | 198 | static int dsbr100_start(struct dsbr100_device *radio) |
199 | { | 199 | { |
200 | int retval; | ||
201 | int request; | ||
202 | |||
200 | mutex_lock(&radio->lock); | 203 | mutex_lock(&radio->lock); |
201 | if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), | 204 | |
202 | USB_REQ_GET_STATUS, | 205 | retval = usb_control_msg(radio->usbdev, |
203 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | 206 | usb_rcvctrlpipe(radio->usbdev, 0), |
204 | 0x00, 0xC7, radio->transfer_buffer, 8, 300) < 0 || | 207 | USB_REQ_GET_STATUS, |
205 | usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), | 208 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
206 | DSB100_ONOFF, | 209 | 0x00, 0xC7, radio->transfer_buffer, 8, 300); |
207 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | 210 | |
208 | 0x01, 0x00, radio->transfer_buffer, 8, 300) < 0) { | 211 | if (retval < 0) { |
209 | mutex_unlock(&radio->lock); | 212 | request = USB_REQ_GET_STATUS; |
210 | return -1; | 213 | goto usb_control_msg_failed; |
211 | } | 214 | } |
212 | 215 | ||
213 | radio->muted=0; | 216 | retval = usb_control_msg(radio->usbdev, |
217 | usb_rcvctrlpipe(radio->usbdev, 0), | ||
218 | DSB100_ONOFF, | ||
219 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | ||
220 | 0x01, 0x00, radio->transfer_buffer, 8, 300); | ||
221 | |||
222 | if (retval < 0) { | ||
223 | request = DSB100_ONOFF; | ||
224 | goto usb_control_msg_failed; | ||
225 | } | ||
226 | |||
227 | radio->muted = 0; | ||
214 | mutex_unlock(&radio->lock); | 228 | mutex_unlock(&radio->lock); |
215 | return (radio->transfer_buffer)[0]; | 229 | return (radio->transfer_buffer)[0]; |
230 | |||
231 | usb_control_msg_failed: | ||
232 | mutex_unlock(&radio->lock); | ||
233 | dev_err(&radio->usbdev->dev, | ||
234 | "%s - usb_control_msg returned %i, request %i\n", | ||
235 | __func__, retval, request); | ||
236 | return -1; | ||
237 | |||
216 | } | 238 | } |
217 | 239 | ||
218 | 240 | ||
219 | /* switch off radio */ | 241 | /* switch off radio */ |
220 | static int dsbr100_stop(struct dsbr100_device *radio) | 242 | static int dsbr100_stop(struct dsbr100_device *radio) |
221 | { | 243 | { |
244 | int retval; | ||
245 | int request; | ||
246 | |||
222 | mutex_lock(&radio->lock); | 247 | mutex_lock(&radio->lock); |
223 | if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), | 248 | |
224 | USB_REQ_GET_STATUS, | 249 | retval = usb_control_msg(radio->usbdev, |
225 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | 250 | usb_rcvctrlpipe(radio->usbdev, 0), |
226 | 0x16, 0x1C, radio->transfer_buffer, 8, 300) < 0 || | 251 | USB_REQ_GET_STATUS, |
227 | usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), | 252 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
228 | DSB100_ONOFF, | 253 | 0x16, 0x1C, radio->transfer_buffer, 8, 300); |
229 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | 254 | |
230 | 0x00, 0x00, radio->transfer_buffer, 8, 300) < 0) { | 255 | if (retval < 0) { |
231 | mutex_unlock(&radio->lock); | 256 | request = USB_REQ_GET_STATUS; |
232 | return -1; | 257 | goto usb_control_msg_failed; |
258 | } | ||
259 | |||
260 | retval = usb_control_msg(radio->usbdev, | ||
261 | usb_rcvctrlpipe(radio->usbdev, 0), | ||
262 | DSB100_ONOFF, | ||
263 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | ||
264 | 0x00, 0x00, radio->transfer_buffer, 8, 300); | ||
265 | |||
266 | if (retval < 0) { | ||
267 | request = DSB100_ONOFF; | ||
268 | goto usb_control_msg_failed; | ||
233 | } | 269 | } |
234 | 270 | ||
235 | radio->muted=1; | 271 | radio->muted = 1; |
236 | mutex_unlock(&radio->lock); | 272 | mutex_unlock(&radio->lock); |
237 | return (radio->transfer_buffer)[0]; | 273 | return (radio->transfer_buffer)[0]; |
274 | |||
275 | usb_control_msg_failed: | ||
276 | mutex_unlock(&radio->lock); | ||
277 | dev_err(&radio->usbdev->dev, | ||
278 | "%s - usb_control_msg returned %i, request %i\n", | ||
279 | __func__, retval, request); | ||
280 | return -1; | ||
281 | |||
238 | } | 282 | } |
239 | 283 | ||
240 | /* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */ | 284 | /* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */ |
241 | static int dsbr100_setfreq(struct dsbr100_device *radio, int freq) | 285 | static int dsbr100_setfreq(struct dsbr100_device *radio, int freq) |
242 | { | 286 | { |
287 | int retval; | ||
288 | int request; | ||
289 | |||
243 | freq = (freq / 16 * 80) / 1000 + 856; | 290 | freq = (freq / 16 * 80) / 1000 + 856; |
244 | mutex_lock(&radio->lock); | 291 | mutex_lock(&radio->lock); |
245 | if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), | 292 | |
246 | DSB100_TUNE, | 293 | retval = usb_control_msg(radio->usbdev, |
247 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | 294 | usb_rcvctrlpipe(radio->usbdev, 0), |
248 | (freq >> 8) & 0x00ff, freq & 0xff, | 295 | DSB100_TUNE, |
249 | radio->transfer_buffer, 8, 300) < 0 || | 296 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
250 | usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), | 297 | (freq >> 8) & 0x00ff, freq & 0xff, |
251 | USB_REQ_GET_STATUS, | 298 | radio->transfer_buffer, 8, 300); |
252 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | 299 | |
253 | 0x96, 0xB7, radio->transfer_buffer, 8, 300) < 0 || | 300 | if (retval < 0) { |
254 | usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), | 301 | request = DSB100_TUNE; |
255 | USB_REQ_GET_STATUS, | 302 | goto usb_control_msg_failed; |
256 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | 303 | } |
257 | 0x00, 0x24, radio->transfer_buffer, 8, 300) < 0) { | 304 | |
258 | radio->stereo = -1; | 305 | retval = usb_control_msg(radio->usbdev, |
259 | mutex_unlock(&radio->lock); | 306 | usb_rcvctrlpipe(radio->usbdev, 0), |
260 | return -1; | 307 | USB_REQ_GET_STATUS, |
308 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | ||
309 | 0x96, 0xB7, radio->transfer_buffer, 8, 300); | ||
310 | |||
311 | if (retval < 0) { | ||
312 | request = USB_REQ_GET_STATUS; | ||
313 | goto usb_control_msg_failed; | ||
314 | } | ||
315 | |||
316 | retval = usb_control_msg(radio->usbdev, | ||
317 | usb_rcvctrlpipe(radio->usbdev, 0), | ||
318 | USB_REQ_GET_STATUS, | ||
319 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | ||
320 | 0x00, 0x24, radio->transfer_buffer, 8, 300); | ||
321 | |||
322 | if (retval < 0) { | ||
323 | request = USB_REQ_GET_STATUS; | ||
324 | goto usb_control_msg_failed; | ||
261 | } | 325 | } |
262 | 326 | ||
263 | radio->stereo = !((radio->transfer_buffer)[0] & 0x01); | 327 | radio->stereo = !((radio->transfer_buffer)[0] & 0x01); |
264 | mutex_unlock(&radio->lock); | 328 | mutex_unlock(&radio->lock); |
265 | return (radio->transfer_buffer)[0]; | 329 | return (radio->transfer_buffer)[0]; |
330 | |||
331 | usb_control_msg_failed: | ||
332 | radio->stereo = -1; | ||
333 | mutex_unlock(&radio->lock); | ||
334 | dev_err(&radio->usbdev->dev, | ||
335 | "%s - usb_control_msg returned %i, request %i\n", | ||
336 | __func__, retval, request); | ||
337 | return -1; | ||
266 | } | 338 | } |
267 | 339 | ||
268 | /* return the device status. This is, in effect, just whether it | 340 | /* return the device status. This is, in effect, just whether it |
269 | sees a stereo signal or not. Pity. */ | 341 | sees a stereo signal or not. Pity. */ |
270 | static void dsbr100_getstat(struct dsbr100_device *radio) | 342 | static void dsbr100_getstat(struct dsbr100_device *radio) |
271 | { | 343 | { |
344 | int retval; | ||
345 | |||
272 | mutex_lock(&radio->lock); | 346 | mutex_lock(&radio->lock); |
273 | if (usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0), | 347 | |
348 | retval = usb_control_msg(radio->usbdev, | ||
349 | usb_rcvctrlpipe(radio->usbdev, 0), | ||
274 | USB_REQ_GET_STATUS, | 350 | USB_REQ_GET_STATUS, |
275 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, | 351 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
276 | 0x00 , 0x24, radio->transfer_buffer, 8, 300) < 0) | 352 | 0x00 , 0x24, radio->transfer_buffer, 8, 300); |
353 | |||
354 | if (retval < 0) { | ||
277 | radio->stereo = -1; | 355 | radio->stereo = -1; |
278 | else | 356 | dev_err(&radio->usbdev->dev, |
357 | "%s - usb_control_msg returned %i, request %i\n", | ||
358 | __func__, retval, USB_REQ_GET_STATUS); | ||
359 | } else { | ||
279 | radio->stereo = !(radio->transfer_buffer[0] & 0x01); | 360 | radio->stereo = !(radio->transfer_buffer[0] & 0x01); |
361 | } | ||
362 | |||
280 | mutex_unlock(&radio->lock); | 363 | mutex_unlock(&radio->lock); |
281 | } | 364 | } |
282 | 365 | ||
@@ -358,13 +441,15 @@ static int vidioc_s_frequency(struct file *file, void *priv, | |||
358 | struct v4l2_frequency *f) | 441 | struct v4l2_frequency *f) |
359 | { | 442 | { |
360 | struct dsbr100_device *radio = video_drvdata(file); | 443 | struct dsbr100_device *radio = video_drvdata(file); |
444 | int retval; | ||
361 | 445 | ||
362 | /* safety check */ | 446 | /* safety check */ |
363 | if (radio->removed) | 447 | if (radio->removed) |
364 | return -EIO; | 448 | return -EIO; |
365 | 449 | ||
366 | radio->curfreq = f->frequency; | 450 | radio->curfreq = f->frequency; |
367 | if (dsbr100_setfreq(radio, radio->curfreq) == -1) | 451 | retval = dsbr100_setfreq(radio, radio->curfreq); |
452 | if (retval == -1) | ||
368 | dev_warn(&radio->usbdev->dev, "Set frequency failed\n"); | 453 | dev_warn(&radio->usbdev->dev, "Set frequency failed\n"); |
369 | return 0; | 454 | return 0; |
370 | } | 455 | } |
@@ -418,6 +503,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv, | |||
418 | struct v4l2_control *ctrl) | 503 | struct v4l2_control *ctrl) |
419 | { | 504 | { |
420 | struct dsbr100_device *radio = video_drvdata(file); | 505 | struct dsbr100_device *radio = video_drvdata(file); |
506 | int retval; | ||
421 | 507 | ||
422 | /* safety check */ | 508 | /* safety check */ |
423 | if (radio->removed) | 509 | if (radio->removed) |
@@ -426,13 +512,15 @@ static int vidioc_s_ctrl(struct file *file, void *priv, | |||
426 | switch (ctrl->id) { | 512 | switch (ctrl->id) { |
427 | case V4L2_CID_AUDIO_MUTE: | 513 | case V4L2_CID_AUDIO_MUTE: |
428 | if (ctrl->value) { | 514 | if (ctrl->value) { |
429 | if (dsbr100_stop(radio) == -1) { | 515 | retval = dsbr100_stop(radio); |
516 | if (retval == -1) { | ||
430 | dev_warn(&radio->usbdev->dev, | 517 | dev_warn(&radio->usbdev->dev, |
431 | "Radio did not respond properly\n"); | 518 | "Radio did not respond properly\n"); |
432 | return -EBUSY; | 519 | return -EBUSY; |
433 | } | 520 | } |
434 | } else { | 521 | } else { |
435 | if (dsbr100_start(radio) == -1) { | 522 | retval = dsbr100_start(radio); |
523 | if (retval == -1) { | ||
436 | dev_warn(&radio->usbdev->dev, | 524 | dev_warn(&radio->usbdev->dev, |
437 | "Radio did not respond properly\n"); | 525 | "Radio did not respond properly\n"); |
438 | return -EBUSY; | 526 | return -EBUSY; |
@@ -484,7 +572,8 @@ static int usb_dsbr100_open(struct inode *inode, struct file *file) | |||
484 | radio->users = 1; | 572 | radio->users = 1; |
485 | radio->muted = 1; | 573 | radio->muted = 1; |
486 | 574 | ||
487 | if (dsbr100_start(radio) < 0) { | 575 | retval = dsbr100_start(radio); |
576 | if (retval < 0) { | ||
488 | dev_warn(&radio->usbdev->dev, | 577 | dev_warn(&radio->usbdev->dev, |
489 | "Radio did not start up properly\n"); | 578 | "Radio did not start up properly\n"); |
490 | radio->users = 0; | 579 | radio->users = 0; |
@@ -493,7 +582,6 @@ static int usb_dsbr100_open(struct inode *inode, struct file *file) | |||
493 | } | 582 | } |
494 | 583 | ||
495 | retval = dsbr100_setfreq(radio, radio->curfreq); | 584 | retval = dsbr100_setfreq(radio, radio->curfreq); |
496 | |||
497 | if (retval == -1) | 585 | if (retval == -1) |
498 | dev_warn(&radio->usbdev->dev, | 586 | dev_warn(&radio->usbdev->dev, |
499 | "set frequency failed\n"); | 587 | "set frequency failed\n"); |
@@ -601,6 +689,7 @@ static int usb_dsbr100_probe(struct usb_interface *intf, | |||
601 | const struct usb_device_id *id) | 689 | const struct usb_device_id *id) |
602 | { | 690 | { |
603 | struct dsbr100_device *radio; | 691 | struct dsbr100_device *radio; |
692 | int retval; | ||
604 | 693 | ||
605 | radio = kmalloc(sizeof(struct dsbr100_device), GFP_KERNEL); | 694 | radio = kmalloc(sizeof(struct dsbr100_device), GFP_KERNEL); |
606 | 695 | ||
@@ -622,7 +711,8 @@ static int usb_dsbr100_probe(struct usb_interface *intf, | |||
622 | radio->usbdev = interface_to_usbdev(intf); | 711 | radio->usbdev = interface_to_usbdev(intf); |
623 | radio->curfreq = FREQ_MIN * FREQ_MUL; | 712 | radio->curfreq = FREQ_MIN * FREQ_MUL; |
624 | video_set_drvdata(&radio->videodev, radio); | 713 | video_set_drvdata(&radio->videodev, radio); |
625 | if (video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr) < 0) { | 714 | retval = video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr); |
715 | if (retval < 0) { | ||
626 | dev_warn(&intf->dev, "Could not register video device\n"); | 716 | dev_warn(&intf->dev, "Could not register video device\n"); |
627 | kfree(radio->transfer_buffer); | 717 | kfree(radio->transfer_buffer); |
628 | kfree(radio); | 718 | kfree(radio); |