Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp981839iob; Fri, 13 May 2022 18:30:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwefZ0ZCVJ0Tl5Sf/XilNXY1LapEFXaNP0iyBOYMrcT3LniAR5iWdHkmW1WQvp+Z5+T5+ix X-Received: by 2002:adf:f58e:0:b0:20a:dfc8:f894 with SMTP id f14-20020adff58e000000b0020adfc8f894mr5985508wro.428.1652491809409; Fri, 13 May 2022 18:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652491809; cv=none; d=google.com; s=arc-20160816; b=HN9kWMnVcxXvCbOysp3b75Rp6sHvFdyL8HGFOZd2fF87fLMuqI5f0dZj1qW3Pvis6i X2azZd8we+1d6JlL/P1z2K/gvG7iwteq1L94BWevlQvhFKa8bPOM5g6oaFUix01hvt22 OTomVkKL6/4qb4l2NSk7Ivlb64gV8uzoDmPrTNwvZ/8bDv339RnRjBlxgkBdojc1l9zl tLDh8f3oJhEbwE51K3EuT4SUE2ykW6KNJiCMBmcAoxjADXce9Qb257Uyj/tmrxTBoR9I 9m7NxR1R6/7II8ykQZF7CniYys4hJ3DxrQOSXwdM160xuK8qmSRghmYt+pAMcaUwb6fw YICw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=DvfUSg18sP/pij1FLJomJh/JLDarh/cSSUwwqyQdn1A=; b=Kxfh8RgtjeQqtjT20XKCM0+ya4wVXL5SUfY/Gpt3YMs3eXkEvPLeyNXAGHinELxgI1 qXdkRoyj+BrTnWzOr4bphYDLsq/D1u68DzFrSS6p2Yz69pVAGNEtxOzKa5UNJK7Jpeql xaHCNslaW/oUQOBvchF4Yf0gztORI+gG2MGgjwDX0VB3zFx8erkNfFngc1WNu3WOOplP 3LGhMlzhMHyTn3jGIBWYz18hFnci3kPQBWE1vNhihAeVHkD7gecsUIp7blrImnIhqWUm ar05ZtN/R0BsLeqHoq6A3Ax1NXliNwS59HwkU/aiGA8YizOz9sgcRta/V8KIGZ5rubWm pw0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mFy0kQCY; 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=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e1-20020a5d6d01000000b00206cc1a0200si3295374wrq.533.2022.05.13.18.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:30:09 -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=@intel.com header.s=Intel header.b=mFy0kQCY; 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=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 009753F85F8; Fri, 13 May 2022 16:58:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356828AbiELRFZ (ORCPT + 99 others); Thu, 12 May 2022 13:05:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356824AbiELRFY (ORCPT ); Thu, 12 May 2022 13:05:24 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07114269EE4; Thu, 12 May 2022 10:05:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652375122; x=1683911122; h=message-id:date:mime-version:subject:to:references:from: in-reply-to:content-transfer-encoding; bh=6xFxG7MLoudi9o64Lr4POIQA3LoUtodJPfElK3mM7f0=; b=mFy0kQCYN9R4A9RXFXzact5Pzvtnzdrld6Av2LQAItp1TJf0qNMjvetP 9DLjb+ZKKEUWxjt0UHSOkfjXCmaOp0ZvJNX0PwBCt1iYWtdi1rbaNz1dD VDB2XnDkRbL5xezV9LxxGDuwxdJ558UJPgjHvKQxf9dVxv9f/Fh7PV24J QbHQzvRDbtuzL/L+25ucaOne7AJGsVoHXpGrrQzHvi4A0fTVzqN8qlGjJ HVCwLKOHNTGSMOkhlGS6+k7Si8XVZGGZXk/0R7OlIDv5gBFSo2ZJHcUdi 9iXaFGJfSTNp3AwQdFJbaouCWK0LXHlZQglS08v4IotYBl0TSkGaLLPOc w==; X-IronPort-AV: E=McAfee;i="6400,9594,10345"; a="269741443" X-IronPort-AV: E=Sophos;i="5.91,220,1647327600"; d="scan'208";a="269741443" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2022 10:03:48 -0700 X-IronPort-AV: E=Sophos;i="5.91,220,1647327600"; d="scan'208";a="521038993" Received: from djiang5-mobl1.amr.corp.intel.com (HELO [10.212.68.97]) ([10.212.68.97]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2022 10:03:48 -0700 Message-ID: Date: Thu, 12 May 2022 10:03:48 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH] dmaengine: ti: Fix refcount leak in ti_dra7_xbar_route_allocate Content-Language: en-US To: Miaoqian Lin , Peter Ujfalusi , Vinod Koul , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220512051815.11946-1-linmq006@gmail.com> From: Dave Jiang In-Reply-To: <20220512051815.11946-1-linmq006@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 5/11/2022 10:18 PM, Miaoqian Lin wrote: > 1. of_find_device_by_node() takes reference, we should use put_device() > to release it when not need anymore. > 2. of_parse_phandle() returns a node pointer with refcount > incremented, we should use of_node_put() on it when not needed anymore. > > Add put_device() and of_node_put() in some error paths to fix. Sounds like you need 2 patches for this? One just for the put_device() and the other for the of_node_put()? > > Fixes: ec9bfa1e1a79 ("dmaengine: ti-dma-crossbar: dra7: Use bitops instead of idr") > Fixes: a074ae38f859 ("dmaengine: Add driver for TI DMA crossbar on DRA7x") > Signed-off-by: Miaoqian Lin > --- > drivers/dma/ti/dma-crossbar.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/dma/ti/dma-crossbar.c b/drivers/dma/ti/dma-crossbar.c > index 71d24fc07c00..f744ddbbbad7 100644 > --- a/drivers/dma/ti/dma-crossbar.c > +++ b/drivers/dma/ti/dma-crossbar.c > @@ -245,6 +245,7 @@ static void *ti_dra7_xbar_route_allocate(struct of_phandle_args *dma_spec, > if (dma_spec->args[0] >= xbar->xbar_requests) { > dev_err(&pdev->dev, "Invalid XBAR request number: %d\n", > dma_spec->args[0]); > + put_device(&pdev->dev); > return ERR_PTR(-EINVAL); > } > > @@ -252,12 +253,14 @@ static void *ti_dra7_xbar_route_allocate(struct of_phandle_args *dma_spec, > dma_spec->np = of_parse_phandle(ofdma->of_node, "dma-masters", 0); > if (!dma_spec->np) { > dev_err(&pdev->dev, "Can't get DMA master\n"); > + put_device(&pdev->dev); > return ERR_PTR(-EINVAL); > } > > map = kzalloc(sizeof(*map), GFP_KERNEL); > if (!map) { > of_node_put(dma_spec->np); > + put_device(&pdev->dev); > return ERR_PTR(-ENOMEM); > } > > @@ -268,6 +271,8 @@ static void *ti_dra7_xbar_route_allocate(struct of_phandle_args *dma_spec, > mutex_unlock(&xbar->mutex); > dev_err(&pdev->dev, "Run out of free DMA requests\n"); > kfree(map); > + of_node_put(dma_spec->np); > + put_device(&pdev->dev); > return ERR_PTR(-ENOMEM); > } > set_bit(map->xbar_out, xbar->dma_inuse);