Skip to content

BLE: replace malloc with cordio buffer allocation #8269

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

Merged
merged 8 commits into from
Oct 6, 2018

Conversation

paul-szczepanek-arm
Copy link
Member

@paul-szczepanek-arm paul-szczepanek-arm commented Sep 27, 2018

Description

Event queue used in BLE was using allocating message on the queue from the heap. This causes an error when called from an interrupt context. This replaces the new (which calls malloc) with placement new which uses the provided memory. Memory is provided from a pool belonging to cordio which is where the queue is only used (hence not pulling in any new dependency).

Error discovered using the BLE_GAP example which was used to validate the fix.

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Breaking change

@@ -73,8 +73,8 @@ struct SimpleEventQueue : EventQueue {
if (_ble_base == NULL) {
return false;
}

EventNode* next = new (std::nothrow) EventNode(event);
uint8_t* event_buf = (uint8_t*)WsfBufAlloc(sizeof(EventNode));
Copy link
Member

Choose a reason for hiding this comment

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

  • The NULL check should be made after WsfBufAlloc.
  • placement new accepts a void*. The cast to uint8_t is not required.

Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

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

Could you move SimpleEventQueue into TARGET_CORDIO as this is a cordio implementation ?

Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

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

In the process of moving the basic event queue implementation, could you change its namespace as well: ble::vendor::cordio.

@@ -22,7 +22,7 @@
#include "ble/BLEInstanceBase.h"
#include "ble/generic/GenericGattClient.h"
#include "ble/generic/GenericSecurityManager.h"
#include "ble/pal/SimpleEventQueue.h"
#include "SimpleEventQueue.h"
Copy link
Member

Choose a reason for hiding this comment

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

That's not used by nordic. We can remove that include.

@@ -22,7 +22,7 @@
#include "ble/BLEInstanceBase.h"
#include "ble/generic/GenericGattClient.h"
#include "ble/generic/GenericSecurityManager.h"
#include "ble/pal/SimpleEventQueue.h"
#include "SimpleEventQueue.h"
Copy link
Member

Choose a reason for hiding this comment

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

That's not used by nordic. We can remove that include.

@cmonr
Copy link
Contributor

cmonr commented Sep 27, 2018

@pan- Looks like it's ready for another speed-review.

@paul-szczepanek-arm
Copy link
Member Author

is now

EventNode* next = new (std::nothrow) EventNode(event);
void* event_buf = WsfBufAlloc(sizeof(EventNode));
if (event_buf == NULL) {
error("\r\n%s:%d Cordio WsfBufAlloc out of memory\r\n", __FILE__, __LINE__);
Copy link
Member

Choose a reason for hiding this comment

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

I think that's a leftover for tracing.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's a unrecoverable error, what do you want to do?

@pan-
Copy link
Member

pan- commented Sep 27, 2018

@cmonr looks good now.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 5, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Oct 5, 2018

Build : SUCCESS

Build number : 3250
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/8269/

Triggering tests

/morph test
/morph mbed2-build

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 5, 2018

/morph export-build

@mbed-ci
Copy link

mbed-ci commented Oct 5, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 5, 2018

License issue

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 5, 2018

/morph export-build

@mbed-ci
Copy link

mbed-ci commented Oct 5, 2018

@mbed-ci
Copy link

mbed-ci commented Oct 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants