Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3837392pxb; Tue, 19 Apr 2022 10:45:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMXVwy6EiSxRwFYSuwaDLI6q1VDRBV0HPcvI4zc2DG4CeL6pupniucUvtZaCFps+VUm1x7 X-Received: by 2002:a17:902:b10c:b0:154:a3b5:b33a with SMTP id q12-20020a170902b10c00b00154a3b5b33amr16307006plr.3.1650390340548; Tue, 19 Apr 2022 10:45:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650390340; cv=none; d=google.com; s=arc-20160816; b=dNRxm+ytdvtTVs0TqlJpGULsXBffU/d3VUzFwb90J0rflsYYgneb+Q5iCZDmSTz4e8 FLVDbt1Qaf1HHXIzXEBvAl2MkCYXqqJwl9PfjQ6crLkiwmDZ0P/QhXIBAUE9aLHrXf2c 9H0lCVspS2XzCIWMxt0lV82HjUdWb8E0g/mS1JIMPOoTSKTc5HkdsujeYXNjnOm8RHbt w7mscHZZ06HY29rUn2gSj33uIEjR36RJKsbHD6qJskxn6wnN+Sd27j7oKp/RASKmMvAo pWfJwf3SWko0CCHVxyHfPD/5EkRcugkWfmTXOdqbiDUrlXfskX0Ncwpk1sBEdAAtmsYu sphw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=I/6lIrmI/D+30WkWJVUchZT15Wpr4KP/NnooMe7fxxA=; b=O/75x4tbitQd1UTO5g8SFqba4ZlG6ywwMUcNOE1uBqls4KnXxANXFulN1+6dGTBcBD gyTlj54TPdZZgq3362q2WOc0UwUlQcQ24zgM55g45I8B+lTbOLz2D+Ic0xGK67GPx+Ru 6vy6fW/iQZZYW807W3PKaovK6PhwMDakZIcCgr8N30TKNixQh7Ec3qH7fjmROVu5lE/B gBaXkPc4HwM9Tz0VxUmjxaXhCXPSq4XznZEh3XsUxlHv1TXUU1d7WcO8Bb3VWAsZ/aMR 3j424YceFwJBggmyajq20T3QFV4Y4HFYyDZeunEfRi3oDlp8pLeBaTwl5sHB5NELjB7l cWEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Pi/ISS/D"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o15-20020a056a00214f00b004fb83b0732dsi11662228pfk.323.2022.04.19.10.45.23; Tue, 19 Apr 2022 10:45:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Pi/ISS/D"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245129AbiDRNwe (ORCPT + 99 others); Mon, 18 Apr 2022 09:52:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243355AbiDRN24 (ORCPT ); Mon, 18 Apr 2022 09:28:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B89E63F309; Mon, 18 Apr 2022 05:53:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E259BB80D9C; Mon, 18 Apr 2022 12:53:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DB42C385A1; Mon, 18 Apr 2022 12:53:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286408; bh=uwWUHcocqa18DATC5hnFI4mO2NFYAmc2DXMf4447H+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pi/ISS/Dd2aCLujLLobdstcNOLxeMiv6fLn+cZMGJ2KJt0ul0g8j2rG2H4VKGBsWD z4oyfNKrbcyJYH+2jSwYgrK32XPFAuauvah+wuCc+7i7MS6QEnlKaorLVjz2oq0Mp6 2+TkdFsy+4TgQJSMhp0esouGNBRR88F/5wfLeqKQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiyu Yang , Xin Tan , Xin Xiong , Claudiu Beznea , Miquel Raynal , Sasha Levin Subject: [PATCH 4.14 123/284] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init Date: Mon, 18 Apr 2022 14:11:44 +0200 Message-Id: <20220418121214.658422150@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Xin Xiong [ Upstream commit fecbd4a317c95d73c849648c406bcf1b6a0ec1cf ] 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 Reviewed-by: Claudiu Beznea Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20220304085330.3610-1-xiongx18@fudan.edu.cn Signed-off-by: Sasha Levin --- drivers/mtd/nand/atmel/nand-controller.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/atmel/nand-controller.c b/drivers/mtd/nand/atmel/nand-controller.c index d5a493e8ee08..475c751f2d1e 100644 --- a/drivers/mtd/nand/atmel/nand-controller.c +++ b/drivers/mtd/nand/atmel/nand-controller.c @@ -1998,13 +1998,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); @@ -2012,10 +2014,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->dmac) + dma_release_channel(nc->dmac); + + return ret; } static int -- 2.34.1