Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2942025ybg; Mon, 28 Oct 2019 05:02:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaUOpqnI+AR9p8bRcSWfqjsV9zND33SBv7XqpWuenRaWzF0OUDiz8prliKW4DwF5OxoCkk X-Received: by 2002:a50:ab50:: with SMTP id t16mr19165391edc.171.1572264161680; Mon, 28 Oct 2019 05:02:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572264161; cv=none; d=google.com; s=arc-20160816; b=wL0VjKUqAmjp1P7hFeoqkqYTGgd7oYE1NTgvm4g6HoHTmqtXxyeCQkgw0GNT8bcBfx 7iOXdLF3NoGr/jst8IVJXohKksmnm5ydgWt9SAici0iCfVwvRmySpAkqenmUH5Ax+Gtf GWeaKOrRvoqjovQNHA+Zbdnzou4/QpeG9aZalxaTI2tT51PiFPQwIAecW0qjiQiiZLBa rUCvaGEGwuJhZUk5hUULwFyPUQlWLLmxLDkZarafK5xNe0mckYCeh0J3oHLEqKFu4fYn udOBmEoJZxOyUngf6v9luCOH/TyYx/pUPevXkONcBhfxt1/6OD1ngZa96VD7F7qhOnVf 1HBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=F8CepSqRWMxzznKDuNjIRyfKA8DcTcaI/XpXdlDrOrE=; b=nU6RE1NIT+eKOI2mnMnDJkPjnw3GZjqAazb7v2c1kkbjGJxgc9aRQH6SaPjts0PxWy b2N9QM6LUbaVvT4WWB5CAVN2h3LxinJY9S180x44o8ne4ayIsP+m971x6rtADxomT26H mSgO1AtIpkSroqUpMwnHv3w0uUhnDQqE3hxtcrtO85QwmzBdk7yQIiCOq03O5jBWfMCM vns/qc85hfACT8YcCXqgtDd5hiW2ziLc81yumGxv28gn+L9K/9VVYfmrzxVnaK/YlNlO UkwI8sHlqwW3GXAshEcJzvVxMhs1va2ruRxeoN9Rm75+cg9G9ii7CHLy9cJZ0zL/U5Tn m95Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m19si5591850ejd.180.2019.10.28.05.02.16; Mon, 28 Oct 2019 05:02:41 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727708AbfJ0WDN (ORCPT + 99 others); Sun, 27 Oct 2019 18:03:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:48398 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726881AbfJ0WDN (ORCPT ); Sun, 27 Oct 2019 18:03:13 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DE7E7AD78; Sun, 27 Oct 2019 22:03:11 +0000 (UTC) From: Davidlohr Bueso To: dsterba@suse.com Cc: dave@stgolabs.net, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: [PATCH] fs/affs: Replace binary semaphores with mutexes Date: Sun, 27 Oct 2019 15:01:43 -0700 Message-Id: <20191027220143.10756-1-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At a slight footprint cost (24 vs 32 bytes), mutexes are more optimal than semaphores; it's also a nicer interface for mutual exclusion, which is why they are encouraged over binary semaphores, when possible. For both i_link_lock and i_ext_lock (and hence i_hash_lock which I annotated for the hash lock mapping hackery for lockdep), their semantics imply traditional lock ownership; that is, the lock owner is the same for both lock/unlock operations and does not run in irq context. Therefore it is safe to convert. Signed-off-by: Davidlohr Bueso --- Compile tested only. fs/affs/affs.h | 16 ++++++++-------- fs/affs/super.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/affs/affs.h b/fs/affs/affs.h index a92eb6ae2ae2..a755bef7c4c7 100644 --- a/fs/affs/affs.h +++ b/fs/affs/affs.h @@ -43,8 +43,8 @@ struct affs_ext_key { */ struct affs_inode_info { atomic_t i_opencnt; - struct semaphore i_link_lock; /* Protects internal inode access. */ - struct semaphore i_ext_lock; /* Protects internal inode access. */ + struct mutex i_link_lock; /* Protects internal inode access. */ + struct mutex i_ext_lock; /* Protects internal inode access. */ #define i_hash_lock i_ext_lock u32 i_blkcnt; /* block count */ u32 i_extcnt; /* extended block count */ @@ -293,30 +293,30 @@ affs_adjust_bitmapchecksum(struct buffer_head *bh, u32 val) static inline void affs_lock_link(struct inode *inode) { - down(&AFFS_I(inode)->i_link_lock); + mutex_lock(&AFFS_I(inode)->i_link_lock); } static inline void affs_unlock_link(struct inode *inode) { - up(&AFFS_I(inode)->i_link_lock); + mutex_unlock(&AFFS_I(inode)->i_link_lock); } static inline void affs_lock_dir(struct inode *inode) { - down(&AFFS_I(inode)->i_hash_lock); + mutex_lock_nested(&AFFS_I(inode)->i_hash_lock, SINGLE_DEPTH_NESTING); } static inline void affs_unlock_dir(struct inode *inode) { - up(&AFFS_I(inode)->i_hash_lock); + mutex_unlock(&AFFS_I(inode)->i_hash_lock); } static inline void affs_lock_ext(struct inode *inode) { - down(&AFFS_I(inode)->i_ext_lock); + mutex_lock(&AFFS_I(inode)->i_ext_lock); } static inline void affs_unlock_ext(struct inode *inode) { - up(&AFFS_I(inode)->i_ext_lock); + mutex_unlock(&AFFS_I(inode)->i_ext_lock); } diff --git a/fs/affs/super.c b/fs/affs/super.c index cc463ae47c12..9fcff55c65af 100644 --- a/fs/affs/super.c +++ b/fs/affs/super.c @@ -121,8 +121,8 @@ static void init_once(void *foo) { struct affs_inode_info *ei = (struct affs_inode_info *) foo; - sema_init(&ei->i_link_lock, 1); - sema_init(&ei->i_ext_lock, 1); + mutex_init(&ei->i_link_lock); + mutex_init(&ei->i_ext_lock); inode_init_once(&ei->vfs_inode); } -- 2.16.4