From: Kees Cook <keescook@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>,
Jarmo Tiitto <jarmo.tiitto@gmail.com>,
Sami Tolvanen <samitolvanen@google.com>,
Bill Wendling <wcw@google.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
clang-built-linux@googlegroups.com
Subject: [PATCH] pgo: Clean up prf_open() error paths
Date: Mon, 7 Jun 2021 16:02:41 -0700 [thread overview]
Message-ID: <20210607230241.3797373-1-keescook@chromium.org> (raw)
Change coding style for prf_open() error handling paths. Additionally
fix up comments to be complete sentences with punctuation.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
This is on top of Jarmo's recent fixes.
---
kernel/pgo/fs.c | 49 ++++++++++++++++++++-----------------------------
1 file changed, 20 insertions(+), 29 deletions(-)
diff --git a/kernel/pgo/fs.c b/kernel/pgo/fs.c
index 0ce0dc9caf7a..3c5aa7c2a4ce 100644
--- a/kernel/pgo/fs.c
+++ b/kernel/pgo/fs.c
@@ -234,17 +234,14 @@ static unsigned long prf_buffer_size(void)
*/
static int prf_serialize(struct prf_private_data *p, size_t buf_size)
{
- int err = 0;
void *buffer;
/* get buffer size, again. */
p->size = prf_buffer_size();
/* check for unlikely overflow. */
- if (p->size > buf_size) {
- err = -EAGAIN;
- goto out;
- }
+ if (p->size > buf_size)
+ return -EAGAIN;
buffer = p->buffer;
@@ -256,8 +253,7 @@ static int prf_serialize(struct prf_private_data *p, size_t buf_size)
prf_serialize_values(&buffer);
-out:
- return err;
+ return 0;
}
/* open() implementation for PGO. Creates a copy of the profiling data set. */
@@ -266,52 +262,47 @@ static int prf_open(struct inode *inode, struct file *file)
struct prf_private_data *data;
unsigned long flags;
size_t buf_size;
- int err = 0;
+ int err = -EINVAL;
data = kzalloc(sizeof(*data), GFP_KERNEL);
- if (!data) {
- err = -ENOMEM;
- goto out_free;
- }
+ if (!data)
+ return -ENOMEM;
- /* get initial buffer size */
+ /* Get initial buffer size. */
flags = prf_lock();
data->size = prf_buffer_size();
prf_unlock(flags);
do {
- if (data->buffer)
- vfree(data->buffer);
+ vfree(data->buffer);
- /* allocate, round up to page size. */
+ /* Allocate, round up to page size. */
buf_size = PAGE_ALIGN(data->size);
data->buffer = vzalloc(buf_size);
if (!data->buffer) {
err = -ENOMEM;
- goto out_free;
+ break;
}
/*
- * try serialize and get actual
- * data length in data->size
+ * Try serialize and get actual
+ * data length in data->size.
*/
flags = prf_lock();
err = prf_serialize(data, buf_size);
prf_unlock(flags);
- /* in unlikely case, try again. */
+ /* In unlikely case, try again. */
} while (err == -EAGAIN);
- if (err)
- goto out_free;
-
- file->private_data = data;
- return 0;
+ if (err < 0) {
+ if (data)
+ vfree(data->buffer);
+ kfree(data);
+ } else {
+ file->private_data = data;
+ }
-out_free:
- if (data)
- vfree(data->buffer);
- kfree(data);
return err;
}
--
2.25.1
reply other threads:[~2021-06-07 23:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210607230241.3797373-1-keescook@chromium.org \
--to=keescook@chromium.org \
--cc=clang-built-linux@googlegroups.com \
--cc=jarmo.tiitto@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=samitolvanen@google.com \
--cc=wcw@google.com \
/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).