drivers: i2c: add runtime put for error path
The previous error path incorrectly returned without calling runtime put async Signed-off-by: Hao Luo <hluo@ambiq.com>
This commit is contained in:
parent
5d69216cc9
commit
e7a64f74a8
2 changed files with 24 additions and 19 deletions
|
@ -183,16 +183,16 @@ static int i2c_ambiq_transfer(const struct device *dev, struct i2c_msg *msgs, ui
|
|||
uint16_t addr)
|
||||
{
|
||||
struct i2c_ambiq_data *data = dev->data;
|
||||
int ret = 0;
|
||||
int pm_ret, ret = 0;
|
||||
|
||||
if (!num_msgs) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = pm_device_runtime_get(dev);
|
||||
pm_ret = pm_device_runtime_get(dev);
|
||||
|
||||
if (ret < 0) {
|
||||
LOG_ERR("pm_device_runtime_get failed: %d", ret);
|
||||
if (pm_ret < 0) {
|
||||
LOG_ERR("pm_device_runtime_get failed: %d", pm_ret);
|
||||
}
|
||||
|
||||
/* Send out messages */
|
||||
|
@ -206,8 +206,8 @@ static int i2c_ambiq_transfer(const struct device *dev, struct i2c_msg *msgs, ui
|
|||
}
|
||||
|
||||
if (ret != 0) {
|
||||
k_sem_give(&data->bus_sem);
|
||||
return ret;
|
||||
LOG_ERR("i2c transfer failed: %d", ret);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,13 +216,15 @@ static int i2c_ambiq_transfer(const struct device *dev, struct i2c_msg *msgs, ui
|
|||
/* Use async put to avoid useless device suspension/resumption
|
||||
* when doing consecutive transmission.
|
||||
*/
|
||||
ret = pm_device_runtime_put_async(dev, K_MSEC(2));
|
||||
if (!pm_ret) {
|
||||
pm_ret = pm_device_runtime_put_async(dev, K_MSEC(2));
|
||||
|
||||
if (ret < 0) {
|
||||
LOG_ERR("pm_device_runtime_put failed: %d", ret);
|
||||
if (pm_ret < 0) {
|
||||
LOG_ERR("pm_device_runtime_put failed: %d", pm_ret);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int i2c_ambiq_init(const struct device *dev)
|
||||
|
|
|
@ -343,16 +343,16 @@ static int spi_ambiq_transceive(const struct device *dev, const struct spi_confi
|
|||
const struct spi_buf_set *rx_bufs)
|
||||
{
|
||||
struct spi_ambiq_data *data = dev->data;
|
||||
int ret;
|
||||
int pm_ret, ret = 0;
|
||||
|
||||
if (!tx_bufs && !rx_bufs) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = pm_device_runtime_get(dev);
|
||||
pm_ret = pm_device_runtime_get(dev);
|
||||
|
||||
if (ret < 0) {
|
||||
LOG_ERR("pm_device_runtime_get failed: %d", ret);
|
||||
if (pm_ret < 0) {
|
||||
LOG_ERR("pm_device_runtime_get failed: %d", pm_ret);
|
||||
}
|
||||
|
||||
/* context setup */
|
||||
|
@ -361,23 +361,26 @@ static int spi_ambiq_transceive(const struct device *dev, const struct spi_confi
|
|||
ret = spi_config(dev, config);
|
||||
|
||||
if (ret) {
|
||||
spi_context_release(&data->ctx, ret);
|
||||
return ret;
|
||||
LOG_ERR("spi_config failed: %d", ret);
|
||||
goto xfer_end;
|
||||
}
|
||||
|
||||
spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1);
|
||||
|
||||
ret = spi_ambiq_xfer(dev, config);
|
||||
|
||||
xfer_end:
|
||||
spi_context_release(&data->ctx, ret);
|
||||
|
||||
/* Use async put to avoid useless device suspension/resumption
|
||||
* when doing consecutive transmission.
|
||||
*/
|
||||
ret = pm_device_runtime_put_async(dev, K_MSEC(2));
|
||||
if (!pm_ret) {
|
||||
pm_ret = pm_device_runtime_put_async(dev, K_MSEC(2));
|
||||
|
||||
if (ret < 0) {
|
||||
LOG_ERR("pm_device_runtime_put failed: %d", ret);
|
||||
if (pm_ret < 0) {
|
||||
LOG_ERR("pm_device_runtime_put failed: %d", pm_ret);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue