Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1471496
| Path | csiph.com!weretis.net!feeder4.news.weretis.net!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> |
| Newsgroups | linux.kernel |
| Subject | [PATCH v2 5/8] pipe: simplify logic in alloc_pipe_info() |
| Date | Mon, 29 Aug 2016 02:30:01 +0200 |
| Message-ID | <sbiCB-eG-7@gated-at.bofh.it> (permalink) |
| References | <sbiCB-eG-9@gated-at.bofh.it> |
| X-Original-To | Andrew Morton <akpm@linux-foundation.org> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=dUWn8wJr6sA/mIbPepxlqtH8UafaK1NycpHZuSkn8QY=; b=yaylX1RItpA/w7GGcKja3+2WxF7lvT7a316sOmYmRa+oqsRVNZYK2T3GoVIp0h94ns 0xz4paRlo/LLX9qG2Aoir+LOtC++WYIupQbCzBm1OWL4M2pONe7x6APaj9COvYw7RpZY hme+LKov2gxiAm95DQld83t8ReJBkNGoWAoVE32m3JfiWWPhXKBbxkgYPLq3FA19tG6F all1elvK8MK3f9B+Q+65WO9QVPBcPe4RVWEb/7ZxoB+xI+9QAWL764dTKwqxOxIy8WTn LK5DlUiOudKZDw+2qRO2GWwiwpYRjoUuC28W2HAyzsnYUpRpZu1F5VdHYN8xRyGD7LBr AtgA== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=dUWn8wJr6sA/mIbPepxlqtH8UafaK1NycpHZuSkn8QY=; b=P9WE0sLli1es/EHX9e7EpF3vpyZDbAv2tjDrwOzl/c4Vo0QZ8UnLcymcbeQNCDDsq/ Xrd5QMVyzF/F5AXN0TK/yBVL2g70I77JeEk63cWm+PkMYCeGtO4kffpeAYBt287PNzWT oyGPxKdXwezsOheG3ITgQ0ELUbS40L+dV9KXW9qh/iRM0k/KwMOE5/P5BsKpHWSM9wxw fwSpQO8ocKND9zvJk37Ddn24SbeV0wzXRPW8+UxkJgw2kBoQv8ynG+Pwsl8mLD8sOSrZ oQOoZ3iYnYcdlG898MTVcp9sDv99DswEHITB3z0aHO19v8hhcSr4btPsLDJDK9Cw7ZOA XOXw== |
| X-Gm-Message-State | AE9vXwMQrSniOZrsC3MN1bBRBmKwKqiTrFm8HcaTr+4sV3pbRtwEcb16LRGuDfDito9pUQ== |
| X-Received | by 10.98.98.193 with SMTP id w184mr27560189pfb.120.1472430105966; Sun, 28 Aug 2016 17:21:45 -0700 (PDT) |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 7bit |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 80 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | mtk.manpages@gmail.com, Willy Tarreau <w@1wt.eu>, Vegard Nossum <vegard.nossum@oracle.com>, socketpair@gmail.com, Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>, Jens Axboe <axboe@fb.com>, Al Viro <viro@zeniv.linux.org.uk>, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org |
| X-Original-Date | Mon, 29 Aug 2016 12:21:39 +1200 |
| X-Original-Message-ID | <aef030c1-0257-98a9-4988-186efa48530c@gmail.com> |
| X-Original-References | <ef9ce203-6683-31b1-26dc-e0b823aba73e@gmail.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1471496 |
Show key headers only | View raw
Replace an 'if' block that covers most of the code in this function
with a 'goto'. This makes the code a little simpler to read, and also
simplifies the next patch (fix limit checking in alloc_pipe_info())
Cc: Willy Tarreau <w@1wt.eu>
Cc: Vegard Nossum <vegard.nossum@oracle.com>
Cc: socketpair@gmail.com
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Jens Axboe <axboe@fb.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-api@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
---
fs/pipe.c | 45 +++++++++++++++++++++++----------------------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/fs/pipe.c b/fs/pipe.c
index f45a173..256fc5a 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -625,33 +625,34 @@ static bool too_many_pipe_buffers_hard(struct user_struct *user)
struct pipe_inode_info *alloc_pipe_info(void)
{
struct pipe_inode_info *pipe;
+ unsigned long pipe_bufs = PIPE_DEF_BUFFERS;
+ struct user_struct *user = get_current_user();
pipe = kzalloc(sizeof(struct pipe_inode_info), GFP_KERNEL_ACCOUNT);
- if (pipe) {
- unsigned long pipe_bufs = PIPE_DEF_BUFFERS;
- struct user_struct *user = get_current_user();
-
- if (!too_many_pipe_buffers_hard(user)) {
- if (too_many_pipe_buffers_soft(user))
- pipe_bufs = 1;
- pipe->bufs = kcalloc(pipe_bufs,
- sizeof(struct pipe_buffer),
- GFP_KERNEL_ACCOUNT);
- }
+ if (pipe == NULL)
+ goto out_free_uid;
+
+ if (!too_many_pipe_buffers_hard(user)) {
+ if (too_many_pipe_buffers_soft(user))
+ pipe_bufs = 1;
+ pipe->bufs = kcalloc(pipe_bufs,
+ sizeof(struct pipe_buffer),
+ GFP_KERNEL_ACCOUNT);
+ }
- if (pipe->bufs) {
- init_waitqueue_head(&pipe->wait);
- pipe->r_counter = pipe->w_counter = 1;
- pipe->buffers = pipe_bufs;
- pipe->user = user;
- account_pipe_buffers(user, 0, pipe_bufs);
- mutex_init(&pipe->mutex);
- return pipe;
- }
- free_uid(user);
- kfree(pipe);
+ if (pipe->bufs) {
+ init_waitqueue_head(&pipe->wait);
+ pipe->r_counter = pipe->w_counter = 1;
+ pipe->buffers = pipe_bufs;
+ pipe->user = user;
+ account_pipe_buffers(user, 0, pipe_bufs);
+ mutex_init(&pipe->mutex);
+ return pipe;
}
+ kfree(pipe);
+out_free_uid:
+ free_uid(user);
return NULL;
}
--
2.5.5
Back to linux.kernel | Previous | Next | Find similar | Unroll thread
[PATCH v2 5/8] pipe: simplify logic in alloc_pipe_info() "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-08-29 02:30 +0200
csiph-web