From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756799AbdLVUp2 (ORCPT ); Fri, 22 Dec 2017 15:45:28 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:39799 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755941AbdLVUpY (ORCPT ); Fri, 22 Dec 2017 15:45:24 -0500 X-Google-Smtp-Source: ACJfBos3C1uSxrt5rLZviuvHN1ZAprguhBmmd3bLqGQiw/aEtTiq8d7WIkbsKwMDFTpwV7whynRthg== Date: Sat, 23 Dec 2017 02:15:19 +0530 From: gaurav jindal To: peterz@infradead.org, mingo@redhat.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH]locking:mutex Print warning if trylock in irq context Message-ID: <20171222204519.GA12047@gaurav.jindal> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since mutex_trylock must not be called from interrupt context, a robustness can be added to this function by throwing a warning if it is called in interrupt context. It would help to make debugging easier in case of undesired calling of this function. Signed-off-by: gaurav jindal --- diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 858a075..fe1cace 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -1176,7 +1176,10 @@ void __sched mutex_lock_io(struct mutex *lock) */ int __sched mutex_trylock(struct mutex *lock) { - bool locked = __mutex_trylock(lock); + bool locked; + + WARN_ONCE(in_irq(), "%s wrongly called in irq context", __func__); + locked = __mutex_trylock(lock); if (locked) mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);