Re: [PATCH] proc: add error handling for kmem_cache_create

From: Alexey Dobriyan
Date: Tue Jun 12 2018 - 01:10:53 EST


On Tue, Jun 12, 2018 at 12:23:52PM +0800, Zhouyang Jia wrote:
> When kmem_cache_create fails, the lack of error-handling code may
> cause unexpected results.
>
> This patch adds error-handling code after calling kmem_cache_create.

> pde_opener_cache =
> kmem_cache_create("pde_opener", sizeof(struct pde_opener), 0,
> SLAB_ACCOUNT|SLAB_PANIC, NULL);
> + if (!proc_inode_cachep || !pde_opener_cache)
> + return -ENOMEM;

SLAB_PANIC was added to not worry about error handling.