linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yang Li <yang.lee@linux.alibaba.com>
To: viro@zeniv.linux.org.uk
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yang Li <yang.lee@linux.alibaba.com>
Subject: [PATCH] direct-io: Using kmem_cache_zalloc() instead of kmem_cache_alloc() and memset()
Date: Thu, 25 Feb 2021 16:59:41 +0800	[thread overview]
Message-ID: <1614243581-50870-1-git-send-email-yang.lee@linux.alibaba.com> (raw)

Fix the following coccicheck warning:
./fs/direct-io.c:1155:7-23: WARNING: kmem_cache_zalloc should be used
for dio, instead of kmem_cache_alloc/memset

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---
 fs/direct-io.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/direct-io.c b/fs/direct-io.c
index 0957e1b..6ec2935 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -1152,7 +1152,7 @@ static inline int drop_refcount(struct dio *dio)
 	if (iov_iter_rw(iter) == READ && !count)
 		return 0;
 
-	dio = kmem_cache_alloc(dio_cache, GFP_KERNEL);
+	dio = kmem_cache_zalloc(dio_cache, GFP_KERNEL);
 	if (!dio)
 		return -ENOMEM;
 	/*
@@ -1160,8 +1160,6 @@ static inline int drop_refcount(struct dio *dio)
 	 * performance regression in a database benchmark.  So, we take
 	 * care to only zero out what's needed.
 	 */
-	memset(dio, 0, offsetof(struct dio, pages));
-
 	dio->flags = flags;
 	if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) {
 		/* will be released by direct_io_worker */
-- 
1.8.3.1


             reply	other threads:[~2021-02-25  9:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-25  8:59 Yang Li [this message]
2021-02-25 15:46 ` [PATCH] direct-io: Using kmem_cache_zalloc() instead of kmem_cache_alloc() and memset() Jeff Moyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1614243581-50870-1-git-send-email-yang.lee@linux.alibaba.com \
    --to=yang.lee@linux.alibaba.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).