Commit ed6886c104c151c4d2d8fbce154da945c3d04dad

Authored by Sachin Kamat
Committed by Jonathan Cameron
1 parent a726dea547

iio: adc: nau7802: Use devm_iio_device_alloc

Using devm_iio_device_alloc makes code simpler.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

Showing 1 changed file with 8 additions and 11 deletions Side-by-side Diff

drivers/iio/adc/nau7802.c
... ... @@ -404,7 +404,7 @@
404 404 return -EINVAL;
405 405 }
406 406  
407   - indio_dev = iio_device_alloc(sizeof(*st));
  407 + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st));
408 408 if (indio_dev == NULL)
409 409 return -ENOMEM;
410 410  
411 411  
... ... @@ -423,13 +423,13 @@
423 423 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL,
424 424 NAU7802_PUCTRL_RR_BIT);
425 425 if (ret < 0)
426   - goto error_free_indio;
  426 + return ret;
427 427  
428 428 /* Enter normal operation mode */
429 429 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL,
430 430 NAU7802_PUCTRL_PUD_BIT);
431 431 if (ret < 0)
432   - goto error_free_indio;
  432 + return ret;
433 433  
434 434 /*
435 435 * After about 200 usecs, the device should be ready and then
436 436  
... ... @@ -438,9 +438,9 @@
438 438 udelay(210);
439 439 ret = i2c_smbus_read_byte_data(st->client, NAU7802_REG_PUCTRL);
440 440 if (ret < 0)
441   - goto error_free_indio;
  441 + return ret;
442 442 if (!(ret & NAU7802_PUCTRL_PUR_BIT))
443   - goto error_free_indio;
  443 + return ret;
444 444  
445 445 of_property_read_u32(np, "nuvoton,vldo", &tmp);
446 446 st->vref_mv = tmp;
447 447  
448 448  
... ... @@ -452,17 +452,17 @@
452 452  
453 453 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_PUCTRL, data);
454 454 if (ret < 0)
455   - goto error_free_indio;
  455 + return ret;
456 456 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_ADC_CTRL, 0x30);
457 457 if (ret < 0)
458   - goto error_free_indio;
  458 + return ret;
459 459  
460 460 if (tmp >= 2400) {
461 461 data = NAU7802_CTRL1_VLDO((4500 - tmp) / 300);
462 462 ret = i2c_smbus_write_byte_data(st->client, NAU7802_REG_CTRL1,
463 463 data);
464 464 if (ret < 0)
465   - goto error_free_indio;
  465 + return ret;
466 466 }
467 467  
468 468 /* Populate available ADC input ranges */
... ... @@ -533,8 +533,6 @@
533 533 error_free_irq:
534 534 if (client->irq)
535 535 free_irq(client->irq, indio_dev);
536   -error_free_indio:
537   - iio_device_free(indio_dev);
538 536  
539 537 return ret;
540 538 }
... ... @@ -549,7 +547,6 @@
549 547 mutex_destroy(&st->data_lock);
550 548 if (client->irq)
551 549 free_irq(client->irq, indio_dev);
552   - iio_device_free(indio_dev);
553 550  
554 551 return 0;
555 552 }