diff --git a/fs/shm/shmfs_alloc.c b/fs/shm/shmfs_alloc.c index 4764c901e6849..740113d7c1b56 100644 --- a/fs/shm/shmfs_alloc.c +++ b/fs/shm/shmfs_alloc.c @@ -51,24 +51,34 @@ FAR struct shmfs_object_s *shmfs_alloc_object(size_t length) * chunk in kernel heap */ - object = fs_heap_zalloc(sizeof(struct shmfs_object_s)); - if (object) + size_t alloc_size; + size_t cachesize = up_get_dcache_linesize(); + + if (cachesize > 0) { - size_t cachesize = up_get_dcache_linesize(); - if (cachesize > 0) + alloc_size = + ALIGN_UP(sizeof(struct shmfs_object_s), cachesize) + + ALIGN_UP(length, cachesize); + object = fs_heap_memalign(cachesize, alloc_size); + if (object) { - object->paddr = fs_heap_memalign(cachesize, - ALIGN_UP(length, cachesize)); + memset(object, 0, alloc_size); + object->paddr = (void *)((uintptr_t)object + cachesize); } - else + } + else + { + alloc_size = sizeof(struct shmfs_object_s) + length; + object = fs_heap_zalloc(alloc_size); + if (object) { - object->paddr = fs_heap_malloc(length); + object->paddr = (FAR char *)(object + 1); } + } - if (object->paddr) - { - allocated = true; - } + if (object->paddr) + { + allocated = true; } #elif defined(CONFIG_BUILD_PROTECTED) @@ -152,9 +162,7 @@ void shmfs_free_object(FAR struct shmfs_object_s *object) { if (object) { -#if defined(CONFIG_BUILD_FLAT) - fs_heap_free(object->paddr); -#elif defined(CONFIG_BUILD_PROTECTED) +#if defined(CONFIG_BUILD_PROTECTED) kumm_free(object->paddr); #elif defined(CONFIG_BUILD_KERNEL) size_t i;