xfs
[Top] [All Lists]

Re: [PATCH 3/8] xfs: handle kmalloc failure when reading attrs

To: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Subject: Re: [PATCH 3/8] xfs: handle kmalloc failure when reading attrs
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Fri, 2 Mar 2012 20:49:38 +1100
Cc: xfs@xxxxxxxxxxx
In-reply-to: <20120302074920.GE4117@xxxxxxxxxxxxx>
References: <1330661507-1121-1-git-send-email-david@xxxxxxxxxxxxx> <1330661507-1121-4-git-send-email-david@xxxxxxxxxxxxx> <20120302074920.GE4117@xxxxxxxxxxxxx>
User-agent: Mutt/1.5.21 (2010-09-15)
On Fri, Mar 02, 2012 at 02:49:20AM -0500, Christoph Hellwig wrote:
> I think the subject should be more like:
> 
> xfs: fallback to vmalloc for large buffers in xfs_attrmulti_attr_get

OK.

> > +   kbuf = kmem_zalloc(*len, KM_SLEEP | KM_MAYFAIL);
> > +   if (!kbuf) {
> > +           kbuf = kmem_zalloc_large(*len);
> > +           if (!kbuf)
> > +                   return ENOMEM;
> > +   }
> >  
> >     error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags);
> >     if (error)
> > @@ -457,7 +460,7 @@ xfs_attrmulti_attr_get(
> >             error = EFAULT;
> >  
> >   out_kfree:
> > -   kfree(kbuf);
> > +   kmem_free(kbuf);
> 
> kmem_free doesn't handle vmalloced buffers from kmem_zalloc_large, you
> need to use kmem_free_large for them.

static inline void kmem_free_large(void *ptr)
{
        vfree(ptr);
}

That only handles vmalloced memory, but kmem_free()
handles both kmalloc() and vmalloc() memory:

void
kmem_free(const void *ptr)
{
        if (!is_vmalloc_addr(ptr)) {
                kfree(ptr);
        } else {
                vfree(ptr);
        }
}

Avoiding having to open code this vmalloc check is exactly why I
chose kmem_free() here ;)

Cheers,

Dave.
-- 
Dave Chinner
david@xxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>