lkml.org 
[lkml]   [2014]   [Nov]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH vfs 1/2] lib: implement ptrset
On Thu, Nov 13, 2014 at 05:09:27PM -0500, Tejun Heo wrote:
> +int ptrset_add(void *ptr, struct ptrset *set, gfp_t gfp)
> +{
> + struct ptrset_elem *elem;
> + struct rb_node *parent, **slot;
> +
> + elem = kmalloc(sizeof(*elem), gfp);
> + if (!elem && !in_interrupt()) /* see ptrset_preload() */
> + elem = this_cpu_xchg(ptrset_preload_elem, NULL);
> + if (!elem)
> + return -ENOMEM;
> + elem->ptr = ptr;
> +
> + if (ptrset_find_slot(elem->ptr, set, &slot, &parent)) {
> + kfree(elem);
> + return -EEXIST;
> + }

Maybe allocation *after* ptrset_find_slot() will be better?
This will avoid extra kmalloc/kfree if such ptr already exist (and also
will avoid ENOMEM for such cases).


\
 
 \ /
  Last update: 2014-11-18 17:41    [W:0.215 / U:0.308 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site