Re: [PATCH] locking/mutex:add MUTEX_CHCEK_INIT to detect uninitialized mutex lock

From: Waiman Long
Date: Wed Sep 24 2025 - 10:24:38 EST


On 9/23/25 11:40 PM, buckzhang1212 wrote:
Hey Waiman
Thank you for your reply.
I totally agree with you that A mutex must be properly initialized before it can be used.
But my customer engineer often make the mistake like this in TP or fingerprint driver.
I want to warn this mistake at first because it can be used normally mostly.
when enable CONFIG_DEBUG_MUTEXES,we can get more informations.
This check has provided no additional value and it slows down the
locking fast path.
---- how about move the warning to __mutex_lock_slowpath?
Can you give me some advices?

As suggested by Peter, additional checks like that should only be enabled in the debug portion of the code (i.e. within CONFIG_DEBUG_MUTEXES or other debug kconfig option). The normal way we test the kernel patches is to build a debug kernel with all the appropriate debug options enabled and use it for testing purpose as performance isn't a concern. This enables all the debug code to be activated and check for correctness. Don't rely your testing just on the production kernel unless you are testing for some performance related metrics. Even then, both the debug and production kernels should be used.

Hope this help.

Cheers,
Longman