Re: [PATCH v2] slab: Warn on duplicate cache names when DEBUG_VM=y

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

 



On Wed, 7 Aug 2024, Pedro Falcato wrote:

> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index 40b582a014b..1abe6a577d5 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -88,6 +88,19 @@ unsigned int kmem_cache_size(struct kmem_cache *s)
>  EXPORT_SYMBOL(kmem_cache_size);
>  
>  #ifdef CONFIG_DEBUG_VM
> +
> +static bool kmem_cache_is_duplicate_name(const char *name)
> +{
> +	struct kmem_cache *s;
> +
> +	list_for_each_entry(s, &slab_caches, list) {
> +		if (!strcmp(s->name, name))
> +			return true;
> +	}
> +
> +	return false;
> +}
> +
>  static int kmem_cache_sanity_check(const char *name, unsigned int size)
>  {
>  	if (!name || in_interrupt() || size > KMALLOC_MAX_SIZE) {
> @@ -95,6 +108,11 @@ static int kmem_cache_sanity_check(const char *name, unsigned int size)
>  		return -EINVAL;
>  	}
>  
> +	if (kmem_cache_is_duplicate_name(name)) {
> +		/* Duplicate names will confuse slabtop, et al */
> +		pr_warn("%s: name %s already exists as a cache\n", __func__, name);


Shouldn't this be a full WARN_ON() instead of pr_warn()?  I assume we'll 
be interested in who is adding the cache when the name already exists.




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux