From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63BAFC2D0C3 for ; Tue, 24 Dec 2019 04:37:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C3A420718 for ; Tue, 24 Dec 2019 04:37:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577162239; bh=MTC8x6597YAibU9FQCS3ExzUhGCIVEAaMacsH86pYiM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=rp2WVUGyvo4vEt3qdCErnPoNq3JIQYm0DFj0OFCE2q0eA1IjWlciFzVu7v5D0AaQf ngLn7ODRYpGCAg+zywq5u6A8D0aYAaBeWt7N3WR20kTV/NooV1jsCa4W5FzxmdU8K/ VFSu8t3t2AZRrF0JQw+3WEPs8+GiebU+W094DCrg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726861AbfLXEhS (ORCPT ); Mon, 23 Dec 2019 23:37:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:44142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726853AbfLXEhS (ORCPT ); Mon, 23 Dec 2019 23:37:18 -0500 Received: from localhost (unknown [122.167.68.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4468C206CB; Tue, 24 Dec 2019 04:37:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577162238; bh=MTC8x6597YAibU9FQCS3ExzUhGCIVEAaMacsH86pYiM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tJljMcQgPMazwkiE30XJib/B4iEsUNt3YxCMH1ktyaETGf4selR9MDcqqVGUilygL Q4xJ5UaKJo1npm3kuwuTi2WSw1YgmJWwYoV+UiAq+zMwsrjbexjmq489g3kMSRVzg0 7a7ld1ZJlG98f0G5/Y18AkfBHOjh6jEszOWYBCvQ= Date: Tue, 24 Dec 2019 10:07:13 +0530 From: Vinod Koul To: Logan Gunthorpe Cc: linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, Dan Williams , Dave Jiang , Kit Chow Subject: Re: [PATCH 2/5] dmaengine: Call module_put() after device_free_chan_resources() Message-ID: <20191224043713.GH2536@vkoul-mobl> References: <20191216190120.21374-1-logang@deltatee.com> <20191216190120.21374-3-logang@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191216190120.21374-3-logang@deltatee.com> Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org On 16-12-19, 12:01, Logan Gunthorpe wrote: > The module reference is taken to ensure the callbacks still exist > when they are called. If the channel holds the last reference to the > module, the module can disappear before device_free_chan_resources() is > called and would cause a call into free'd memory. > > Signed-off-by: Logan Gunthorpe > --- > drivers/dma/dmaengine.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c > index 4b604086b1b3..776fdf535a3a 100644 > --- a/drivers/dma/dmaengine.c > +++ b/drivers/dma/dmaengine.c > @@ -250,7 +250,6 @@ static void dma_chan_put(struct dma_chan *chan) > return; > > chan->client_count--; > - module_put(dma_chan_to_owner(chan)); > > /* This channel is not in use anymore, free it */ > if (!chan->client_count && chan->device->device_free_chan_resources) { > @@ -259,6 +258,8 @@ static void dma_chan_put(struct dma_chan *chan) > chan->device->device_free_chan_resources(chan); > } > > + module_put(dma_chan_to_owner(chan)); > + > /* If the channel is used via a DMA request router, free the mapping */ > if (chan->router && chan->router->route_free) { > chan->router->route_free(chan->router->dev, chan->route_data); I think this should be moved here after route_free() and will take care of route cleanup as well Thanks -- ~Vinod