Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: rpc: openthread: dynamic allocation for CLI commands #19320

Merged
merged 2 commits into from
Dec 23, 2024

Conversation

kderda
Copy link
Contributor

@kderda kderda commented Dec 6, 2024

No description provided.

@kderda kderda requested review from a team as code owners December 6, 2024 11:35
@github-actions github-actions bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Dec 6, 2024
@NordicBuilder
Copy link
Contributor

NordicBuilder commented Dec 6, 2024

CI Information

To view the history of this post, clich the 'edited' button above
Build number: 7

Inputs:

Sources:

sdk-nrf: PR head: 93d84930d87841bdcb4d3f8148d23181a7fc47ad

more details

sdk-nrf:

PR head: 93d84930d87841bdcb4d3f8148d23181a7fc47ad
merge base: d9500b94b05c776294fda96ebb0baaedb553a47e
target head (main): 6266884de899a254b7f09868d6ad4947d0dfc879
Diff

Github labels

Enabled Name Description
ci-disabled Disable the ci execution
ci-all-test Run all of ci, no test spec filtering will be done
ci-force-downstream Force execution of downstream even if twister fails
ci-run-twister Force run twister
ci-run-zephyr-twister Force run zephyr twister
List of changed files detected by CI (3)
include
│  ├── nrf_rpc
│  │  │ nrf_rpc_serialize.h
subsys
│  ├── net
│  │  ├── openthread
│  │  │  ├── rpc
│  │  │  │  ├── server
│  │  │  │  │  │ ot_rpc_cli.c
│  ├── nrf_rpc
│  │  │ nrf_rpc_serialize.c

Outputs:

Toolchain

Version: b77d8c1312
Build docker image: docker-dtr.nordicsemi.no/sw-production/ncs-build:b77d8c1312_912848a074

Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped; ⚠️ Quarantine

  • ◻️ Toolchain - Skipped: existing toolchain is used
  • ✅ Build twister - Skipped: Skipping Build & Test as it succeeded in a previous run: 6
  • ✅ Integration tests
    • ✅ test_ble_nrf_config
    • ✅ test-fw-nrfconnect-ble_samples - Skipped: Job was skipped as it succeeded in a previous run
    • ✅ test-fw-nrfconnect-rpc - Skipped: Job was skipped as it succeeded in a previous run
    • ✅ test-fw-nrfconnect-rs - Skipped: Job was skipped as it succeeded in a previous run
    • ✅ test-fw-nrfconnect-fem - Skipped: Job was skipped as it succeeded in a previous run
    • ✅ test-fw-nrfconnect-thread - Skipped: Job was skipped as it succeeded in a previous run
    • ✅ test-sdk-dfu - Skipped: Job was skipped as it succeeded in a previous run
    • ✅ test-fw-nrfconnect-ps - Skipped: Job was skipped as it succeeded in a previous run
Disabled integration tests
    • desktop52_verification
    • doc-internal
    • test-fw-nrfconnect-apps
    • test-fw-nrfconnect-ble_mesh
    • test-fw-nrfconnect-boot
    • test-fw-nrfconnect-chip
    • test-fw-nrfconnect-nfc
    • test-fw-nrfconnect-nrf-iot_libmodem-nrf
    • test-fw-nrfconnect-nrf-iot_lwm2m
    • test-fw-nrfconnect-nrf-iot_mosh
    • test-fw-nrfconnect-nrf-iot_nrf_provisioning
    • test-fw-nrfconnect-nrf-iot_positioning
    • test-fw-nrfconnect-nrf-iot_samples
    • test-fw-nrfconnect-nrf-iot_serial_lte_modem
    • test-fw-nrfconnect-nrf-iot_thingy91
    • test-fw-nrfconnect-nrf-iot_zephyr_lwm2m
    • test-fw-nrfconnect-nrf_crypto
    • test-fw-nrfconnect-tfm
    • test-fw-nrfconnect-zigbee
    • test-low-level
    • test-sdk-audio
    • test-sdk-find-my
    • test-sdk-mcuboot
    • test-sdk-pmic-samples
    • test-sdk-sidewalk
    • test-sdk-wifi
    • test-secdom-samples-public

Note: This message is automatically posted and updated by the CI

@NordicBuilder
Copy link
Contributor

You can find the documentation preview for this PR at this link. It will be updated about 10 minutes after the documentation build succeeds.

Note: This comment is automatically posted by the Documentation Publish GitHub Action.

@@ -232,7 +232,7 @@ char *nrf_rpc_decode_str(struct nrf_rpc_cbor_ctx *ctx, char *buffer, size_t buff
/** @brief Decode a string pointer and length. Moves CBOR pointer past string on success.
*
* @param[in,out] ctx CBOR decoding context.
* @param[out] size String length.
* @param[out] len String length.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be corrected in the first commit that introduces nrf_rpc_decode_str_ptr_and_len(), not here where dynamic allocation is added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 79 to 91
if (ptr) {
buffer = malloc(len + 1);
if (buffer) {
memcpy(buffer, ptr, len);
buffer[len] = '\0';
}
}

if (!nrf_rpc_decoding_done_and_check(group, ctx)) {
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_CLI_INPUT_LINE);
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

The function can return here without freeing buffer. Is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed

memcpy(buffer, ptr, len);
buffer[len] = '\0';
}
}

if (!nrf_rpc_decoding_done_and_check(group, ctx)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not move this before the allocation and copying which turn out to be unnecessary when this fails? This extra call to free would not be needed then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nrf_rpc_decoding_done_and_check() frees the buffer which holds the data to be stored in the buffer.

Copy link
Contributor

@pdunaj pdunaj left a comment

Choose a reason for hiding this comment

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

checked nrf_rpc commit

This commit adds new helper function nrf_rpc_decode_str_ptr_and_len()
that decodes CBOR string without copying it to a buffer. It allows to
get string length before buffer allocation.

Signed-off-by: Konrad Derda <[email protected]>
CLI commands may require large buffer for command strings. This commit
introduces usage of dynamic allocation to avoid usage of huge static
buffer.

Signed-off-by: Konrad Derda <[email protected]>
@nordicjm nordicjm merged commit 7f5d9d4 into nrfconnect:main Dec 23, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants