Received: by 10.223.185.116 with SMTP id b49csp1257469wrg; Wed, 21 Feb 2018 15:13:58 -0800 (PST) X-Google-Smtp-Source: AH8x226GzbEH3ghGTbF/4JoK1Erv/sc0yR2r6fi9itgvOk8GcyKohQyYIAMEdX2OBsp2gM9qaJrg X-Received: by 10.99.124.68 with SMTP id l4mr3950845pgn.225.1519254838072; Wed, 21 Feb 2018 15:13:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519254838; cv=none; d=google.com; s=arc-20160816; b=v53TyWsrx9PSKt5i6XFD8A89nDxCUdAshcZe34OQNOxXdxFgZevnHdzd5KtmDto06O 6FJuTvU5x1Ccig65rCjPpwCrq4DTzeB0wmbkF7ZlPMRomMHjrBSW+zOP1XTqv9Yw6bKd wUVID+qvQ1OT+DHBhL0RkH1ntfV4sq0vRawOaxRsZ0UOjhF6SqJVKV9iAIpXXMmZgiod x9qdnUp+EyhdquEntzS2A93Elm6eVOScsJc5x+b83zv4FgcLX7sQf+HG/45jxdI/rToq UM0ROynmmLbo02BiIqZWfRvxeKgHn7DyJv0Ztnqxc9JcivKKr0W7W9KzfqcAESAAIYHF UX8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=fQXG8v5Uxp+tc7L0rPC0P32Mq165nsR/rYgq2c1GRNo=; b=EcIx3MwhEz7NaZ6SOHYQFDAevjwdAR8hUz890eefqWKnf8EpNElh5ypwxzMiSEZkV7 w7t/8x8TWqJoRDnN+n1EyVUHk/+a10BHhH8OA/HZrt6WjE/KiTk9Dn4MQM94TmcNQUxP EB4jbcxOXHCcVt8jQwnYcYuGEryjnq7CdOCYfU4dgOuvUu8d0Kjx13X83M8kZGKu7Ixb S1vMq3W16LHDVQZsZSTq1lYYdBenzZKRgM41wtgNrGQYHeUnWA7sSRMxXEF6n/sEVj9w wiIOql6SOeW9OyAox5L94fgPEzY+jEly1rxx9t4wuKvA1WeBMrCmpvM1PHUMlP8q2Rc3 AS4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pj0eQekw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si267289pgn.333.2018.02.21.15.13.43; Wed, 21 Feb 2018 15:13:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pj0eQekw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751412AbeBUXMe (ORCPT + 99 others); Wed, 21 Feb 2018 18:12:34 -0500 Received: from mail-ua0-f195.google.com ([209.85.217.195]:46095 "EHLO mail-ua0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750765AbeBUXMc (ORCPT ); Wed, 21 Feb 2018 18:12:32 -0500 Received: by mail-ua0-f195.google.com with SMTP id n48so2151358uae.13; Wed, 21 Feb 2018 15:12:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=fQXG8v5Uxp+tc7L0rPC0P32Mq165nsR/rYgq2c1GRNo=; b=pj0eQekwsmTe7MzDEqY5gaHnY0XndJyvT8D0a41SBaeGP4905eoSX1Bm/xupU2yRsm FJFVvjwY3eLaMFoPak868ZnmZozK066BR2f5KSFRjAXAObOk9QvDPjOQ6lm/OyKb5KIF K0bqRrxe2vC34fNqXcixEFDsuPgdlIYhrIO5cBgtSucs9tg3K/IZItzBIHiRs/gSE4xr pz4/rbAE/djf0pBoWZnza18LIgtbTD+Oyms6qDypMYltAdBLM9wHSI+TO0tbfZwmGif/ aQLmjdsaeOWi/fZPNQYpeMyy45ZhRs0lAG/JgoUET7qyRN2MxFjiBHih5jqFiBc/kcnk H2hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=fQXG8v5Uxp+tc7L0rPC0P32Mq165nsR/rYgq2c1GRNo=; b=SJ7lmW1HLRt7zwidGvaJl6P5rhIJeuWWFO+tiaFZW7un5ZnY3rwvgcexULEZt4SR/7 TMZUQiWSrD3J9j6B15DWDLcqFrAz7Mkxla6XeMPtR4b1r4xwfQhd/DwdiQlcUWWouXp4 /YDWJDonykIbqzN1hX0An7DQBE6OyvEEAYU+7wbgwSOPrfi3kqSLjkJ87ScMcX6n5qAz i2I3GA4S0dYwpQ+OHeK9IgPy5vjkhjFlLpnvHGyIdENsciaAGe627pDPv8YIEmn3SBUA wy61e3pWlLuKuo0Wq4Rh34jLg0ErSho1g3kM/S8hi80d7gZpCNtn6lgXr6jo49Id8M87 hYJw== X-Gm-Message-State: APf1xPBTqZeUjwu67R3JAIIvVST9nPc5qeIRdwavy2z9aB3DEqLFvyJy oc9jTkcuTxC5YtBRxNZn6Cik7SwT8+mNSZ2pDw== X-Received: by 10.176.21.46 with SMTP id o43mr3970950uae.78.1519254751861; Wed, 21 Feb 2018 15:12:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.94.194 with HTTP; Wed, 21 Feb 2018 15:12:31 -0800 (PST) In-Reply-To: <20180221215605.GK6778@dastard> References: <20180221204128.5846-1-garrmcnu@gmail.com> <20180221215605.GK6778@dastard> From: Garry McNulty Date: Wed, 21 Feb 2018 23:12:31 +0000 Message-ID: Subject: Re: [PATCH] fs/iomap: fix memory leak on error condition To: Dave Chinner Cc: linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, hch@lst.de, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21 February 2018 at 21:56, Dave Chinner wrote: > > On Wed, Feb 21, 2018 at 08:41:28PM +0000, Garry McNulty wrote: > > If the call to is_sync_kiocb() fails an error is returned without > > freeing dio. Set the return code and jump to out_free_dio. > > > > Detected by CoverityScan, CID 1429424 ("Resource leak") > > Coverity is wrong. > > > Signed-off-by: Garry McNulty > > --- > > fs/iomap.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/fs/iomap.c b/fs/iomap.c > > index afd163586aa0..65c5db38c15a 100644 > > --- a/fs/iomap.c > > +++ b/fs/iomap.c > > @@ -1063,8 +1063,10 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, > > iomap_dio_set_error(dio, ret); > > > > if (!atomic_dec_and_test(&dio->ref)) { > > - if (!is_sync_kiocb(iocb)) > > - return -EIOCBQUEUED; > > + if (!is_sync_kiocb(iocb)) { > > + ret = -EIOCBQUEUED; > > + goto out_free_dio; > > + } > > This is where we return after AIO submission. The struct dio has > already been attached to the bio we have submitted, and will be > freed on IO completion. We are simply not waiting for IO completion > here, instead leaving it to the completion code to free the struct > dio and pass the completion status to the AIO code appropriately. > ah OK, thanks for reviewing and for the explanation. Cheers Garry