From patchwork Wed Nov 18 13:07:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 7648571 X-Patchwork-Delegate: axboe@kernel.dk Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5DB76BF90C for ; Wed, 18 Nov 2015 13:08:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C14F205FF for ; Wed, 18 Nov 2015 13:08:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9324920416 for ; Wed, 18 Nov 2015 13:08:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755776AbbKRNI3 (ORCPT ); Wed, 18 Nov 2015 08:08:29 -0500 Received: from m50-133.163.com ([123.125.50.133]:48536 "EHLO m50-133.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755773AbbKRNI2 (ORCPT ); Wed, 18 Nov 2015 08:08:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=BJbfcZmf6Wv1P03nDz giJuzlcH95zh1rC6k+9bWxsd8=; b=AgK8+5ILtvVNGM0CqNh3cnLRhDOpgz1NCD L0wTJz4y7qj8XwG8+TNbxdxOCtDdwPnz2CF+Aws2SVlhrPpYGjRK65zAOKO2GTBO L2iYCcVJxZMWdcDgBjjMUnzp3OUTb5a5YMhXKp4cW6OIQFVc5ADXCDtF6OqSNMd/ enLlSNs7Q= Received: from localhost (unknown [116.77.130.235]) by smtp3 (Coremail) with SMTP id DdGowEAJoEQXeExWDWgjAA--.14632S3; Wed, 18 Nov 2015 21:07:37 +0800 (CST) From: Geliang Tang To: Jens Axboe Cc: Geliang Tang , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] blk-throttle: use list_first_entry_or_null() Date: Wed, 18 Nov 2015 21:07:31 +0800 Message-Id: <8e96d9ad3e820a9ac346c0d2924507e9d34465b1.1447851969.git.geliangtang@163.com> X-Mailer: git-send-email 2.5.0 X-CM-TRANSID: DdGowEAJoEQXeExWDWgjAA--.14632S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7uFy5Gr1DGFWrGr4fCF1fCrg_yoW8Jw4xpF yayw4DW3ykJrsagryFyw4YkFWaqan7ArWDt3sxCw4rtFW2qw4fWF15Zry8Aa1rAFZ3Wr42 vr4UKr43JF4UGFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UonQUUUUUU= X-Originating-IP: [116.77.130.235] X-CM-SenderInfo: 5jhoxtpqjwt0rj6rljoofrz/1tbiMBq2mVWBSh3wXQAAsr Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Simplify the code with list_first_entry_or_null(). Signed-off-by: Geliang Tang --- block/blk-throttle.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 2149a1d..db2dbf1 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -263,10 +263,11 @@ static void throtl_qnode_add_bio(struct bio *bio, struct throtl_qnode *qn, */ static struct bio *throtl_peek_queued(struct list_head *queued) { - struct throtl_qnode *qn = list_first_entry(queued, struct throtl_qnode, node); + struct throtl_qnode *qn; struct bio *bio; - if (list_empty(queued)) + qn = list_first_entry_or_null(queued, struct throtl_qnode, node); + if (!qn) return NULL; bio = bio_list_peek(&qn->bios); @@ -291,10 +292,11 @@ static struct bio *throtl_peek_queued(struct list_head *queued) static struct bio *throtl_pop_queued(struct list_head *queued, struct throtl_grp **tg_to_put) { - struct throtl_qnode *qn = list_first_entry(queued, struct throtl_qnode, node); + struct throtl_qnode *qn; struct bio *bio; - if (list_empty(queued)) + qn = list_first_entry_or_null(queued, struct throtl_qnode, node); + if (!qn) return NULL; bio = bio_list_pop(&qn->bios);