From patchwork Wed Oct 11 09:46:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: weiping zhang X-Patchwork-Id: 9999161 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 53029603B5 for ; Wed, 11 Oct 2017 09:46:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4498E289A3 for ; Wed, 11 Oct 2017 09:46:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 395A9289AA; Wed, 11 Oct 2017 09:46:36 +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=-5.3 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, URIBL_SBL 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 EE55A289A9 for ; Wed, 11 Oct 2017 09:46:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752346AbdJKJqe (ORCPT ); Wed, 11 Oct 2017 05:46:34 -0400 Received: from 22.17.110.36.static.bjtelecom.net ([36.110.17.22]:14758 "EHLO BJEXCAS002.didichuxing.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751415AbdJKJqc (ORCPT ); Wed, 11 Oct 2017 05:46:32 -0400 Received: from localhost.didichuxing.com (172.22.50.20) by BJSGEXMBX03.didichuxing.com (172.20.15.133) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 11 Oct 2017 17:46:28 +0800 Date: Wed, 11 Oct 2017 17:46:23 +0800 From: weiping zhang To: , CC: Subject: [PATCH v2] blkcg: add sanity check for blkcg policy operations Message-ID: <20171011094619.GA37417@localhost.didichuxing.com> Mail-Followup-To: axboe@kernel.dk, jthumshirn@suse.de, linux-block@vger.kernel.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [172.22.50.20] X-ClientProxiedBy: BJEXCAS004.didichuxing.com (172.20.1.44) To BJSGEXMBX03.didichuxing.com (172.20.15.133) 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 blkcg policy should keep cpd/pd's alloc_fn and free_fn in pairs, otherwise policy would register fail. Signed-off-by: weiping zhang --- block/blk-cgroup.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index e7ec676..67b01c5 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1419,6 +1419,16 @@ int blkcg_policy_register(struct blkcg_policy *pol) if (i >= BLKCG_MAX_POLS) goto err_unlock; + /* Make sure cpd_alloc_fn and cpd_free_fn in pairs */ + if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) || + (!pol->cpd_alloc_fn && pol->cpd_free_fn)) + goto err_unlock; + + /* Make sure pd_alloc_fn and pd_free_fn in pairs */ + if ((pol->pd_alloc_fn && !pol->pd_free_fn) || + (!pol->pd_alloc_fn && pol->pd_free_fn)) + goto err_unlock; + /* register @pol */ pol->plid = i; blkcg_policy[pol->plid] = pol;