[openib-general] Re: [PATCH] kDAPL: remove dat_os_realloc()
James Lentini
jlentini at netapp.com
Thu Jun 23 19:37:00 PDT 2005
What do you think about doing it this way? (see attached)
On Thu, 23 Jun 2005, Tom Duffy wrote:
tduffy> There was only one user of the dat_os_realloc() function. Roll it into
tduffy> the base function.
tduffy>
tduffy> Signed-off-by: Tom Duffy <tduffy at sun.com>
tduffy>
tduffy> Index: linux-kernel/dat-provider/dapl_evd.c
tduffy> ===================================================================
tduffy> --- linux-kernel/dat-provider/dapl_evd.c (revision 2704)
tduffy> +++ linux-kernel/dat-provider/dapl_evd.c (working copy)
tduffy> @@ -191,13 +191,15 @@ bail:
tduffy> static u32 dapl_evd_event_realloc(struct dapl_evd *evd, int qlen)
tduffy> {
tduffy> struct dat_event *events;
tduffy> - int i, old_qlen, diff;
tduffy> + int i, old_qlen, diff, size;
tduffy> u32 status;
tduffy>
tduffy> - /* Allocate EVENTs */
tduffy> - events = (struct dat_event *)dapl_os_realloc(evd->events,
tduffy> - qlen * sizeof *events);
tduffy> - if (!events) {
tduffy> + size = qlen * sizeof *events;
tduffy> + events = kmalloc(size, GFP_ATOMIC);
tduffy> + if (events) {
tduffy> + memcpy(events, evd->events, size);
tduffy> + kfree(evd->events);
tduffy> + } else {
tduffy> status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
tduffy> DAT_RESOURCE_MEMORY);
tduffy> goto bail;
tduffy> Index: linux-kernel/dat-provider/dapl_util.h
tduffy> ===================================================================
tduffy> --- linux-kernel/dat-provider/dapl_util.h (revision 2704)
tduffy> +++ linux-kernel/dat-provider/dapl_util.h (working copy)
tduffy> @@ -89,23 +89,6 @@ static inline int dapl_os_atomic_assign(
tduffy> }
tduffy>
tduffy> /*
tduffy> - * Memory Functions
tduffy> - */
tduffy> -
tduffy> -static inline void *dapl_os_realloc(void *ptr, int size)
tduffy> -{
tduffy> - void *newptr;
tduffy> -
tduffy> - newptr = kmalloc(size, GFP_ATOMIC);
tduffy> - if (newptr) {
tduffy> - /* copy the mem array to the new */
tduffy> - memcpy(newptr, ptr, size);
tduffy> - kfree(ptr);
tduffy> - }
tduffy> - return newptr;
tduffy> -}
tduffy> -
tduffy> -/*
tduffy> * *printf format helper. We use the C string constant concatenation
tduffy> * ability to define 64 bit formats, which unfortunatly are non standard
tduffy> * in the C compiler world.
tduffy>
-------------- next part --------------
Index: dat-provider/dapl_evd.c
===================================================================
--- dat-provider/dapl_evd.c (revision 2704)
+++ dat-provider/dapl_evd.c (working copy)
@@ -191,19 +191,20 @@ bail:
static u32 dapl_evd_event_realloc(struct dapl_evd *evd, int qlen)
{
struct dat_event *events;
- int i, old_qlen, diff;
+ int i, old_qlen, diff, size;
u32 status;
- /* Allocate EVENTs */
- events = (struct dat_event *)dapl_os_realloc(evd->events,
- qlen * sizeof *events);
+ size = qlen * sizeof *events;
+ events = kmalloc(size, GFP_ATOMIC);
if (!events) {
status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
DAT_RESOURCE_MEMORY);
goto bail;
}
+ memcpy(events, evd->events, size);
diff = events - evd->events;
+ kfree(evd->events);
evd->events = events;
old_qlen = evd->qlen;
Index: dat-provider/dapl_util.h
===================================================================
--- dat-provider/dapl_util.h (revision 2704)
+++ dat-provider/dapl_util.h (working copy)
@@ -89,23 +89,6 @@ static inline int dapl_os_atomic_assign(
}
/*
- * Memory Functions
- */
-
-static inline void *dapl_os_realloc(void *ptr, int size)
-{
- void *newptr;
-
- newptr = kmalloc(size, GFP_ATOMIC);
- if (newptr) {
- /* copy the mem array to the new */
- memcpy(newptr, ptr, size);
- kfree(ptr);
- }
- return newptr;
-}
-
-/*
* *printf format helper. We use the C string constant concatenation
* ability to define 64 bit formats, which unfortunatly are non standard
* in the C compiler world.
More information about the general
mailing list