diff mbox series

cifs: use kfree in error path of cifs_writedata_alloc()

Message ID CAH2r5ms6p4_PdihrLC+ZJ4W=YjqOmwYhDT-fF6swZ5SB0fP4Ww@mail.gmail.com
State New
Headers show
Series cifs: use kfree in error path of cifs_writedata_alloc() | expand

Commit Message

Steve French Nov. 10, 2022, 8:30 p.m. UTC
The kvfree vs. kfree wasn't obvious to me

Is this just a "it's cleaner" patch? or a bug.  I thought kvfree will
call kfree in this case as mentioned in the link below

https://patchwork.kernel.org/project/dri-devel/patch/1447070170-8512-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp/

---------- Forwarded message ---------
From: Liu Jian <liujian56@huawei.com>
Date: Thu, Nov 10, 2022 at 5:14 AM
Subject: [PATCH] cifs: use kfree in error path of cifs_writedata_alloc()
To: <sfrench@samba.org>, <pc@cjr.nz>, <lsahlber@redhat.com>,
<sprasad@microsoft.com>, <tom@talpey.com>, <zhangxiaoxu5@huawei.com>,
<linux-cifs@vger.kernel.org>, <samba-technical@lists.samba.org>
Cc: <liujian56@huawei.com>


'pages' is allocated by kcalloc(), which should freed by kfree().

Fixes: 4153d789e299 ("cifs: Fix pages array leak when writedata alloc
failed in cifs_writedata_alloc()")
Signed-off-by: Liu Jian <liujian56@huawei.com>
---
 fs/cifs/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

        return writedata;
--
2.17.1

Comments

David Howells Nov. 10, 2022, 10:13 p.m. UTC | #1
Steve French <smfrench@gmail.com> wrote:

> 'pages' is allocated by kcalloc(), which should freed by kfree().

Either kfree() or kvfree() will do; though kfree() is going to be slightly
faster.

David
diff mbox series

Patch

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index cd9698209930..9a250fee673f 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2440,7 +2440,7 @@  cifs_writedata_alloc(unsigned int nr_pages,
work_func_t complete)
        if (pages) {
                writedata = cifs_writedata_direct_alloc(pages, complete);
                if (!writedata)
-                       kvfree(pages);
+                       kfree(pages);
        }