From patchwork Tue Oct 17 15:56:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: weiping zhang X-Patchwork-Id: 10012353 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 E3EC7600CC for ; Tue, 17 Oct 2017 15:56:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1FE1285D5 for ; Tue, 17 Oct 2017 15:56:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C69D02896B; Tue, 17 Oct 2017 15:56: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 1D6AB285D5 for ; Tue, 17 Oct 2017 15:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965339AbdJQP4d (ORCPT ); Tue, 17 Oct 2017 11:56:33 -0400 Received: from mx1.didichuxing.com ([111.202.154.82]:7825 "EHLO BJEXCAS005.didichuxing.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965224AbdJQP4c (ORCPT ); Tue, 17 Oct 2017 11:56:32 -0400 Received: from bogon.didichuxing.com (172.22.50.20) by BJSGEXMBX03.didichuxing.com (172.20.15.133) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Tue, 17 Oct 2017 23:56:26 +0800 Date: Tue, 17 Oct 2017 23:56:21 +0800 From: weiping zhang To: CC: , Subject: [PATCH v4] blkcg: add sanity check for blkcg policy operations Message-ID: <20171017155621.GA38911@bogon.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. Reviewed-by: Johannes Thumshirn Signed-off-by: weiping zhang --- Changes since V4: * merge "if(cpd->xxx)" and "if(pd->xxx)" together Changes since V3: * make if more cleaner by using !pold->cpd_alloc_fn ^ !pol->cpd_free_fn Chagnes since V2: * merge blkcg_policy_check_ops into the caller blkcg_policy_register V1: * add blkcg_policy_check_ops to check cpd/pd's alloc_fn and free_fn in * pairs. block/blk-cgroup.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index e7ec676..4117524 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1419,6 +1419,11 @@ int blkcg_policy_register(struct blkcg_policy *pol) if (i >= BLKCG_MAX_POLS) goto err_unlock; + /* Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs */ + if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) || + (!pol->pd_alloc_fn ^ !pol->pd_free_fn)) + goto err_unlock; + /* register @pol */ pol->plid = i; blkcg_policy[pol->plid] = pol;