Skip to content

Fix/uart init error path deinit - #655

Merged
shiliu-yang merged 3 commits into
masterfrom
fix/uart-init-error-path-deinit
Jul 28, 2026
Merged

Fix/uart init error path deinit#655
shiliu-yang merged 3 commits into
masterfrom
fix/uart-init-error-path-deinit

Conversation

@shiliu-yang

Copy link
Copy Markdown
Contributor

PR 描述/PR description

[在此详细描述 PR 的内容]/[Describe the PR content in detail here]

代码质量/Code Quality:

在本次拉取请求中,我已考虑以下事项 As part of this pull request, I've considered the following:

  • 确保代码注释和文档清晰,并使用英文注释以保证代码可读性。Ensure that the code comments and documentation are clear, and use English for comments to ensure code readability.
  • 确保文件头遵循文件头格式。Ensure that the file header follows the File Header Format.
  • 确保函数头遵循 Doxygen 格式。Ensure that function headers follow the Doxygen format as specified in Comments.
  • 已查阅 编码风格指南,并核查代码风格合规性,包括缩进、空格、命名规范及其他风格要求。 Reviewed the Coding Style Guide and verified code style compliance, including indentation, spacing, naming conventions, and other style guidelines.
  • 已使用代码格式化工具确保符合 TuyaOpen 编码规范。Have used the code-formatting source code formatting tool to ensure compliance with TuyaOpen coding standards.

tkl_ble_gatts_service_add() returned early on invalid parameters and
allocation failures without releasing the service/characteristic UUIDs
already allocated in the same call, and never checked the results of
tal_malloc()/tuya_ble_hs_malloc().

- extract tuya_ble_gatts_uuid_free() and share it between the stack
  deinit path and the new exit_cleanup path
- check every allocation and reject unknown UUID types explicitly
- clear tuya_gatt_svcs / read_char buffer pointers after freeing so a
  second deinit cannot double free
- bound char_num per service instead of accumulating across services,
  which could overflow a tuya_gatt_chars row
Once tkl_uart_init() succeeded, every later failure in tal_uart_init()
jumped to ERR_EXIT, and uart_free_source() only releases TAL level
objects. The lower layer stayed initialized: on the Linux adapter that
leaks a file descriptor and the IRQ thread started by tkl_uart_init().

- track whether tkl_uart_init() succeeded and call tkl_uart_deinit()
  from ERR_EXIT before uart_free_source()
- handle uart_list_add_one_node() failure, which previously returned an
  error while leaving the port initialized and the node off the list,
  where tal_uart_deinit() could never reclaim it
- tal_cli_init_with_uart(): call tal_uart_deinit() when the CLI thread
  cannot be created after the UART came up, and add the missing format
  specifier to the uart init failure log

Fixes #632
@shiliu-yang
shiliu-yang merged commit b637384 into master Jul 28, 2026
2 checks passed
@shiliu-yang
shiliu-yang deleted the fix/uart-init-error-path-deinit branch July 28, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants