summaryrefslogtreecommitdiff
path: root/sys/dev/raidframe/rf_debugMem.h
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2019-02-09 03:33:59 +0000
committerchristos <christos@NetBSD.org>2019-02-09 03:33:59 +0000
commitf9496794ff5670818d14b58cb9ffda8f702eaed7 (patch)
tree44b46fe0fb83d0c2f7514745778b296e33474227 /sys/dev/raidframe/rf_debugMem.h
parent96d63dcbe0bd602859527fcd9c280042831fea01 (diff)
- Change the allocation macros to be more like function calls
- Change sizeof(type) -> sizeof(*variable) - Use macros for the long buffer length allocations - Remove "bit polishing" memsets() -- do them only once - Remove unnecessary casts Thanks to oster@ for finding bugs and testing.
Diffstat (limited to 'sys/dev/raidframe/rf_debugMem.h')
-rw-r--r--sys/dev/raidframe/rf_debugMem.h77
1 files changed, 42 insertions, 35 deletions
diff --git a/sys/dev/raidframe/rf_debugMem.h b/sys/dev/raidframe/rf_debugMem.h
index 0ab17cae6c6..62875c223d8 100644
--- a/sys/dev/raidframe/rf_debugMem.h
+++ b/sys/dev/raidframe/rf_debugMem.h
@@ -1,4 +1,4 @@
-/* $NetBSD: rf_debugMem.h,v 1.13 2011/05/01 06:49:43 mrg Exp $ */
+/* $NetBSD: rf_debugMem.h,v 1.14 2019/02/09 03:34:00 christos Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
* All rights reserved.
@@ -42,47 +42,54 @@
#include <sys/types.h>
#include <sys/malloc.h>
-#ifndef RF_DEBUG_MEM
-#define RF_DEBUG_MEM 0
-#endif
+int rf_ConfigureDebugMem(RF_ShutdownList_t **);
-#if RF_DEBUG_MEM
-#define RF_Malloc(_p_, _size_, _cast_) \
- { \
- _p_ = _cast_ malloc((u_long)_size_, M_RAIDFRAME, M_WAITOK); \
- memset((char *)_p_, 0, _size_); \
- if (rf_memDebug) rf_record_malloc(_p_, _size_, __LINE__, __FILE__); \
- }
+#ifndef RF_DEBUG_MEM
+# define RF_DEBUG_MEM 0
+# define RF_Malloc(s) malloc(s, M_RAIDFRAME, M_WAITOK | M_ZERO)
+# define RF_Free(p, s) free(p, M_RAIDFRAME)
+# define RF_MallocAndAdd(s, l) _RF_MallocAndAdd(s, l)
#else
-#define RF_Malloc(_p_, _size_, _cast_) \
- { \
- _p_ = _cast_ malloc((u_long)_size_, M_RAIDFRAME, M_WAITOK); \
- memset((char *)_p_, 0, _size_); \
- }
-#endif
+extern long rf_memDebug;
+
+void rf_record_malloc(void *, size_t, const char *, uint32_t);
+void rf_unrecord_malloc(void *, size_t);
+void rf_print_unfreed(void);
-#define RF_MallocAndAdd(__p_, __size_, __cast_, __alist_) \
- { \
- RF_Malloc(__p_, __size_, __cast_); \
- if (__alist_) rf_AddToAllocList(__alist_, __p_, __size_); \
+# define RF_Malloc(s) _RF_Malloc(s, __FILE__, __LINE__)
+# define RF_MallocAndAdd(s, l) \
+ _RF_MallocAndAdd(s, l, __FILE__, __LINE__)
+
+static __inline void *
+_RF_Malloc(size_t size, const char *file, uint32_t line)
+{
+ void *p = malloc(size, M_RAIDFRAME, M_WAITOK | M_ZERO);
+ if (rf_memDebug) rf_record_malloc(p, size, file, line);
+ return p;
+}
+
+static __inline void
+RF_Free(void *p, size_t size)
+{
+ free(p, M_RAIDFRAME);
+ if (rf_memDebug) rf_unrecord_malloc(p, size);
}
+#endif
+static __inline void *
+_RF_MallocAndAdd(size_t size, RF_AllocListElem_t *l
#if RF_DEBUG_MEM
-#define RF_Free(_p_, _sz_) \
- { \
- free((void *)(_p_), M_RAIDFRAME); \
- if (rf_memDebug) rf_unrecord_malloc(_p_, (u_int32_t) (_sz_)); \
- }
-#else
-#define RF_Free(_p_, _sz_) \
- { \
- free((void *)(_p_), M_RAIDFRAME); \
- }
+ , const char *file, uint32_t line
+#endif
+)
+{
+ void *p = malloc(size, M_RAIDFRAME, M_WAITOK | M_ZERO);
+#if RF_DEBUG_MEM
+ if (rf_memDebug) rf_record_malloc(p, size, file, line);
#endif
+ if (l) rf_AddToAllocList(l, p, size);
+ return p;
+}
-void rf_record_malloc(void *p, int size, int line, const char *filen);
-void rf_unrecord_malloc(void *p, int sz);
-void rf_print_unfreed(void);
-int rf_ConfigureDebugMem(RF_ShutdownList_t ** listp);
#endif /* !_RF__RF_DEBUGMEM_H_ */