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

"Yu Kuai" <[email protected]>
Newsgroups gmane.linux.raid
Message-ID <[email protected]>
Hi,

在 2026/1/27 10:13, Bart Van Assche 写道:
> 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!

oops, this looks correct.

Just wonder why we didn't hit any strange bug with this, a try lock failure
should be quite possible.

>
> 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.
>
-- 
Thansk,
Kuai
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.