From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753107AbcD1OkA (ORCPT ); Thu, 28 Apr 2016 10:40:00 -0400 Received: from forward9h.cmail.yandex.net ([87.250.230.220]:48637 "EHLO forward9h.cmail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752675AbcD1Oj7 (ORCPT ); Thu, 28 Apr 2016 10:39:59 -0400 X-Greylist: delayed 501 seconds by postgrey-1.27 at vger.kernel.org; Thu, 28 Apr 2016 10:39:59 EDT X-Yandex-ForeignMX: US X-Yandex-Suid-Status: 1 0,1 0,1 0 Date: Thu, 28 Apr 2016 16:31:28 +0200 From: Andrey Gursky To: Vyacheslav Yurkov Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH] drivers/base: wrong return value of dmam_declare_coherent_memory Message-Id: <20160428163128.2670db58033e598779e373f6@e-mail.ua> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.24.30; x86_64-unknown-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Vyacheslav, thanks for your patch. For now it introduces a new bug. Vyacheslav Yurkov gmail.com> writes: > > Hi guys, > I found an issue in managed version of dma_declare_coherent_memory, > i.e. in dmam_declare_coherent_memory. It looks like the return value > of dma_declare_coherent_memory is zero in case of error and a > requested flag on success, You should take this into account and not ignore the value of rc at all by using flags instead, which is not being altered by dma_declare_coherent_memory() making the latter appear to succeed always. > which dmam_* version doesn't take into > account and this leads to leaking of resources. > > --- > Yours sincerely, > Vyacheslav V. Yurkov > > P.S.: I'm not subscribed to the maillist, so please include me in CC > when responding to this Email. > > --- > --- linux-4.5.2/drivers/base/dma-mapping.c.orig 2016-04-20 > 08:46:35.000000000 +0200 > +++ linux-4.5.2/drivers/base/dma-mapping.c 2016-04-28 10:15:34.295080491 > +0200 > -198,10 +198,15 int dmam_declare_coherent_memory(struct > > rc = dma_declare_coherent_memory(dev, phys_addr, device_addr, size, > flags); > - if (rc == 0) > + > + if ((flags & DMA_MEMORY_MAP) == DMA_MEMORY_MAP || > + (flags & DMA_MEMORY_IO) == DMA_MEMORY_IO) { > devres_add(dev, res); > - else > + rc = 0; > + } else { > devres_free(res); > + rc = -ENOMEM; > + } > > return rc; > } > > Signed-off-by: Vyacheslav Yurkov gmail.com> > Best Regards, Andrey