iio: inkern: clean up error return code
When the IIO consumer tries to get specific IIO channel,
few error cases can be happened.
(a) Memory allocation failure
(b) No matched ADC channel error
(c) Invalid input arguments
This patch enables cleaning up error handling in case of (a) and (b).
In error handling code,
(a): the reference count of the IIO device should be decreased.
(b): the allocated memory should be freed with restoring the reference count.
Therefore iio_deivce_put() is called in both cases.
This can be handled in the last error statement.
Additionally, integer variable is used for stating each error case explicitly.
Then, the error returns as ERR_PTR() with this value.
Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>