Re: [PATCH 1/1] fs/xfs: Add check to kmem_cache_zalloc()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2025-02-28 at 10:48 +0800, Yuanjun Gong wrote:
> > Add check to the return value of kmem_cache_zalloc() in case it
> > fails.
> > 
> > Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@xxxxxxx>
> > ---
> >  fs/xfs/xfs_buf_item.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c
> > index 47549cfa61cd..3c23223b7d70 100644
> > --- a/fs/xfs/xfs_buf_item.c
> > +++ b/fs/xfs/xfs_buf_item.c
> > @@ -880,6 +880,8 @@ xfs_buf_item_init(
> >         }
> >  
> >         bip = kmem_cache_zalloc(xfs_buf_item_cache, GFP_KERNEL |
> > __GFP_NOFAIL);
> > +       if (!bip)
> > +               return -ENOMEM;
> >         xfs_log_item_init(mp, &bip->bli_item, XFS_LI_BUF,
> > &xfs_buf_item_ops);
> >         bip->bli_buf = bp;
> >  

The __GFP_NOFAIL flag ensures that this allocation will not fail, as stated
in the comments in include/linux/gfp_types.h:
 
 %__GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller
 * cannot handle allocation failures. The allocation could block
 * indefinitely but will never return with failure. Testing for
 * failure is pointless.

Thanks,
-- 
Julian Sun <sunjunchao2870@xxxxxxxxx>

-- 
Julian Sun <sunjunchao2870@xxxxxxxxx>





[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux