From 0fe3281713238483fba07e7face15bd9846f6a88 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 14 Mar 2022 18:42:45 +0100 Subject: [PATCH 1/3] driver: fix issues reported by PVS-Studio https://www.viva64.com/en/b/0790/#ID88049D3FA2 https://www.viva64.com/en/b/0790/#IDE0890EE01C Reported in https://github.com/espressif/esp-idf/issues/6440 --- components/driver/ledc.c | 8 ++++++-- components/driver/sdio_slave.c | 4 ---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/driver/ledc.c b/components/driver/ledc.c index a753405671..6bec8b05e7 100644 --- a/components/driver/ledc.c +++ b/components/driver/ledc.c @@ -942,15 +942,19 @@ static esp_err_t ledc_fade_channel_init_check(ledc_mode_t speed_mode, ledc_chann if (s_ledc_fade_rec[speed_mode][channel] == NULL) { #if CONFIG_SPIRAM_USE_MALLOC s_ledc_fade_rec[speed_mode][channel] = (ledc_fade_t *) heap_caps_calloc(1, sizeof(ledc_fade_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); - if (!s_ledc_fade_rec[speed_mode][channel]) { + if (s_ledc_fade_rec[speed_mode][channel] == NULL) { ledc_fade_channel_deinit(speed_mode, channel); - return ESP_FAIL; + return ESP_ERR_NO_MEM; } memset(&s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem_storage, 0, sizeof(StaticQueue_t)); s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem = xSemaphoreCreateBinaryStatic(&s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem_storage); #else s_ledc_fade_rec[speed_mode][channel] = (ledc_fade_t *) calloc(1, sizeof(ledc_fade_t)); + if (s_ledc_fade_rec[speed_mode][channel] == NULL) { + ledc_fade_channel_deinit(speed_mode, channel); + return ESP_ERR_NO_MEM; + } s_ledc_fade_rec[speed_mode][channel]->ledc_fade_sem = xSemaphoreCreateBinary(); #endif s_ledc_fade_rec[speed_mode][channel]->ledc_fade_mux = xSemaphoreCreateMutex(); diff --git a/components/driver/sdio_slave.c b/components/driver/sdio_slave.c index db0913dc72..a987dc2fbf 100644 --- a/components/driver/sdio_slave.c +++ b/components/driver/sdio_slave.c @@ -403,10 +403,6 @@ esp_err_t sdio_slave_start(void) critical_enter_recv(); sdio_slave_hal_recv_start(context.hal); critical_exit_recv(); - ret = ESP_OK; - if (ret != ESP_OK) { - return ret; - } sdio_slave_hal_set_ioready(context.hal, true); return ESP_OK; From 6a4a6d584bf7a57cbcccc46555a01b594ec73aa7 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 14 Mar 2022 18:44:07 +0100 Subject: [PATCH 2/3] essl: fix logical bug in argument check https://pvs-studio.com/en/blog/posts/cpp/0790/#IDBDD4F1FD2D Reported in https://github.com/espressif/esp-idf/issues/6440 --- components/esp_serial_slave_link/essl_sdio.c | 20 ++++++-------------- tools/ci/check_copyright_ignore.txt | 1 - 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/components/esp_serial_slave_link/essl_sdio.c b/components/esp_serial_slave_link/essl_sdio.c index 58b6e75a47..56ac197abd 100644 --- a/components/esp_serial_slave_link/essl_sdio.c +++ b/components/esp_serial_slave_link/essl_sdio.c @@ -1,16 +1,8 @@ -// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include "essl_sdio.h" #include "esp_log.h" @@ -206,7 +198,7 @@ esp_err_t essl_sdio_init(void *arg, uint32_t wait_ms) ESP_LOGD(TAG, "Function 0 BS: %04x", (int) bs_read); // Set block sizes for functions 1 to given value (default value = 512). - if (ctx->block_size > 0 || ctx->block_size <= 2048) { + if (ctx->block_size > 0 && ctx->block_size <= 2048) { bs = ctx->block_size; } else { bs = 512; diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 965ecac3df..9bd4b6a20a 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -672,7 +672,6 @@ components/esp_rom/test/test_miniz.c components/esp_rom/test/test_tjpgd.c components/esp_serial_slave_link/essl.c components/esp_serial_slave_link/essl_internal.h -components/esp_serial_slave_link/essl_sdio.c components/esp_serial_slave_link/include/esp_serial_slave_link/essl.h components/esp_serial_slave_link/include/esp_serial_slave_link/essl_sdio.h components/esp_serial_slave_link/include/esp_serial_slave_link/essl_spi.h From 12717cbc0040485e063134ddc4e4f69b957810b3 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 14 Mar 2022 18:45:40 +0100 Subject: [PATCH 3/3] hal: fix issues reported by PVS-Studio https://www.viva64.com/en/b/0790/#ID369075A8F4 https://www.viva64.com/en/b/0790/#IDF03E449184 Reported in https://github.com/espressif/esp-idf/issues/6440 --- .../hal/esp32/include/hal/spi_flash_ll.h | 20 ++++++------------ components/hal/esp32/touch_sensor_hal.c | 21 +++++++------------ tools/ci/check_copyright_ignore.txt | 2 -- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/components/hal/esp32/include/hal/spi_flash_ll.h b/components/hal/esp32/include/hal/spi_flash_ll.h index 3f18774a29..e3f02d3d07 100644 --- a/components/hal/esp32/include/hal/spi_flash_ll.h +++ b/components/hal/esp32/include/hal/spi_flash_ll.h @@ -1,16 +1,8 @@ -// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /******************************************************************************* * NOTICE @@ -370,7 +362,7 @@ static inline void spi_flash_ll_set_usr_address(spi_dev_t *dev, uint32_t addr, i dev->addr = addr; dev->slv_wr_status = UINT32_MAX; } else { - uint32_t padding_ones = (bit_len == 32? 0 : UINT32_MAX >> bit_len); + uint32_t padding_ones = UINT32_MAX >> bit_len; dev->addr = (addr << (32 - bit_len)) | padding_ones; } } diff --git a/components/hal/esp32/touch_sensor_hal.c b/components/hal/esp32/touch_sensor_hal.c index 59a10e5150..d74a6686dd 100644 --- a/components/hal/esp32/touch_sensor_hal.c +++ b/components/hal/esp32/touch_sensor_hal.c @@ -1,16 +1,8 @@ -// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ // The HAL layer for Touch sensor (common part) @@ -46,6 +38,7 @@ void touch_hal_get_wakeup_status(touch_pad_t *pad_num) touch_ll_read_trigger_status_mask(&touch_mask); if (touch_mask == 0) { *pad_num = -1; + } else { + *pad_num = (touch_pad_t)(__builtin_ffs(touch_mask) - 1); } - *pad_num = (touch_pad_t)(__builtin_ffs(touch_mask) - 1); } diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 9bd4b6a20a..195bf53d54 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -832,14 +832,12 @@ components/hal/esp32/include/hal/sha_ll.h components/hal/esp32/include/hal/sigmadelta_ll.h components/hal/esp32/include/hal/soc_ll.h components/hal/esp32/include/hal/spi_flash_encrypted_ll.h -components/hal/esp32/include/hal/spi_flash_ll.h components/hal/esp32/include/hal/touch_sensor_hal.h components/hal/esp32/include/hal/touch_sensor_ll.h components/hal/esp32/include/hal/trace_ll.h components/hal/esp32/include/hal/twai_ll.h components/hal/esp32/include/hal/uart_ll.h components/hal/esp32/interrupt_descriptor_table.c -components/hal/esp32/touch_sensor_hal.c components/hal/esp32c3/hmac_hal.c components/hal/esp32c3/include/hal/adc_hal_conf.h components/hal/esp32c3/include/hal/aes_ll.h