Skip to content

Bugfix/fix bluetooth sal spp interface moudle cb change to const#433

Open
huangyulong3 wants to merge 15 commits intoopen-vela:devfrom
huangyulong3:bugfix/fix_bluetooth_sal_spp_interface_moudle_cb_change_to_const
Open

Bugfix/fix bluetooth sal spp interface moudle cb change to const#433
huangyulong3 wants to merge 15 commits intoopen-vela:devfrom
huangyulong3:bugfix/fix_bluetooth_sal_spp_interface_moudle_cb_change_to_const

Conversation

@huangyulong3
Copy link

Memory Optimization: Change the bluetooth sal spp device interface module to const for reduce the ram size.

bug:v/84958

Rootcause: To reduce RAM resource consumption, the spp_attrs_template and g_rfcomm_ops,
in the sal spp interface module must be marked with the const modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

…k to const for reduce the ram size.

bug: v/84934

Rootcause: To reduce RAM resource consumption, the `adv_callback`
in the ble impl module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…re_gattc_cbs to const for reduce the ram size.

bug: v/84935

Rootcause: To reduce RAM resource consumption, the `s_feature_gattc_cbs`
in the gatt feature module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…v_callback to const for reduce the ram size.

bug: v/84941

Rootcause: To reduce RAM resource consumption, the `g_advertiser_socket_cb`
in the socket advertiser module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…back to const for reduce the ram size.

bug: v/84944

Rootcause: To reduce RAM resource consumption, the `g_advertiser_socket_cb`
in the socket scan module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…ket_cb to const for reduce the ram size.

bug: v/84945

Rootcause: To reduce RAM resource consumption, the `g_spp_socket_cb`
in the socket spp module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…o const for reduce the ram size.

bug:v/84946

Rootcause: To reduce RAM resource consumption, the `deviceInterface`
in the hid device service module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
… for reduce the ram size.

bug:v/84947

Rootcause: To reduce RAM resource consumption, the `sppInterface`
in the spp service module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…o const for reduce the ram size.

bug:v/84950

Rootcause: To reduce RAM resource consumption, the `stream_ops`
in the sal a2dp interface module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…e to const for reduce the ram size.

bug:v/84951

Rootcause: To reduce RAM resource consumption, the `g_conn_cbs`, `g_setting_cbs`,
`g_conn_auth_info_cbs`and `g_br_discovery_cb`,
in the sal adapter interface module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com
…dule to const for reduce the ram size.

bug:v/84952

Rootcause: To reduce RAM resource consumption, the `g_conn_auth_info_cbs`, `g_conn_cbs`,
and `g_setting_cbs` in the sal adapter interface module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…to const for reduce the ram size.

bug:v/84953

Rootcause: To reduce RAM resource consumption, the `avrcp_tg_cbks`,
in the sal avrcp interface module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
… to const for reduce the ram size.

bug:v/84954

Rootcause: To reduce RAM resource consumption, the `g_hfp_ag_cb`,
in the sal hfp ag interface module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
…e to const for reduce the ram size.

bug:v/84956

Rootcause: To reduce RAM resource consumption, the `hf_callbacks`,
in the sal hfp hf interface module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.
…dule to const for reduce the ram size.

bug:v/84957

Rootcause: To reduce RAM resource consumption, the `hid_attrs_template` and `hid_callback`,
in the sal hid device interface module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.
…dule to const for reduce the ram size.

bug:v/84958

Rootcause: To reduce RAM resource consumption, the `spp_attrs_template` and `g_rfcomm_ops`,
in the sal spp interface module must be marked with the `const` modifier.
This ensures it is compiled and linked into Flash memory instead of RAM.

Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a memory optimization by marking callback structure variables as const, ensuring they are placed in Flash memory instead of RAM, reducing RAM usage. The changes affect multiple Bluetooth profile interface files across the SAL (Stack Abstraction Layer) for Zephyr.

Changes:

  • Mark callback structure variables as const in SPP, HID, HFP (HF and AG), AVRCP, A2DP, and adapter interfaces
  • Add explicit casts when passing const pointers to registration functions that expect non-const pointers
  • Add forward declarations in sal_adapter_le_interface.c (though these appear unnecessary)

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
service/stacks/zephyr/sal_spp_interface.c Mark spp_attrs_template and g_rfcomm_ops as const, add cast for ops assignment
service/stacks/zephyr/sal_hid_device_interface.c Mark hid_attrs_template and hid_callback as const, add cast for registration
service/stacks/zephyr/sal_hfp_hf_interface.c Mark hf_callbacks as const, add cast for registration
service/stacks/zephyr/sal_hfp_ag_interface.c Mark g_hfp_ag_cb as const, add cast for registration
service/stacks/zephyr/sal_avrcp_interface.c Mark avrcp_tg_cbks as const
service/stacks/zephyr/sal_adapter_le_interface.c Mark connection and auth callbacks as const, add unnecessary forward declarations, add casts for registrations
service/stacks/zephyr/sal_adapter_interface.c Mark connection, settings, and auth callbacks as const, add casts for registrations
service/stacks/zephyr/sal_a2dp_interface.c Mark sbc_src_ie, stream_ops, and a2dp_cbks as const, add casts for registrations
service/profiles/spp/spp_service.c Mark sppInterface as const
service/profiles/hid/hid_device_service.c Mark deviceInterface as const
service/ipc/socket/src/bt_socket_spp.c Mark g_spp_socket_cb as const, add cast for registration
service/ipc/socket/src/bt_socket_scan.c Mark g_scanner_socket_cb as const, add cast for registration
service/ipc/socket/src/bt_socket_advertiser.c Mark g_advertiser_socket_cb as const, add cast for registration
framework/btwrap/async/bt_gatt_feature.c Mark s_feature_gattc_cbs as const, add casts for registrations
feature/feature_async/src/bluetooth_ble_impl.c Mark adv_callback and gattc_cbs as const, add casts for registrations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

spp_conn->rfcomm_dlc.ops = &g_rfcomm_ops;
spp_conn->rfcomm_dlc.ops = (struct bt_rfcomm_dlc_ops *)&g_rfcomm_ops;
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cast to remove const qualification here is a code smell that indicates the underlying Zephyr API struct field (rfcomm_dlc.ops) should be const-qualified. While this cast is safe in this specific case since the ops pointer is never modified after assignment, it would be better if the Zephyr API struct definition marked this field as const to avoid the need for this cast. This is a pattern repeated throughout the PR for various callback structures. Consider proposing changes to the Zephyr API headers to properly mark these callback fields as const-qualified.

Copilot uses AI. Check for mistakes.
Comment on lines +110 to +112
static le_conn_info_t* le_conn_add(const bt_address_t* addr);
static le_conn_info_t* le_conn_find(const bt_address_t* addr);

Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These forward declarations for le_conn_add and le_conn_find appear to be unnecessary. These function names don't match any functions defined or called in this file. The actual connection management functions used are bt_conn_add, bt_conn_find, and bt_conn_remove which are imported from elsewhere. Consider removing these unused forward declarations.

Suggested change
static le_conn_info_t* le_conn_add(const bt_address_t* addr);
static le_conn_info_t* le_conn_find(const bt_address_t* addr);

Copilot uses AI. Check for mistakes.
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.

1 participant