Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1090781ybh; Wed, 11 Mar 2020 17:24:08 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtVzmvHBzW0hA6cOFIuDMalh2+RGGfOc0Oi2WjE6EYFpwRZJdw5Szx4CbK+F0IWFIXnsDR2 X-Received: by 2002:aca:3354:: with SMTP id z81mr860224oiz.129.1583972648533; Wed, 11 Mar 2020 17:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583972648; cv=none; d=google.com; s=arc-20160816; b=upZxpoFgvMIGZfUOncFXu2t7Q57EFHsQa6Pdkd/KE2Bx3RWI5aIC/KRSc75EoRvrmJ HSaDLpoBKgvD5++w50a1dkiEntzDaSP1MrO4v/nzzD/ySINTSrHLeQwlRAel/D73Ez86 DRGmyNXtUpJJwcvQlnTW2PahDjotdB47CClJmP2sVZUkyRa2NiTj6yRoLNp9i0N1DLL5 0Da4YGchBQ2aTuG7tNohKTAbH4g9vM4BDLvKWXEbuSES2szEQn2+WA8HXypZAMT6OtMx ERh0E4OfPbPuyV7qEMBgaoIJrG/EFLtSghra4GmWNee6KRGoDVkDzNZ78hfTLQ2fNiuQ e+xQ== 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=XMQYZ+6NFPRcSEcavCV/oXjjG97VYnibSYtGEAw9FKE=; b=S8SBoFKzFoGId+nlF9C0Q7cZHDYO4wKbfK/cX/NHjQQASIOFi5/jMbi/+AjjqWv4uc Cug02bqeNknRoDa9AvcCwywKJYdvnh62lLPmrzqnGmfEW8oONAGNctzQB3qWzLDNYtic kKRhs9cPViijc4DRMB9LME8AdekkcnVDmDtFt0WYLqNCCLrRhFuLRb7PmW8PdvDjVOy2 JZwn5ySHip4v5x+hYOuuuTMvCsA8C3cRTxbfWXU28YjmZ+iv4t44S8gVdznVqhzhYYLo 5tBDlt+2DrcLfdwhm0Lcp3dsoYlLruQcsMKqUeR2/YTgBNM/AdzDpYwaCXorjwEp9JEa UkDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YBCJcKO7; 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 j2si1778037otk.164.2020.03.11.17.23.56; Wed, 11 Mar 2020 17:24:08 -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=YBCJcKO7; 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 S1731619AbgCLAWK (ORCPT + 99 others); Wed, 11 Mar 2020 20:22:10 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37330 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731559AbgCLAWJ (ORCPT ); Wed, 11 Mar 2020 20:22:09 -0400 Received: by mail-wr1-f68.google.com with SMTP id 6so5139990wre.4 for ; Wed, 11 Mar 2020 17:22:07 -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=XMQYZ+6NFPRcSEcavCV/oXjjG97VYnibSYtGEAw9FKE=; b=YBCJcKO7WMERIDKhjn9c2ArgxPEQrxYKQEQ6LEfLaxrvuoz6rScdfqIJUaX/XDRZny brr2Fvy1Sghb7FOcgZLndwtSBycagaPxcRLChohsdVmGmuJKinJ3Fv/UY+FUdT1CGwow qeYRKy9iruEhap5M+4IhNnTM94la8flsSvACVFbjxmIblKzpQuxUjPg/puovL1noOdlb 7opS1YDKCcch3XvJe31/eHlb7ES3VRqmIcVcKefQZ2GrEuNx7y3T+nEsWOOgNNdDPIOV SKeLbUsxg4iEOonOYb5ImSQZTmzPPzAGf5KFWeiZaZ1B4kU3KN0X3+vB7XcXs0dIlP51 mQGg== 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=XMQYZ+6NFPRcSEcavCV/oXjjG97VYnibSYtGEAw9FKE=; b=bwOLfPOCylaCI+OKTkT7RpbmSjwwGzfHmhTnoE8OOlR1g9CK3og15u+nN1oVj9r2dc F5MtG4WB2Jl9B9K6ZiRKVDS1twaiqVd8cY8GUrcH6lvmVkzKWEDFQTnrNilAcESfFrcg U/UORVOZwM25asGkKdZRaQDtLu5Rr/muKpSyhMC/3DEH2DkzfKjYkY+GITE6TCFyjLPR E/h2aou4fylpEDTNd7Bxd1J4aJyegLZdKFTqyIu0v356H9rxs6MtH2dGmnte3PYOxSD1 hmClFeKMKtge5QTAYiIrnr1OpgM4CYfRNn6sVKHeoAE54+zMzDXCjJvz+D5X65S5Qh4T npmw== X-Gm-Message-State: ANhLgQ3YASFlDH6ricOU0wnEiYtjoT1Yj54z2H8FiYk5TG5GBwNGQg+M yNWGNeN3BJ5ND07hX5W6BA== X-Received: by 2002:adf:f0c8:: with SMTP id x8mr7543466wro.58.1583972527134; Wed, 11 Mar 2020 17:22:07 -0700 (PDT) Received: from ninjahost.lan (host-2-102-15-144.as13285.net. [2.102.15.144]) by smtp.googlemail.com with ESMTPSA id w9sm35254337wrn.35.2020.03.11.17.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 17:22:06 -0700 (PDT) From: Jules Irenge To: boqun.feng@gmail.com Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/1] backing-dev: refactor wb_congested_put() Date: Thu, 12 Mar 2020 00:21:56 +0000 Message-Id: <20200312002156.49023-2-jbi.octave@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200312002156.49023-1-jbi.octave@gmail.com> References: <20200312002156.49023-1-jbi.octave@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 wb_congested_put() was written in such a way that made it difficult for Sparse tool not to complain Expanding the function locking block in the if statement improves on the readability of the code. Rewritting it comes with one add-on: It fixes a warning reported by Sparse tool at wb_congested_put() warning: context imbalance in wb_congested_put() - unexpected unlock Refactor the function wb_congested_put() Signed-off-by: Jules Irenge --- mm/backing-dev.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 62f05f605fb5..9d47c0b6a42c 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -464,18 +464,21 @@ void wb_congested_put(struct bdi_writeback_congested *congested) { unsigned long flags; - if (!refcount_dec_and_lock_irqsave(&congested->refcnt, &cgwb_lock, &flags)) - return; - + if (!refcount_dec_not_one(&congested->refcnt)) { + spin_lock_irqsave(&cgwb_lock, flags); + if (!refcount_dec_and_test(&congested->refcnt)) { + spin_unlock_irqrestore(&cgwb_lock, flags); + return; + } /* bdi might already have been destroyed leaving @congested unlinked */ - if (congested->__bdi) { - rb_erase(&congested->rb_node, - &congested->__bdi->cgwb_congested_tree); - congested->__bdi = NULL; + if (congested->__bdi) { + rb_erase(&congested->rb_node, + &congested->__bdi->cgwb_congested_tree); + congested->__bdi = NULL; + } + spin_unlock_irqrestore(&cgwb_lock, flags); + kfree(congested); } - - spin_unlock_irqrestore(&cgwb_lock, flags); - kfree(congested); } static void cgwb_release_workfn(struct work_struct *work) -- 2.24.1