Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp690421pxb; Tue, 5 Apr 2022 18:56:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycmyGeknCckCmWJ8CyQBq9c1u0j9RimbwnKINSDOqcxEyXhU65cjcRb6YpesH1ukfYXRxp X-Received: by 2002:a17:903:2cd:b0:156:780d:5b69 with SMTP id s13-20020a17090302cd00b00156780d5b69mr6338472plk.156.1649210184767; Tue, 05 Apr 2022 18:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649210184; cv=none; d=google.com; s=arc-20160816; b=jfInbNZM6BqjwiiH35RMocWXiJgiAFiUnZxzH81xlDCPiCIlddumQt8/TnrBysx/nE 1tmQYGOfevPeVJDTRqOVJotAc4mx+mbLE/wRtOlf1uiZJIHN3Da9XhB/XkhnPr1EYJ6r Dn6AMIgabp173uEGgfnVBT/oqXGKXb3d0Hu1a7xhZn/wR8KI08BU+GMnnqvgbX+aHhPu f1kBrT+0BZvU/wh58AI2NrjcdvnxPXa/Dxs8dU9qCl4DATRYolH8Fr9jTVbheWsj7wol Z7a86jz7d9h/A7+W8YpXUQ/kxXTbL+SGQ8yi7VRg59EOGZgtWk5leZUpgh0dLlNL2TWI XwaA== 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=QP2dQSUkHgIuCRPUVepFsGoS1TSRg9UC/vpQmpynl4tAxaIfd4bXVUgicuSZ2tEJ4B yxzi73MCiRY4tK2tUNHH/WZI2/tP54hZhDY7N/eyOW6PuaZBvPmZfiKQC/KD8BRZeubJ K2gNngr3mrslXykU0NeqOHaa7JcqgwdlTepeGRFne7Yzlgg3dSMboIUMMK0KoB9zPQj9 aiSVi220HU7NxMyoWhXu4tFiw1JmKjhZEeMKIsl6vC1+Aot6mBfjXK1HxmTzii1CZRcL /ySsvzKpEPc5xeakC5eFhGSjhasf9R5i4yHR7bfcDltRYD8E1s3NmusoRQw0XpaPB66J KonA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gKi9mJ6M; 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 m1-20020a170902f64100b001567cbd9a37si11209031plg.223.2022.04.05.18.56.10; Tue, 05 Apr 2022 18:56:24 -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=gKi9mJ6M; 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 S1350440AbiDEJ6Q (ORCPT + 99 others); Tue, 5 Apr 2022 05:58:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238456AbiDEITH (ORCPT ); Tue, 5 Apr 2022 04:19:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F30F9DEA3; Tue, 5 Apr 2022 01:08:57 -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 37462B81A32; Tue, 5 Apr 2022 08:08:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 979C5C385A0; Tue, 5 Apr 2022 08:08:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146135; bh=X0rTzsBGeb+2G6pQhnVePEmfjAUos6BVgAr1tfd3tDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gKi9mJ6MywLpRltIlBdzoezf/Xg0P4ElweLlExvhqGpkHGy6Yd5fKkJ2sTdDzTnFo iFGAABC3GIo0jEtGPCm+9muz3LDYXV/56IdvcAMpZJuRI9GjugyiXYmD8fBBZyRPK3 se4dHW4CKPUyOYVlrHDxcXf6NfzXmO1JDYLoOe9M= 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.17 0655/1126] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init Date: Tue, 5 Apr 2022 09:23:22 +0200 Message-Id: <20220405070426.856215230@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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.1 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/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