From patchwork Tue Aug 15 00:54:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Qi X-Patchwork-Id: 9900421 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BF7696038C for ; Tue, 15 Aug 2017 00:54:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B186D286D2 for ; Tue, 15 Aug 2017 00:54:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A657C28773; Tue, 15 Aug 2017 00:54:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AFE0286D2 for ; Tue, 15 Aug 2017 00:54:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752902AbdHOAyg (ORCPT ); Mon, 14 Aug 2017 20:54:36 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:36870 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752899AbdHOAyf (ORCPT ); Mon, 14 Aug 2017 20:54:35 -0400 Received: by mail-oi0-f67.google.com with SMTP id j194so10803009oib.4 for ; Mon, 14 Aug 2017 17:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=6NeIu2ryKkm1QITvOHwvkgBKL+C668PIVW6Bu379pO4=; b=W7kyZ/8zQ5FlXCwPQB16Dc+MDt/W3kHUVDJyt1XsSDLd7q0RCyrTRb7+0AQuYooi35 3bd4uzSyVZ4ODxbuVvRKApumC6Jq6Mokx4I1XMXoE3q/Ymkou6CbIywnzHABBC6we7zX 2xOW0kMHLflFHBW8CpuuSoz9djKe6IsqMKbl44nzEHcZN7IeMKpKowqjAKFlsUWS5YZm aeNR3wJ6rdyGoCQgkD+wnuru4mZz/V9i2jux6c2cDt91x++HGR5SpI0Ev4q1p9Ui2TPY QfaMDt1vObA+4/cmbwEcUtA/BPKG6QBG7bysFhdKw1yf4bY4jfpgVAUlHDuxBA4lzwpm L1Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=6NeIu2ryKkm1QITvOHwvkgBKL+C668PIVW6Bu379pO4=; b=nAsHrAJfny4vB5YmIrl1tHR+s+fYriJcaCeMzyqTu+jay1/s0Hb5aX7nGhjBQgp6oY xmRlHnI3e43xBocn8xhaKG9Wz9kUdnqUYtUwgHkegWhhNYdUk7RDq3Qaq91jm4DSg8qE 8gf4aSAUCAJ5dNFgGQlKozQAKm3pempTPy+qhj6eBNhB6huW4+ceVLhER8O4hlyck9tX WUeP9rm82bfQHQdSYexerL/Lg5kQgwaWSYVJuvbAXCcAnhHih0XiZqzifVxJee9r2rDU 6kGnP7d5X4prsJGR4e75Ra+39mJxboTaOqW4hlieMWdD9qyudbR6gAcgZ1KW5y2LUtRS YXSg== X-Gm-Message-State: AHYfb5gT8nODzYT4TxxoPoUttUKCTSx+Exdf7doOPZU8ociDWzZ6LGn0 idGXMU5YXicOXQ== X-Received: by 10.202.67.6 with SMTP id q6mr32827674oia.144.1502758475345; Mon, 14 Aug 2017 17:54:35 -0700 (PDT) Received: from JosephdeMacBook-Pro.local ([205.204.117.18]) by smtp.gmail.com with ESMTPSA id w128sm9247173oiw.9.2017.08.14.17.54.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 17:54:34 -0700 (PDT) To: linux-block@vger.kernel.org Cc: Jens Axboe , qijiang.qj@alibaba-inc.com From: Joseph Qi Subject: [PATCH RESEND] blk-throttle: fix potential NULL pointer dereference in throtl_select_dispatch Message-ID: <43a4a32d-4eb2-4b1b-541f-f0593ad90851@gmail.com> Date: Tue, 15 Aug 2017 08:54:24 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Language: en-US Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Joseph Qi Since throtl_rb_first may return NULL, so it should check tg first and then use it. Signed-off-by: Joseph Qi --- block/blk-throttle.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index a7285bf..c1d2c5b 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -1201,7 +1201,7 @@ static int throtl_select_dispatch(struct throtl_service_queue *parent_sq) while (1) { struct throtl_grp *tg = throtl_rb_first(parent_sq); - struct throtl_service_queue *sq = &tg->service_queue; + struct throtl_service_queue *sq; if (!tg) break; @@ -1213,6 +1213,7 @@ static int throtl_select_dispatch(struct throtl_service_queue *parent_sq) nr_disp += throtl_dispatch_tg(tg); + sq = &tg->service_queue; if (sq->nr_queued[0] || sq->nr_queued[1]) tg_update_disptime(tg);