Commit a62dbd7027667d99254f0f38f9364e4edcd56ddc
1 parent
333f3460f8
Exists in
v3.2_SMARCT335xPSP_04.06.00.11
and in
3 other branches
IIO: ti_adc: Correct error handling path
The remove module and the error return path missed checks for buffer management. Add the same in ADC driver. Signed-off-by: Patil, Rachna <rachna@ti.com>
Showing 1 changed file with 16 additions and 8 deletions Side-by-side Diff
drivers/staging/iio/adc/ti_adc.c
... | ... | @@ -413,7 +413,7 @@ |
413 | 413 | if (idev == NULL) { |
414 | 414 | dev_err(&pdev->dev, "failed to allocate iio device.\n"); |
415 | 415 | err = -ENOMEM; |
416 | - goto err_allocate; | |
416 | + goto err_ret; | |
417 | 417 | } |
418 | 418 | adc_dev = iio_priv(idev); |
419 | 419 | |
420 | 420 | |
421 | 421 | |
422 | 422 | |
... | ... | @@ -436,23 +436,23 @@ |
436 | 436 | |
437 | 437 | err = tiadc_channel_init(idev, adc_dev); |
438 | 438 | if (err < 0) |
439 | - goto err_cleanup_channels; | |
439 | + goto err_free_device; | |
440 | 440 | |
441 | 441 | init_waitqueue_head(&adc_dev->wq_data_avail); |
442 | 442 | |
443 | 443 | err = request_irq(adc_dev->irq, tiadc_irq, IRQF_SHARED, |
444 | 444 | idev->name, idev); |
445 | 445 | if (err) |
446 | - goto err_unregister; | |
446 | + goto err_cleanup_channels; | |
447 | 447 | |
448 | 448 | err = tiadc_config_sw_ring(idev); |
449 | 449 | if (err) |
450 | - goto err_unregister; | |
450 | + goto err_free_irq; | |
451 | 451 | |
452 | 452 | err = iio_buffer_register(idev, |
453 | 453 | idev->channels, idev->num_channels); |
454 | 454 | if (err < 0) |
455 | - goto err_unregister; | |
455 | + goto err_free_sw_rb; | |
456 | 456 | |
457 | 457 | err = iio_device_register(idev); |
458 | 458 | if (err) |
459 | 459 | |
460 | 460 | |
... | ... | @@ -464,11 +464,16 @@ |
464 | 464 | return 0; |
465 | 465 | |
466 | 466 | err_unregister: |
467 | - tiadc_channel_remove(idev); | |
467 | + iio_buffer_unregister(idev); | |
468 | +err_free_sw_rb: | |
469 | + iio_sw_rb_free(idev->buffer); | |
470 | +err_free_irq: | |
471 | + free_irq(adc_dev->irq, idev); | |
468 | 472 | err_cleanup_channels: |
469 | - iio_device_unregister(idev); | |
473 | + tiadc_channel_remove(idev); | |
474 | +err_free_device: | |
470 | 475 | iio_free_device(idev); |
471 | -err_allocate: | |
476 | +err_ret: | |
472 | 477 | return err; |
473 | 478 | } |
474 | 479 | |
475 | 480 | |
... | ... | @@ -478,7 +483,10 @@ |
478 | 483 | struct adc_device *adc_dev = tscadc_dev->adc; |
479 | 484 | struct iio_dev *idev = adc_dev->idev; |
480 | 485 | |
486 | + free_irq(adc_dev->irq, idev); | |
481 | 487 | iio_device_unregister(idev); |
488 | + iio_buffer_unregister(idev); | |
489 | + iio_sw_rb_free(idev->buffer); | |
482 | 490 | tiadc_channel_remove(idev); |
483 | 491 | |
484 | 492 | tscadc_dev->adc = NULL; |