[PATCH v3] mm: Fixed incorrect comment for _kmem_cache_create function

zhaoxinchao posted 1 patch 2 years, 8 months ago
mm/slab.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
[PATCH v3] mm: Fixed incorrect comment for _kmem_cache_create function
Posted by zhaoxinchao 2 years, 8 months ago
From: zhaoxinchao <chrisxinchao@outlook.com>

Actually __kmem_cache_create() returns a status :
0 is success
nonezero are failed.

This function has three return positions. In addition to successfully
return 0, the first failed position will return - E2BIG, and the second
position will return nonzero value for setup_cpu_cache function failure.

Signed-off-by: zhaoxinchao <chrisxinchao@outlook.com>
---
 mm/slab.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index edbe722fb..ebd326f07 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1888,14 +1888,17 @@ static bool set_on_slab_cache(struct kmem_cache *cachep,
 	return true;
 }
 
-/**
+/*
  * __kmem_cache_create - Create a cache.
  * @cachep: cache management descriptor
  * @flags: SLAB flags
  *
- * Returns a ptr to the cache on success, NULL on failure.
- * Cannot be called within an int, but can be interrupted.
- * The @ctor is run when new pages are allocated by the cache.
+ * Returns zero on success, nonzero on failure.
+ * This function has three return positions.
+ * In addition to successfully return 0, the
+ * first failed position will return - E2BIG,
+ * and the second position will return nonzero
+ * value for setup_cpu_cache function failure.
  *
  * The flags are
  *
@@ -1908,8 +1911,6 @@ static bool set_on_slab_cache(struct kmem_cache *cachep,
  * %SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware
  * cacheline.  This can be beneficial if you're counting cycles as closely
  * as davem.
- *
- * Return: a pointer to the created cache or %NULL in case of error
  */
 int __kmem_cache_create(struct kmem_cache *cachep, slab_flags_t flags)
 {
-- 
2.39.2
Re: [PATCH v3] mm: Fixed incorrect comment for _kmem_cache_create function
Posted by Vlastimil Babka 2 years, 8 months ago
On 4/18/23 04:05, zhaoxinchao wrote:
> From: zhaoxinchao <chrisxinchao@outlook.com>
> 
> Actually __kmem_cache_create() returns a status :
> 0 is success
> nonezero are failed.
> 
> This function has three return positions. In addition to successfully
> return 0, the first failed position will return - E2BIG, and the second
> position will return nonzero value for setup_cpu_cache function failure.

Adjusted a bit.

> Signed-off-by: zhaoxinchao <chrisxinchao@outlook.com>
> ---
>  mm/slab.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/slab.c b/mm/slab.c
> index edbe722fb..ebd326f07 100644
> --- a/mm/slab.c
> +++ b/mm/slab.c
> @@ -1888,14 +1888,17 @@ static bool set_on_slab_cache(struct kmem_cache *cachep,
>  	return true;
>  }
>  
> -/**
> +/*
>   * __kmem_cache_create - Create a cache.
>   * @cachep: cache management descriptor
>   * @flags: SLAB flags
>   *
> - * Returns a ptr to the cache on success, NULL on failure.
> - * Cannot be called within an int, but can be interrupted.
> - * The @ctor is run when new pages are allocated by the cache.
> + * Returns zero on success, nonzero on failure.
> + * This function has three return positions.
> + * In addition to successfully return 0, the
> + * first failed position will return - E2BIG,
> + * and the second position will return nonzero
> + * value for setup_cpu_cache function failure.

In v2 I recommended dropping the detailed description. Removed it when
merging. The result is merged for 6.5 here:

https://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git/log/?h=slab/for-6.5/trivial

Thanks!

>   *
>   * The flags are
>   *
> @@ -1908,8 +1911,6 @@ static bool set_on_slab_cache(struct kmem_cache *cachep,
>   * %SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware
>   * cacheline.  This can be beneficial if you're counting cycles as closely
>   * as davem.
> - *
> - * Return: a pointer to the created cache or %NULL in case of error
>   */
>  int __kmem_cache_create(struct kmem_cache *cachep, slab_flags_t flags)
>  {