Skip to content

Commit

Permalink
refactor: remove redundnant NULL check for i2c_master handle
Browse files Browse the repository at this point in the history
  • Loading branch information
pback34 committed Nov 7, 2024
1 parent 3dc85d9 commit a230096
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions components/esp_driver_i2c/i2c_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,30 +790,27 @@ static esp_err_t i2c_master_bus_destroy(i2c_master_bus_handle_t bus_handle)
i2c_common_deinit_pins(i2c_master->base);

if (i2c_release_bus_handle(i2c_master->base) == ESP_OK) {
if (i2c_master) {
if (i2c_master->bus_lock_mux) {
vSemaphoreDeleteWithCaps(i2c_master->bus_lock_mux);
i2c_master->bus_lock_mux = NULL;
}
if (i2c_master->cmd_semphr) {
vSemaphoreDeleteWithCaps(i2c_master->cmd_semphr);
i2c_master->cmd_semphr = NULL;
}
if (i2c_master->event_queue) {
vQueueDeleteWithCaps(i2c_master->event_queue);
}
if (i2c_master->queues_storage) {
free(i2c_master->queues_storage);
}
free(i2c_master->i2c_async_ops);
for (int i = 0; i < I2C_TRANS_QUEUE_MAX; i++) {
if (i2c_master->trans_queues[i]) {
vQueueDelete(i2c_master->trans_queues[i]);
}
if (i2c_master->bus_lock_mux) {
vSemaphoreDeleteWithCaps(i2c_master->bus_lock_mux);
i2c_master->bus_lock_mux = NULL;
}
if (i2c_master->cmd_semphr) {
vSemaphoreDeleteWithCaps(i2c_master->cmd_semphr);
i2c_master->cmd_semphr = NULL;
}
if (i2c_master->event_queue) {
vQueueDeleteWithCaps(i2c_master->event_queue);
}
if (i2c_master->queues_storage) {
free(i2c_master->queues_storage);
}
free(i2c_master->i2c_async_ops);
for (int i = 0; i < I2C_TRANS_QUEUE_MAX; i++) {
if (i2c_master->trans_queues[i]) {
vQueueDelete(i2c_master->trans_queues[i]);
}
bus_handle = NULL;
}

bus_handle = NULL;
free(i2c_master);
} else {
free(i2c_master);
Expand Down

0 comments on commit a230096

Please sign in to comment.