Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1247693rdb; Fri, 22 Dec 2023 22:40:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6Ts3RsL9qWbnO2CFdz7EZ88pOAns/EM173UDP/eEv1r4dNfn7OIMoc41kl8I0c96S2KC+ X-Received: by 2002:a0c:f8c7:0:b0:67f:998b:bf9e with SMTP id h7-20020a0cf8c7000000b0067f998bbf9emr2047130qvo.74.1703313607168; Fri, 22 Dec 2023 22:40:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703313607; cv=none; d=google.com; s=arc-20160816; b=Agv9z7DPwlr0GaYnpmTU67Fdoo8tWCZg6zhDJx/RMd8SMJj8HHGoHVN2eiEy4IgQyw nIb0ZcKRi6Uib95wV4NaDTZYCaFtkt4BIAn3Z4xNFR6Cs6tNxnuONCQgFjIR8q58Z24K dklmPlgwBt2tgw9jY6zQE5hS8awXakYbLery5e+af8BH43wwdNOBSVSoASTlFapA3Z4Z jRRYQIaZH6XdJI0ygwQS3lTQ1fIqln+pahNgphe/rUt/8qdkcDXDeNsFTFgS/ZWsFJ4v pmCyWOE8+ST9XffKL/DI2oxopzGBQA/oEtqhA2cAmP/qC/1JgeDA1BgOu/u5RdNqEg3s u0Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=lDaTa5ky3eqQY438IOsnwqNUM1Cs4msUdKPHYjGf1EU=; fh=zkcIwTk9sJN+dFrByvp4IZwwJkxOuOrldZrviqmXhTE=; b=hnuiXHgRU02xPaH2Cf2p8S18uoGUWlltcXjt1lM0ZLJjkoAmLOJ0YRRUdQgrDSVy7i XmS+9uNUQTuD/tDtU9gGOFjSWQM6iWSlSgPMVvLJYKKpevOqOBE5HcHlDAzg696MLCg9 hOBdlWPG5LCG+jONtuRgOw9Udhouu8+WdA6/5k56h8fId8+dIdu9HJS0H3mjxNL3d42Y eqQMk8vn7X8PkdsWstc/13BXOVGrVuL/hH4+LDrt+vBzTBwoVZDoYA9SU6PKjzXmh/Pp YQXQCWUbkbzU3eCQyqQQT+lsZTxbIkaaHQVpjqr5r8e94PTd7Mt4yVpGrds/rDoR7fDk mmpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10321-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10321-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w16-20020a0cf710000000b0067f827b4971si5114595qvn.262.2023.12.22.22.40.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 22:40:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10321-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10321-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10321-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B34481C22B3E for ; Sat, 23 Dec 2023 06:40:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E67338F7E; Sat, 23 Dec 2023 06:39:40 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3D0D4437; Sat, 23 Dec 2023 06:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Sxvf90z6kz4f3lDH; Sat, 23 Dec 2023 14:39:29 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 6B8081A0787; Sat, 23 Dec 2023 14:39:34 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXmhCjgIZlBfyaEQ--.4053S5; Sat, 23 Dec 2023 14:39:34 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, geliang.tang@suse.com, xni@redhat.com, colyli@suse.de Cc: ira.weiny@intel.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linan666@huaweicloud.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH 1/4] badblocks: goto out if find any unacked badblocks in _badblocks_check() Date: Sat, 23 Dec 2023 14:37:25 +0800 Message-Id: <20231223063728.3229446-2-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231223063728.3229446-1-linan666@huaweicloud.com> References: <20231223063728.3229446-1-linan666@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgCXmhCjgIZlBfyaEQ--.4053S5 X-Co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x4A2jsIEc7CjxVAFwI0_Gr0_ Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUwFxUUUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ From: Li Nan In _badblocks_check(), after finding any unacked badblocks, the return value, 'first_bad' and 'bad_sectors' will not be changed anymore, and there is no need to check other ranges. So goto out directly after finding unacked badblocks. Signed-off-by: Li Nan --- block/badblocks.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index fc92d4e18aa3..ebf17a54851a 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -1274,7 +1274,7 @@ static int _badblocks_clear(struct badblocks *bb, sector_t s, int sectors) static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors, sector_t *first_bad, int *bad_sectors) { - int unacked_badblocks, acked_badblocks; + int acked_badblocks; int prev = -1, hint = -1, set = 0; struct badblocks_context bad; unsigned int seq; @@ -1297,7 +1297,6 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors, seq = read_seqbegin(&bb->lock); p = bb->page; - unacked_badblocks = 0; acked_badblocks = 0; re_check: @@ -1318,21 +1317,24 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors, } if (overlap_front(bb, prev, &bad)) { - if (BB_ACK(p[prev])) + if (set == 0) { + *first_bad = BB_OFFSET(p[prev]); + *bad_sectors = BB_LEN(p[prev]); + set = 1; + } + + if (BB_ACK(p[prev])) { acked_badblocks++; - else - unacked_badblocks++; + } else { + rv = -1; + goto out; + } if (BB_END(p[prev]) >= (s + sectors)) len = sectors; else len = BB_END(p[prev]) - s; - if (set == 0) { - *first_bad = BB_OFFSET(p[prev]); - *bad_sectors = BB_LEN(p[prev]); - set = 1; - } goto update_sectors; } @@ -1355,13 +1357,12 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors, WARN_ON(sectors < 0); - if (unacked_badblocks > 0) - rv = -1; - else if (acked_badblocks > 0) + if (acked_badblocks > 0) rv = 1; else rv = 0; +out: if (read_seqretry(&bb->lock, seq)) goto retry; -- 2.39.2