Re: [PATCH 1/3] md: call del_gendisk in control path

Bart Van Assche <[email protected]>
Newsgroups gmane.linux.raid
Message-ID <[email protected]>
On 6/11/25 12:31 AM, Xiao Ni wrote:
>   static inline int mddev_trylock(struct mddev *mddev)
>   {
> -	return mutex_trylock(&mddev->reconfig_mutex);
> +	int ret;
> +
> +	ret = mutex_trylock(&mddev->reconfig_mutex);
> +	if (!ret && test_bit(MD_DELETED, &mddev->flags)) {
> +		ret = -ENODEV;
> +		mutex_unlock(&mddev->reconfig_mutex);
> +	}
> +	return ret;
>   }

This change seems wrong to me. This change will cause mutex_unlock() to
be called if mutex_trylock() *failed*. Additionally, returning -ENODEV
from the failure path will cause the caller to call mutex_unlock() a
second time if mutex_trylock() failed. Please fix this!

As a reminder, from include/linux/mutex.h:

/*
  * NOTE: mutex_trylock() follows the spin_trylock() convention,
  *       not the down_trylock() convention!
  *
  * Returns 1 if the mutex has been acquired successfully, and 0 on 
contention.
  */

Bart.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.