From patchwork Sat Oct 30 15:15:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel J Blueman X-Patchwork-Id: 292052 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9UFGHPM013829 for ; Sat, 30 Oct 2010 15:16:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752649Ab0J3PQE (ORCPT ); Sat, 30 Oct 2010 11:16:04 -0400 Received: from mail-iw0-f174.google.com ([209.85.214.174]:46554 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751611Ab0J3PQC convert rfc822-to-8bit (ORCPT ); Sat, 30 Oct 2010 11:16:02 -0400 Received: by iwn10 with SMTP id 10so5051409iwn.19 for ; Sat, 30 Oct 2010 08:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:cc:content-type:content-transfer-encoding; bh=VHhf2U3YFbGXns7XyAe80gXX2zSbOoyxnStLSBInZ9M=; b=m2IvQXP00oLcY84RC+TW3HODDb6PPiZwzPwF6YsR7OaMTNS5cCvRXuujoLeFvLY2wP 2kci2j8INOAPSnX8dPssg6RhNyd9SLxooXD1RAUz1uQ5bqOM0/wFG/sOYRmVmYJTft50 QkPrUfR6248Yltv219zRSVhfDNVdKf9xuTAAo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=daCk+xoUyQmsJpU/yWdYBRqI5HWG2OfbHIcJ/lDtaqaS9urnFjspV6vEbkAP27jpA/ LRWaViwW/OmyuU/Facy8ZsKnoAKiGeMn9H+UQl5HF2UsgemqQNj75igUZBoDAQVRJsLR jYYXHWVZxF/yNfI7QBWsbxoLzTzyrct1EJA6I= MIME-Version: 1.0 Received: by 10.231.11.130 with SMTP id t2mr243075ibt.154.1288451744748; Sat, 30 Oct 2010 08:15:44 -0700 (PDT) Received: by 10.231.39.203 with HTTP; Sat, 30 Oct 2010 08:15:44 -0700 (PDT) Date: Sat, 30 Oct 2010 16:15:44 +0100 Message-ID: Subject: [2.6.37-rc0 patch] direct I/O submission fixes v3 From: Daniel J Blueman To: Chris Mason Cc: Linux BTRFS , Josef Bacik , Linux Kernel Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sat, 30 Oct 2010 15:16:18 +0000 (UTC) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 558cac2..986cc40 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5761,7 +5761,7 @@ free_ordered: if (write) { struct btrfs_ordered_extent *ordered; ordered = btrfs_lookup_ordered_extent(inode, - dip->logical_offset); + file_offset); if (!test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags) && !test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags)) btrfs_free_reserved_extent(root, ordered->start, --- [2] Fix leak of 'dip' on error path and unnecessary double-assignment. Signed-off-by: Daniel J Blueman diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 558cac2..312eeb7 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5701,15 +5701,15 @@ static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode, ret = -ENOMEM; goto free_ordered; } - dip->csums = NULL; if (!skip_sum) { dip->csums = kmalloc(sizeof(u32) * bio->bi_vcnt, GFP_NOFS); if (!dip->csums) { ret = -ENOMEM; - goto free_ordered; + goto out_err; } - } + } else + dip->csums = NULL; dip->private = bio->bi_private; dip->inode = inode; ---------- Forwarded message ---------- From: Daniel J Blueman Date: 25 July 2010 19:53 Subject: Re: [2.6.35-rc6 patch] direct I/O submission fixes v2 To: Josef Bacik , Chris Mason Cc: Linux BTRFS On 25 July 2010 15:42, Josef Bacik wrote: > On Sat, Jul 24, 2010 at 12:01:59AM +0100, Daniel J Blueman wrote: >> Hi Chris, >> >> This fixes some issues relating to direct I/O submission, however a >> further patch will be needed to handle the case where allocation of >> 'dip' fails, which is always dereferenced when finding the ordered >> extent. >> > > Hi, > > There's an easier way to do this.  This patch should fix the problem, > > Signed-off-by: Josef Bacik > > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c > index 3232945..7259ef9 100644 > --- a/fs/btrfs/inode.c > +++ b/fs/btrfs/inode.c > @@ -5815,7 +5815,7 @@ free_ordered: >        if (write) { >                struct btrfs_ordered_extent *ordered; >                ordered = btrfs_lookup_ordered_extent(inode, > -                                                     dip->logical_offset); > +                                                     file_offset); >                if (!test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags) && >                    !test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags)) >                        btrfs_free_reserved_extent(root, ordered->start, > Good move! With your patch applied, mine (now not priority) then becomes: Fix leak of 'dip' on error path and double assignment. Signed-off-by: Daniel J Blueman diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 1bff92a..bd7f940 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5652,15 +5652,15 @@ static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode,                ret = -ENOMEM;                goto free_ordered;        } -       dip->csums = NULL;        if (!skip_sum) {                dip->csums = kmalloc(sizeof(u32) * bio->bi_vcnt, GFP_NOFS);                if (!dip->csums) {                        ret = -ENOMEM; -                       goto free_ordered; +                       goto out_err;                } -       } +       } else +               dip->csums = NULL;        dip->private = bio->bi_private;