Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp755068pxb; Tue, 5 Apr 2022 21:55:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywMI0U1pE+cKtS8LC1fVLRkQCFhRuWCRvacAZsjI1UI8nNFtkWcIeUr+YkvAX1t5/aKzkU X-Received: by 2002:a05:6a00:1512:b0:4fe:215b:36 with SMTP id q18-20020a056a00151200b004fe215b0036mr7082081pfu.37.1649220932205; Tue, 05 Apr 2022 21:55:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649220932; cv=none; d=google.com; s=arc-20160816; b=ez+Sm1pte1CEC51RGYPpVnpaeQTF5IIS1lpFowuxJBHp+8zcpIiVsOGfh5cU1pQSdM zemIq72uFoxqd1ytCJlpY/BARMCLJRwcK5YQqUUgxVQ/fzaLWHo5KZCLW0diRHbxZ03d nTaJ8Mibgcrm4oGS9n1F8to+d+w/v/WEaHfwP4Nohw+xjIJAQxowQE5gYMuY9KoHAHL0 W2UIBss+8wQGGBwZ/5yyrhQdnmokWk9xifUlroPv6+Ly0m68XLxI6L1jETzqA4II1mWC 8/sc2ulQ2+0WLtMtZWgrsMzO69aUaohW9qVg3IEf6/HlCNEQh16bhm4yk91eZQmBgwMv ZJIQ== 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=iNx09RKDi8srFw0AbSjV9w6i9pE/MGRW19cnHQGAzwY=; b=cb4IXEkeo6WaG+giq9JiP6RWo6oti4kk5/z8rLSYFCCNlkRx5rGDt5InIrL0+8Xjr0 m63XfA3hd1yoz+fotXAlNPO7xkq55628GC+m+xnVsbayZKbdTWW8ErISiwvoyubmnemT lI05zhuNwcaBF5nTiBW7HUUFkSy/kBvE4laUSHJJ0vIKywv/uu3yZFYQ6qQgwTIFdwXG FfdoVGz9qT1QWE+8fURvCYBS3eDKr67YqKN5ppVA/N9/EaqOP6psMcT+MstBM4q236AR 0Za01DlgqykrkfjsfraZzWgFNVnB19/dV4zioxnlIRJlXvqdqoySylXvFj33DlUMXEkI yRaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oXQbq0yS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f29-20020aa79d9d000000b004faf1d84ebcsi13878332pfq.279.2022.04.05.21.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 21:55:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oXQbq0yS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4B49012B5FA; Tue, 5 Apr 2022 20:16:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378975AbiDEMw4 (ORCPT + 99 others); Tue, 5 Apr 2022 08:52:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245337AbiDEJLq (ORCPT ); Tue, 5 Apr 2022 05:11:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34BD32CCBB; Tue, 5 Apr 2022 02:00:05 -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 92976B81A22; Tue, 5 Apr 2022 09:00:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6623C385A0; Tue, 5 Apr 2022 09:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149202; bh=X0rTzsBGeb+2G6pQhnVePEmfjAUos6BVgAr1tfd3tDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oXQbq0ySmEJZYBJIwaGB6+hrILvvZuK1gx8JDZhngM1TrZrmgy6s5OOe6qLn36Ex0 Ela42VT3a9TwTHX+uMHHaVRlWsHSjcuEp0Pt2XI281wpRCs7rhUyHCI5YvL87ARJwc iYP7XcjnE5X2O9cD1c4Kj8CSPUgroYhD1ZVG4+Qw= 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 5.16 0594/1017] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init Date: Tue, 5 Apr 2022 09:25:07 +0200 Message-Id: <20220405070411.909567431@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 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/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..ddd93bc38ea6 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->dmac) + dma_release_channel(nc->dmac); + + return ret; } static int -- 2.34.1