From patchwork Thu Aug 10 01:22:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Qi X-Patchwork-Id: 9892473 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 8A83B60236 for ; Thu, 10 Aug 2017 01:23:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CF0428A08 for ; Thu, 10 Aug 2017 01:23:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7025D28A05; Thu, 10 Aug 2017 01:23:08 +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 3812E28A08 for ; Thu, 10 Aug 2017 01:23:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752174AbdHJBXF (ORCPT ); Wed, 9 Aug 2017 21:23:05 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:34051 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752098AbdHJBXF (ORCPT ); Wed, 9 Aug 2017 21:23:05 -0400 Received: by mail-oi0-f68.google.com with SMTP id v11so7302414oif.1 for ; Wed, 09 Aug 2017 18:23:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=6NeIu2ryKkm1QITvOHwvkgBKL+C668PIVW6Bu379pO4=; b=KT8NguX4Iymjts3MMs/sg4z/hG8wCgg/XimJhpDG+GtZ2Nve0oCOsldHtFaim5xI/p ULltfSoE1x3E99f+buiRXKfkXEUhoNipoRGCrtiRhRIZckJZNqcArTB+Er7tuAuHsjY9 YOBZB4Ydjy1A66De6ZRVhZwuPg+xXZUf4J+z12CQapB6DiQ+sf7REeGncPJZEgsa/HoJ HlB7Zj3odDASHA7Xy100lRkWYsfznVRb+mz92f9OxmMeVT8s6ivN+oWs88aPuB0RMNCQ PDvpLvcs8MfLX7U7vTGuRMkAWsomepPaSXRhRr2Ff6uqUjidLDSfo2mO8Gc4IUq0C41a bLYw== 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:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=6NeIu2ryKkm1QITvOHwvkgBKL+C668PIVW6Bu379pO4=; b=RiaNuQF2ZfzAlf2oX22qo5ThysSrSObYiQw7InstmCk0Ot5832wyM7ez900U3W7ybN TfKoSxAKBKNZ7hqIC139oyeuXNKw8TeMVH8ZRG98FdzSteGAkaOU8J5knp/LY0Qgyjzf XmxeEL5xjCDr+T8JQsySuMpE+qNaSW0WxSlFEh7Wcgm5BmCglMHJl882xfIU0u/dme3z F/WzowoN2jjYkq0FSqiNnhP3rydCyOnaKc9UOCevIYnGo2HRrzGTKKS9S1vUNkPu4A/Y m7vOuf3KxR4dZJuFUzNyME5eRYAMLnpHE6cWgtLRu+Yh9wBplZoBKdttvnLzFIuPQm9G h60Q== X-Gm-Message-State: AHYfb5jwHJ5+3t7m2V6prpHYvtCxcGLmAeTOhKPPnsiI6Uw1If4HZrbK DnU1EmjJzxZE0w== X-Received: by 10.202.67.7 with SMTP id q7mr7495432oia.62.1502328184580; Wed, 09 Aug 2017 18:23:04 -0700 (PDT) Received: from JosephdeMacBook-Pro.local ([205.204.117.3]) by smtp.gmail.com with ESMTPSA id p63sm6568104oie.8.2017.08.09.18.22.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Aug 2017 18:23:04 -0700 (PDT) From: Joseph Qi To: linux-block@vger.kernel.org Cc: Jens Axboe , boyu.mt@taobao.com, wenqing.lz@taobao.com, qijiang.qj@alibaba-inc.com Subject: blk-throttle: fix potential NULL pointer dereference in throtl_select_dispatch Message-ID: <9b5dd19b-7dfd-7f10-fe7d-ff80e0440b99@gmail.com> Date: Thu, 10 Aug 2017 09:22:48 +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);