Skip to content

Commit fd8abcf

Browse files
utsavm9kartben
authored andcommitted
portability: cmsis: Avoid copying objects names into control block
Instead, just store the pointer to the string provided as part of the RTOS object init attributes. Signed-off-by: Utsav Munendra <[email protected]>
1 parent e676bf3 commit fd8abcf

File tree

7 files changed

+34
-55
lines changed

7 files changed

+34
-55
lines changed

include/zephyr/portability/cmsis_types.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#include <zephyr/kernel.h>
1212
#include <zephyr/portability/cmsis_os2.h>
1313

14-
/** @brief Size for names of RTOS objects. */
15-
#define CMSIS_OBJ_NAME_MAX_LEN 16
16-
1714
/**
1815
* @brief Control block for a CMSIS-RTOSv2 thread.
1916
*
@@ -40,7 +37,7 @@ struct cmsis_rtos_timer_cb {
4037
osTimerType_t type;
4138
uint32_t status;
4239
bool is_cb_dynamic_allocation;
43-
char name[CMSIS_OBJ_NAME_MAX_LEN];
40+
const char *name;
4441
void (*callback_function)(void *argument);
4542
void *arg;
4643
};
@@ -54,7 +51,7 @@ struct cmsis_rtos_timer_cb {
5451
struct cmsis_rtos_mutex_cb {
5552
struct k_mutex z_mutex;
5653
bool is_cb_dynamic_allocation;
57-
char name[CMSIS_OBJ_NAME_MAX_LEN];
54+
const char *name;
5855
uint32_t state;
5956
};
6057

@@ -67,7 +64,7 @@ struct cmsis_rtos_mutex_cb {
6764
struct cmsis_rtos_semaphore_cb {
6865
struct k_sem z_semaphore;
6966
bool is_cb_dynamic_allocation;
70-
char name[CMSIS_OBJ_NAME_MAX_LEN];
67+
const char *name;
7168
};
7269

7370
/**
@@ -81,7 +78,7 @@ struct cmsis_rtos_mempool_cb {
8178
void *pool;
8279
char is_dynamic_allocation;
8380
bool is_cb_dynamic_allocation;
84-
char name[CMSIS_OBJ_NAME_MAX_LEN];
81+
const char *name;
8582
};
8683

8784
/**
@@ -95,7 +92,7 @@ struct cmsis_rtos_msgq_cb {
9592
void *pool;
9693
char is_dynamic_allocation;
9794
bool is_cb_dynamic_allocation;
98-
char name[CMSIS_OBJ_NAME_MAX_LEN];
95+
const char *name;
9996
};
10097

10198
/**
@@ -109,7 +106,7 @@ struct cmsis_rtos_event_cb {
109106
struct k_poll_event poll_event;
110107
uint32_t signal_results;
111108
bool is_cb_dynamic_allocation;
112-
char name[CMSIS_OBJ_NAME_MAX_LEN];
109+
const char *name;
113110
};
114111

115112
#endif

subsys/portability/cmsis_rtos_v2/event_flags.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr)
5050
&events->poll_signal);
5151
events->signal_results = 0U;
5252

53-
if (attr->name == NULL) {
54-
strncpy(events->name, init_event_flags_attrs.name, sizeof(events->name) - 1);
55-
} else {
56-
strncpy(events->name, attr->name, sizeof(events->name) - 1);
57-
}
53+
events->name = (attr->name == NULL) ? init_event_flags_attrs.name : attr->name;
5854

5955
return (osEventFlagsId_t)events;
6056
}
@@ -207,16 +203,16 @@ uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t optio
207203

208204
/**
209205
* @brief Get name of an Event Flags object.
206+
* This function may be called from Interrupt Service Routines.
210207
*/
211208
const char *osEventFlagsGetName(osEventFlagsId_t ef_id)
212209
{
213210
struct cmsis_rtos_event_cb *events = (struct cmsis_rtos_event_cb *)ef_id;
214211

215-
if (!k_is_in_isr() && (ef_id != NULL)) {
216-
return events->name;
217-
} else {
212+
if (events == NULL) {
218213
return NULL;
219214
}
215+
return events->name;
220216
}
221217

222218
/**

subsys/portability/cmsis_rtos_v2/mempool.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size,
8484
return NULL;
8585
}
8686

87-
if (attr->name == NULL) {
88-
strncpy(mslab->name, init_mslab_attrs.name, sizeof(mslab->name) - 1);
89-
} else {
90-
strncpy(mslab->name, attr->name, sizeof(mslab->name) - 1);
91-
}
87+
mslab->name = (attr->name == NULL) ? init_mslab_attrs.name : attr->name;
9288

9389
return (osMemoryPoolId_t)mslab;
9490
}
@@ -152,16 +148,16 @@ osStatus_t osMemoryPoolFree(osMemoryPoolId_t mp_id, void *block)
152148

153149
/**
154150
* @brief Get name of a Memory Pool object.
151+
* This function may be called from Interrupt Service Routines.
155152
*/
156153
const char *osMemoryPoolGetName(osMemoryPoolId_t mp_id)
157154
{
158155
struct cmsis_rtos_mempool_cb *mslab = (struct cmsis_rtos_mempool_cb *)mp_id;
159156

160-
if (!k_is_in_isr() && (mslab != NULL)) {
161-
return mslab->name;
162-
} else {
157+
if (mslab == NULL) {
163158
return NULL;
164159
}
160+
return mslab->name;
165161
}
166162

167163
/**

subsys/portability/cmsis_rtos_v2/msgq.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
7979

8080
k_msgq_init(&msgq->z_msgq, msgq->pool, msg_size, msg_count);
8181

82-
if (attr->name == NULL) {
83-
strncpy(msgq->name, init_msgq_attrs.name, sizeof(msgq->name) - 1);
84-
} else {
85-
strncpy(msgq->name, attr->name, sizeof(msgq->name) - 1);
86-
}
82+
msgq->name = (attr->name == NULL) ? init_msgq_attrs.name : attr->name;
8783

8884
return (osMessageQueueId_t)(msgq);
8985
}
@@ -222,16 +218,16 @@ uint32_t osMessageQueueGetSpace(osMessageQueueId_t msgq_id)
222218

223219
/**
224220
* @brief Get name of a Message Queue object.
221+
* This function may be called from Interrupt Service Routines.
225222
*/
226223
const char *osMessageQueueGetName(osMessageQueueId_t msgq_id)
227224
{
228225
struct cmsis_rtos_msgq_cb *msgq = (struct cmsis_rtos_msgq_cb *)msgq_id;
229226

230-
if (!k_is_in_isr() && (msgq_id != NULL)) {
231-
return msgq->name;
232-
} else {
227+
if (msgq == NULL) {
233228
return NULL;
234229
}
230+
return msgq->name;
235231
}
236232

237233
/**

subsys/portability/cmsis_rtos_v2/mutex.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ osMutexId_t osMutexNew(const osMutexAttr_t *attr)
5151
k_mutex_init(&mutex->z_mutex);
5252
mutex->state = attr->attr_bits;
5353

54-
if (attr->name == NULL) {
55-
strncpy(mutex->name, init_mutex_attrs.name, sizeof(mutex->name) - 1);
56-
} else {
57-
strncpy(mutex->name, attr->name, sizeof(mutex->name) - 1);
58-
}
54+
mutex->name = (attr->name == NULL) ? init_mutex_attrs.name : attr->name;
5955

6056
return (osMutexId_t)mutex;
6157
}
@@ -156,13 +152,16 @@ osThreadId_t osMutexGetOwner(osMutexId_t mutex_id)
156152
return get_cmsis_thread_id(mutex->z_mutex.owner);
157153
}
158154

155+
/**
156+
* @brief Get name of a mutex.
157+
* This function may be called from Interrupt Service Routines.
158+
*/
159159
const char *osMutexGetName(osMutexId_t mutex_id)
160160
{
161161
struct cmsis_rtos_mutex_cb *mutex = (struct cmsis_rtos_mutex_cb *)mutex_id;
162162

163-
if (k_is_in_isr() || (mutex == NULL)) {
163+
if (mutex == NULL) {
164164
return NULL;
165165
}
166-
167166
return mutex->name;
168167
}

subsys/portability/cmsis_rtos_v2/semaphore.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count,
4747

4848
k_sem_init(&semaphore->z_semaphore, initial_count, max_count);
4949

50-
if (attr->name == NULL) {
51-
strncpy(semaphore->name, init_sema_attrs.name, sizeof(semaphore->name) - 1);
52-
} else {
53-
strncpy(semaphore->name, attr->name, sizeof(semaphore->name) - 1);
54-
}
50+
semaphore->name = (attr->name == NULL) ? init_sema_attrs.name : attr->name;
5551

5652
return (osSemaphoreId_t)semaphore;
5753
}
@@ -148,13 +144,16 @@ osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
148144
return osOK;
149145
}
150146

147+
/**
148+
* @brief Get name of a semaphore.
149+
* This function may be called from Interrupt Service Routines.
150+
*/
151151
const char *osSemaphoreGetName(osSemaphoreId_t semaphore_id)
152152
{
153153
struct cmsis_rtos_semaphore_cb *semaphore = (struct cmsis_rtos_semaphore_cb *)semaphore_id;
154154

155-
if (!k_is_in_isr() && (semaphore_id != NULL)) {
156-
return semaphore->name;
157-
} else {
155+
if (semaphore == NULL) {
158156
return NULL;
159157
}
158+
return semaphore->name;
160159
}

subsys/portability/cmsis_rtos_v2/timer.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument,
6767

6868
k_timer_init(&timer->z_timer, zephyr_timer_wrapper, NULL);
6969

70-
if (attr->name == NULL) {
71-
strncpy(timer->name, init_timer_attrs.name, sizeof(timer->name) - 1);
72-
} else {
73-
strncpy(timer->name, attr->name, sizeof(timer->name) - 1);
74-
}
70+
timer->name = (attr->name == NULL) ? init_timer_attrs.name : attr->name;
7571

7672
return (osTimerId_t)timer;
7773
}
@@ -153,15 +149,15 @@ osStatus_t osTimerDelete(osTimerId_t timer_id)
153149

154150
/**
155151
* @brief Get name of a timer.
152+
* This function may be called from Interrupt Service Routines.
156153
*/
157154
const char *osTimerGetName(osTimerId_t timer_id)
158155
{
159156
struct cmsis_rtos_timer_cb *timer = (struct cmsis_rtos_timer_cb *)timer_id;
160157

161-
if (k_is_in_isr() || (timer == NULL)) {
158+
if (timer == NULL) {
162159
return NULL;
163160
}
164-
165161
return timer->name;
166162
}
167163

0 commit comments

Comments
 (0)