Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp445360yba; Wed, 24 Apr 2019 04:10:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzNlyfjYGHViO3rg5pBB9VhQ9+/GqCQDj4X8VNPCSmE4bgLzkOPQjX9/YPUiGyaeh6CLNfF X-Received: by 2002:a63:b64:: with SMTP id a36mr30201867pgl.58.1556104209285; Wed, 24 Apr 2019 04:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556104209; cv=none; d=google.com; s=arc-20160816; b=itDpHEnWIEno2Uh7Xk0O5vroF58gIQqJScfwhT7Fi9DYNj+nJOgjBUURKqHoZJ8t1D kYVSuI+Rs1+bgktaLfWDWIUICYUUa6Xc2eqFiByogIt1BOv9qSP60mCh6uXuxaWQK3lq VshQQMQyOsfSXFFgbwKMk1MYkrZK4pmNtglB+qGLTT5weWOtdQTbX6QBNcDfSkjDhbrJ BF52l00VWF4A8hDBRGodybI4Yks1TPKTRXOIx0//DgPK4/3R2x9fcIe7Orz2L6hnrp/4 wLsCKx9vqkXFArhRtbPP4z76yKds9/SCFeDcLaxcsFCWR8fgk16r1nzEZTFnVEO0PvSa KMeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CUbE0l8ESuXny4EMkKvO4cEsxQopKceRf5oHUmqZiWk=; b=nIJuyu1HY2j3wNfrHFfsmZyXuPe/ptlyqPGf7Vf4Rtwccfran7w92Eny0VF0u/YSKi thK5ovhC7/QbWyX9IswI69UIOQb68ekEEOI6WFM7ebm4bjEZPeeySwnV8vEQu67vAseS MxzNo/YbK5t4ZNHYk8kiAHaFDYgEQP8VRPUgUWJgHCPBMnYS2rtwr0bK/djgSzeGCI3B Sl/67aCHRMwzPvan/qGF4ZpB7FK6CpsBUY7WAoAA5Ns9gHmK3+Xv7G2SZgB1REZjRiGQ 40il6pHYUv5k71K6x6RZsG8OmeLGO0DNTmSVEbDWABmG/G37GRAvgPgYk/SFn6XZj3yO XFRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q8sueVEa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si16644513pgp.161.2019.04.24.04.09.53; Wed, 24 Apr 2019 04:10:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q8sueVEa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729806AbfDXKVj (ORCPT + 99 others); Wed, 24 Apr 2019 06:21:39 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:37953 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727478AbfDXKVg (ORCPT ); Wed, 24 Apr 2019 06:21:36 -0400 Received: by mail-pf1-f193.google.com with SMTP id 10so9080685pfo.5 for ; Wed, 24 Apr 2019 03:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CUbE0l8ESuXny4EMkKvO4cEsxQopKceRf5oHUmqZiWk=; b=q8sueVEa+mAx+ibGdxfUCjuFkOzpK/+z3WnPWZHH3OW0cgH052tGuPby23DNrAUzep nEeq1W2S839tdTaOZmKWQn+5KW+0/dRYXFKccSCPru8NgNngadZDJE4e9rB9vf5pSY8a ZoDLC6n4f+fly03QYmWtPSpBEr7l78vmiiJWAv93DMsnKZxggiuyNBUP9mOdW9apPgCd UNwtUL0bqyOf9cSdFH3w1oT2bgLQ9yjfjzVVMdPgPxNE5sR1Xnm2civAaOL/AYC6DmK7 +uGqt18mFrv+GH9NTAkLw+nS+gTP8Zz8/9sj2JKmeRshGPU1n30tkGddVBehtxSflYHj G2gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CUbE0l8ESuXny4EMkKvO4cEsxQopKceRf5oHUmqZiWk=; b=fRyVwFiI98lR9qgMX9BF289wJO37J3gOVb1FcFJBOQlmUp0njTeNH3byy+N/zkzmxM vPOS9jCnfQlfVE5kYH989MJQM+sZyvUl741r/4SIAKbqDmLvrmrxRa6il3DxYawCIlkg Lk0F5kMvymzjIuf24MzEzC8d4aAmtUsnCYFOAQYSQRyWea6HGkVCSsVcYmsVcTDz3Y6f lTaRv7lJ+S/x8YuW+lxVTdlYF7ORg2l+6iayeByRMU0sRs11eQn59eDH/DHWskiFGDxk 180RMDw6JDuwPwWvIVLa6AZ04rycOrBJtFEk6tm3bvS2nW8Ctnq9/fn7fiAmi5EvDvAX JFJA== X-Gm-Message-State: APjAAAUldTG6LkS7C8l0yUibbPO2HZVTbX+0ED07OLNzkXbywbhCXkAg fseW4ha8nvgtcFzJeMro560= X-Received: by 2002:a65:63c3:: with SMTP id n3mr15521869pgv.170.1556101295834; Wed, 24 Apr 2019 03:21:35 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v19sm25051604pfn.62.2019.04.24.03.21.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:21:35 -0700 (PDT) From: Yuyang Du To: peterz@infradead.org, will.deacon@arm.com, mingo@kernel.org Cc: bvanassche@acm.org, ming.lei@redhat.com, frederic@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, Yuyang Du Subject: [PATCH 22/28] locking/lockdep: Adjust new bit cases in mark_lock Date: Wed, 24 Apr 2019 18:19:28 +0800 Message-Id: <20190424101934.51535-23-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190424101934.51535-1-duyuyang@gmail.com> References: <20190424101934.51535-1-duyuyang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The new bit can be any possible lock usage except it is garbage, so the cases in switch can be made simpler. Warn early on if wrong usage bit is passed without taking locks. No functional change. Signed-off-by: Yuyang Du --- kernel/locking/lockdep.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index c08ec88..291cc9c 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3476,6 +3476,11 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, { unsigned int new_mask = 1 << new_bit, ret = 1; + if (new_bit >= LOCK_USAGE_STATES) { + WARN_ON(1); + return 0; + } + /* * If already set then do not dirty the cacheline, * nor do any checks: @@ -3499,25 +3504,13 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, return 0; switch (new_bit) { -#define LOCKDEP_STATE(__STATE) \ - case LOCK_USED_IN_##__STATE: \ - case LOCK_USED_IN_##__STATE##_READ: \ - case LOCK_ENABLED_##__STATE: \ - case LOCK_ENABLED_##__STATE##_READ: -#include "lockdep_states.h" -#undef LOCKDEP_STATE - ret = mark_lock_irq(curr, this, new_bit); - if (!ret) - return 0; - break; case LOCK_USED: debug_atomic_dec(nr_unused_locks); break; default: - if (!debug_locks_off_graph_unlock()) + ret = mark_lock_irq(curr, this, new_bit); + if (!ret) return 0; - WARN_ON(1); - return 0; } graph_unlock(); -- 1.8.3.1