Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp314990pxm; Wed, 2 Mar 2022 16:10:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJyoYELYcsqVknPHin786UZWbNN3jxiNa70Na+8eQV2mf+1Wl3OMychvSlPVYjwWJduafvAT X-Received: by 2002:aa7:9017:0:b0:4df:e33f:f1b4 with SMTP id m23-20020aa79017000000b004dfe33ff1b4mr35702877pfo.80.1646266231510; Wed, 02 Mar 2022 16:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646266231; cv=none; d=google.com; s=arc-20160816; b=OUPJZ73wrPki9/Xjf5j5fVh6iiToJamU00+ZfNPbjEEdq8Kx7XZb4NbPYIAH+dmle/ EvGsL2xRhDyznGE09C9QMuJJebSBjIf6bzRy4fXFW3nQARxoRFnzK7+9WOOXa+M6SZYk xpptOtljp1FVTWnXYhR/sgrSlm1Vgb6wswraptKLb5ZCl3SAh/yB6Uhmaoqqaa2PtEvL HArlj+Hp0zhCq7b8dEKjfdARmOjsWyvSpSI43TPS7kATzlJ+StqlueBhaIreI5iG20Ue cyoFRNwaTPuIzIGQiua4Nbk5DCM4OZPvvkh1Pa7fC0p3kcxICrjMMpfOPqpj8tSrLkhv Ha5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=iMaVXwk3iGrh60WLRmIvGc+VdwFYNW0mHH3SCrZ7WO8=; b=btr1gczf+5Z9sx3gOPDuGNf6wjyxg8CCLHCkrp7wYfa30BPTgkZee6DoB0jyuCGsj3 k6oLpCrsKLLKlQSy8tqDlfpXSbWss2WRzWSERfZrWcUXDpRZ20RyO0/egJmDXzGi9X8G lsV9NaaS7FZiWo0E5JroXDPZCntIjAsDvz9hs7DSqz2XuaeE1ReqShCD2hiPglp+vD8f Zkx/2EPy7ScKYsQ+Pjr3yPuXff9J3LZoFzpCAoNwCyUO2U5OK/Tfe92b1c9S/aWkbfrj +4P4+oiiei2Oh7WZGmQ4ONlFtOrTnCFLe19aT4Z5M2EyiX0aB6RuLL1pyDPgt7wSY6AU nk+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fudan.edu.cn header.s=dkim header.b="v/G8PjMj"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fudan.edu.cn Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id bd10-20020a656e0a000000b003471d131ef0si549711pgb.34.2022.03.02.16.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 16:10:31 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@fudan.edu.cn header.s=dkim header.b="v/G8PjMj"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fudan.edu.cn Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BBDA11BE131; Wed, 2 Mar 2022 15:26:16 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242232AbiCBNbn (ORCPT + 99 others); Wed, 2 Mar 2022 08:31:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237407AbiCBNbl (ORCPT ); Wed, 2 Mar 2022 08:31:41 -0500 Received: from zg8tmty1ljiyny4xntqumjca.icoremail.net (zg8tmty1ljiyny4xntqumjca.icoremail.net [165.227.154.27]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 90AC9BA76B for ; Wed, 2 Mar 2022 05:30:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fudan.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id:MIME-Version:Content-Transfer-Encoding; bh=iMaVXwk3iG rh60WLRmIvGc+VdwFYNW0mHH3SCrZ7WO8=; b=v/G8PjMjWUihvkpKtwrOY3Yq7k Xmd9dva8SrKjgb4bH0MCUdvRzJ2tbak1EKdW0fWs3sFcGiiKaOOc5H7g4Zq+hL2y 3AJv2Lg+QdwDSwIZ/ofJzc9MZdAi41RDdS7heG60XJKxoDs0mc9NBDeCDQOas7Cq sRWTbqtBXQNju7Ce4= Received: from localhost.localdomain (unknown [10.102.225.84]) by app1 (Coremail) with SMTP id XAUFCgCnvMBWcR9iqJhcCg--.35820S4; Wed, 02 Mar 2022 21:30:03 +0800 (CST) From: Xin Xiong To: Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Boris Brezillon , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: yuanxzhang@fudan.edu.cn, Xin Xiong , Xiyu Yang , Xin Tan Subject: [PATCH v3] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init Date: Wed, 2 Mar 2022 21:27:59 +0800 Message-Id: <20220302132758.3820-1-xiongx18@fudan.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: XAUFCgCnvMBWcR9iqJhcCg--.35820S4 X-Coremail-Antispam: 1UD129KBjvJXoW7Zw47ZF4DGrW7uF4rZw47urg_yoW8trykpF WUJFW3ZFWUtFs3ZF12kayxuF1rZ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Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The reference counting issue happens in several error handling paths on a refcounted object "nc->dmac". In these paths, the function simply returns the error code, forgetting to balance the reference count of "nc->dmac", increased earlier by dma_request_channel(), which may cause refcount leaks. Fix it by decrementing the refcount of specific object in those error paths. Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver") Co-developed-by: Xiyu Yang Signed-off-by: Xiyu Yang Co-developed-by: Xin Tan Signed-off-by: Xin Tan Signed-off-by: Xin Xiong --- V2 -> V3: Removed redundant lines V1 -> V2: Rewrited the error handling block --- drivers/mtd/nand/raw/atmel/nand-controller.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c index f3276ee9e4fe..3dc4a4bacde5 100644 --- a/drivers/mtd/nand/raw/atmel/nand-controller.c +++ b/drivers/mtd/nand/raw/atmel/nand-controller.c @@ -2060,13 +2060,15 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc, nc->mck = of_clk_get(dev->parent->of_node, 0); if (IS_ERR(nc->mck)) { dev_err(dev, "Failed to retrieve MCK clk\n"); - return PTR_ERR(nc->mck); + ret = PTR_ERR(nc->mck); + goto out_release_dma; } np = of_parse_phandle(dev->parent->of_node, "atmel,smc", 0); if (!np) { dev_err(dev, "Missing or invalid atmel,smc property\n"); - return -EINVAL; + ret = -EINVAL; + goto out_release_dma; } nc->smc = syscon_node_to_regmap(np); @@ -2074,10 +2076,16 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc, if (IS_ERR(nc->smc)) { ret = PTR_ERR(nc->smc); dev_err(dev, "Could not get SMC regmap (err = %d)\n", ret); - return ret; + goto out_release_dma; } return 0; + +out_release_dma: + if (nc->caps->has_dma && !atmel_nand_avoid_dma && nc->dmac) + dma_release_channel(nc->dmac); + + return ret; } static int -- 2.25.1