From nobody Tue Jun 23 13:16:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F3ACC433EF for ; Mon, 28 Mar 2022 08:24:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239319AbiC1I0h convert rfc822-to-8bit (ORCPT ); Mon, 28 Mar 2022 04:26:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231297AbiC1I0f (ORCPT ); Mon, 28 Mar 2022 04:26:35 -0400 Received: from mx1.emlix.com (mx1.emlix.com [136.243.223.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A75DDEA8 for ; Mon, 28 Mar 2022 01:24:54 -0700 (PDT) Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id B58C35F8EA; Mon, 28 Mar 2022 10:24:52 +0200 (CEST) From: Rolf Eike Beer To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: mm: use mmap_assert_write_locked() instead of open coding it Date: Mon, 28 Mar 2022 10:24:51 +0200 Message-ID: <5827758.TJ1SttVevJ@mobilepool36.emlix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case the lock is actually not held at this point this also avoids a stale lock reference if built with NDEBUG. Signed-off-by: Rolf Eike Beer Reviewed-by: Christoph Hellwig Reviewed-by? --- mm/mmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 3aa839f81e63..d62598dc2fdd 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3561,7 +3561,7 @@ int mm_take_all_locks(struct mm_struct *mm) struct vm_area_struct *vma; struct anon_vma_chain *avc; =20 - BUG_ON(mmap_read_trylock(mm)); + mmap_assert_write_locked(mm); =20 mutex_lock(&mm_all_locks_mutex); =20 @@ -3641,7 +3641,7 @@ void mm_drop_all_locks(struct mm_struct *mm) struct vm_area_struct *vma; struct anon_vma_chain *avc; =20 - BUG_ON(mmap_read_trylock(mm)); + mmap_assert_write_locked(mm); BUG_ON(!mutex_is_locked(&mm_all_locks_mutex)); =20 for (vma =3D mm->mmap; vma; vma =3D vma->vm_next) { --=20 2.35.1 --=20 Rolf Eike Beer, emlix GmbH, https://www.emlix.com Fon +49 551 30664-0, Fax +49 551 30664-11 Gothaer Platz 3, 37083 G=C3=B6ttingen, Germany Sitz der Gesellschaft: G=C3=B6ttingen, Amtsgericht G=C3=B6ttingen HR B 3160 Gesch=C3=A4ftsf=C3=BChrung: Heike Jordan, Dr. Uwe Kracke =E2=80=93 Ust-IdNr= .: DE 205 198 055 emlix - smart embedded open source