mm/kmm_heap/kmm_sem : Add null check of kheap for avoiding dereferencing
In kmm sem APIs, heap pointer can be NULL sometimes.
To avoid dereferencing, add null checking.
************************************************************************/
#include <tinyara/config.h>
+#include <debug.h>
+#include <errno.h>
#include <tinyara/mm/mm.h>
int kmm_trysemaphore(void *dummy_addr)
{
struct mm_heap_s *kheap = mm_get_heap(dummy_addr);
+ if (kheap) {
return mm_trysemaphore(kheap);
}
+ mdbg("Invalid Heap address given, Fail to try to take sem.\n");
+ return -EFAULT;
+}
/************************************************************************
* Name: kmm_givesemaphore
@@ -115,7 +121,11 @@ int kmm_trysemaphore(void *dummy_addr)
void kmm_givesemaphore(void *dummy_addr)
{
struct mm_heap_s *kheap = mm_get_heap(dummy_addr);
- return mm_givesemaphore(kheap);
+ if (kheap) {
+ mm_givesemaphore(kheap);
+ } else {
+ mdbg("Invalid Heap address given, Fail to give sem.\n");
+ }
}
#endif /* CONFIG_MM_KERNEL_HEAP */
