Skip to content

Commit c7467f0

Browse files
Nicolas Pitrekartben
authored andcommitted
ring_buffer: constify some arguments
Functions that don't modify content should have pointers to it marked const. Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
1 parent e1eead3 commit c7467f0

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

include/zephyr/sys/ring_buffer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static inline void ring_buf_item_init(struct ring_buf *buf,
209209
*
210210
* @return true if the ring buffer is empty, or false if not.
211211
*/
212-
static inline bool ring_buf_is_empty(struct ring_buf *buf)
212+
static inline bool ring_buf_is_empty(const struct ring_buf *buf)
213213
{
214214
return buf->get.head == buf->put.tail;
215215
}
@@ -231,7 +231,7 @@ static inline void ring_buf_reset(struct ring_buf *buf)
231231
*
232232
* @return Ring buffer free space (in bytes).
233233
*/
234-
static inline uint32_t ring_buf_space_get(struct ring_buf *buf)
234+
static inline uint32_t ring_buf_space_get(const struct ring_buf *buf)
235235
{
236236
ring_buf_idx_t allocated = buf->put.head - buf->get.tail;
237237

@@ -245,7 +245,7 @@ static inline uint32_t ring_buf_space_get(struct ring_buf *buf)
245245
*
246246
* @return Ring buffer free space (in 32-bit words).
247247
*/
248-
static inline uint32_t ring_buf_item_space_get(struct ring_buf *buf)
248+
static inline uint32_t ring_buf_item_space_get(const struct ring_buf *buf)
249249
{
250250
return ring_buf_space_get(buf) / 4;
251251
}
@@ -257,7 +257,7 @@ static inline uint32_t ring_buf_item_space_get(struct ring_buf *buf)
257257
*
258258
* @return Ring buffer capacity (in bytes).
259259
*/
260-
static inline uint32_t ring_buf_capacity_get(struct ring_buf *buf)
260+
static inline uint32_t ring_buf_capacity_get(const struct ring_buf *buf)
261261
{
262262
return buf->size;
263263
}
@@ -269,7 +269,7 @@ static inline uint32_t ring_buf_capacity_get(struct ring_buf *buf)
269269
*
270270
* @return Ring buffer data size (in bytes).
271271
*/
272-
static inline uint32_t ring_buf_size_get(struct ring_buf *buf)
272+
static inline uint32_t ring_buf_size_get(const struct ring_buf *buf)
273273
{
274274
ring_buf_idx_t available = buf->put.tail - buf->get.head;
275275

subsys/net/lib/lwm2m/lwm2m_registry.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,13 +1723,11 @@ size_t lwm2m_cache_size(const struct lwm2m_time_series_resource *cache_entry)
17231723
#if defined(CONFIG_LWM2M_RESOURCE_DATA_CACHE_SUPPORT)
17241724
uint32_t bytes_available;
17251725

1726-
/* ring_buf_is_empty() takes non-const pointer but still does not modify */
1727-
if (ring_buf_is_empty((struct ring_buf *) &cache_entry->rb)) {
1726+
if (ring_buf_is_empty(&cache_entry->rb)) {
17281727
return 0;
17291728
}
17301729

1731-
/* ring_buf_size_get() takes non-const pointer but still does not modify */
1732-
bytes_available = ring_buf_size_get((struct ring_buf *) &cache_entry->rb);
1730+
bytes_available = ring_buf_size_get(&cache_entry->rb);
17331731

17341732
return (bytes_available / sizeof(struct lwm2m_time_series_elem));
17351733
#else

0 commit comments

Comments
 (0)