From: Dan Carpenter <dan.carpenter@oracle.com>
To: Namjae Jeon <namjae.jeon@samsung.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steve French <sfrench@samba.org>,
Hyunchul Lee <hyc.lee@gmail.com>,
linux-cifs@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH] ksmbd: use kasprintf() in ksmbd_vfs_xattr_stream_name()
Date: Wed, 7 Jul 2021 13:15:32 +0300 [thread overview]
Message-ID: <YOV+xDbnpDrR/Ipj@mwanda> (raw)
Simplify the code by using kasprintf(). This also silences a Smatch
warning:
fs/ksmbd/vfs.c:1725 ksmbd_vfs_xattr_stream_name()
warn: inconsistent indenting
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Not tested.
fs/ksmbd/vfs.c | 27 ++++++---------------------
1 file changed, 6 insertions(+), 21 deletions(-)
diff --git a/fs/ksmbd/vfs.c b/fs/ksmbd/vfs.c
index 0f5a4fb8215f..d3bab9235e9a 100644
--- a/fs/ksmbd/vfs.c
+++ b/fs/ksmbd/vfs.c
@@ -1697,35 +1697,20 @@ ssize_t ksmbd_vfs_casexattr_len(struct user_namespace *user_ns,
int ksmbd_vfs_xattr_stream_name(char *stream_name, char **xattr_stream_name,
size_t *xattr_stream_name_size, int s_type)
{
- int stream_name_size;
- char *xattr_stream_name_buf;
- char *type;
- int type_len;
+ char *type, *buf;
if (s_type == DIR_STREAM)
type = ":$INDEX_ALLOCATION";
else
type = ":$DATA";
- type_len = strlen(type);
- stream_name_size = strlen(stream_name);
- *xattr_stream_name_size = stream_name_size + XATTR_NAME_STREAM_LEN + 1;
- xattr_stream_name_buf = kmalloc(*xattr_stream_name_size + type_len,
- GFP_KERNEL);
- if (!xattr_stream_name_buf)
+ buf = kasprintf(GFP_KERNEL, "%s%s%s",
+ XATTR_NAME_STREAM, stream_name, type);
+ if (!buf)
return -ENOMEM;
- memcpy(xattr_stream_name_buf, XATTR_NAME_STREAM, XATTR_NAME_STREAM_LEN);
-
- if (stream_name_size) {
- memcpy(&xattr_stream_name_buf[XATTR_NAME_STREAM_LEN],
- stream_name, stream_name_size);
- }
- memcpy(&xattr_stream_name_buf[*xattr_stream_name_size - 1], type, type_len);
- *xattr_stream_name_size += type_len;
-
- xattr_stream_name_buf[*xattr_stream_name_size - 1] = '\0';
- *xattr_stream_name = xattr_stream_name_buf;
+ *xattr_stream_name = buf;
+ *xattr_stream_name_size = strlen(buf) + 1;
return 0;
}
--
2.30.2
next reply other threads:[~2021-07-07 10:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20210707101617epcas1p12eede31054d5985ad00297f45102bcd5@epcas1p1.samsung.com>
2021-07-07 10:15 ` Dan Carpenter [this message]
2021-07-08 0:35 ` [PATCH] ksmbd: use kasprintf() in ksmbd_vfs_xattr_stream_name() Namjae Jeon
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=YOV+xDbnpDrR/Ipj@mwanda \
--to=dan.carpenter@oracle.com \
--cc=hyc.lee@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=namjae.jeon@samsung.com \
--cc=senozhatsky@chromium.org \
--cc=sfrench@samba.org \
/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).