From patchwork Mon Sep 12 19:29:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9327869 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F20660231 for ; Mon, 12 Sep 2016 19:33:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 618C628E59 for ; Mon, 12 Sep 2016 19:33:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 563E528E6F; Mon, 12 Sep 2016 19:33:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 028CA28E59 for ; Mon, 12 Sep 2016 19:33:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932664AbcILTcp (ORCPT ); Mon, 12 Sep 2016 15:32:45 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:38643 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758192AbcILT3i (ORCPT ); Mon, 12 Sep 2016 15:29:38 -0400 Received: by mail-wm0-f48.google.com with SMTP id 1so163056237wmz.1 for ; Mon, 12 Sep 2016 12:29:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b2mJsgT8XLJ8KYxa1Br7gGr2MDaE5XPkr6lJjn/OPSQ=; b=evhJilIf/BwaN1In0YpdajDRWCpPykhqxIRZyI4kmXYc8mTGD8zEwcxTZI+fRLB03H xwoeW9diTfBgtEiww1kEVVZWVMyL72fzhRoAYh2cfnuIS7dywzBAKRVpEGLxFfU8vN2j 3nejoaH7HwfxuphG//JaAO2OdSAuymkuzvbMAS73BvVXAjhUIBb+HMRyWlNIxLw2Ngdv 3Jw3uwMPZGXI76FQWb9UZEROK0tM2a6DGeGODwET4Y8+bmSpYWKDatnXB2/cdyFjcGSS sSS9bYAA2qQX14a1oE5u+CYb57mkhkWb2ndylbeGa2hmtY+z+gt5R7RQbd0R2cb4/X/Q tT+w== X-Gm-Message-State: AE9vXwNwra3dUYxLdsUBU4OD8vgvr3/HLMkuSGQ2yJo7ZZTqYXuhqmR4nZXt7q9pWXyJMwA3 X-Received: by 10.194.109.229 with SMTP id hv5mr16398017wjb.131.1473708576420; Mon, 12 Sep 2016 12:29:36 -0700 (PDT) Received: from veci.piliscsaba.szeredi.hu (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id f8sm19250418wjh.45.2016.09.12.12.29.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Sep 2016 12:29:35 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Al Viro Subject: [PATCH 10/17] nsfs: clean up ns_get_name() interface Date: Mon, 12 Sep 2016 21:29:12 +0200 Message-Id: <1473708559-12714-11-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1473708559-12714-1-git-send-email-mszeredi@redhat.com> References: <1473708559-12714-1-git-send-email-mszeredi@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The only user of this is proc_ns_get_link(), which needs an allocated buffer. And ns_get_name() is much better positioned to know the size of the buffer to allocate, since it's the one that is going to fill it. Signed-off-by: Miklos Szeredi --- fs/nsfs.c | 17 +++++++++++++---- fs/proc/namespaces.c | 20 +++----------------- include/linux/proc_ns.h | 4 ++-- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/fs/nsfs.c b/fs/nsfs.c index 8f20d6016e20..33ec85b91aba 100644 --- a/fs/nsfs.c +++ b/fs/nsfs.c @@ -5,6 +5,7 @@ #include #include #include +#include static struct vfsmount *nsfs_mnt; @@ -106,14 +107,22 @@ slow: goto got_it; } -int ns_get_name(char *buf, size_t size, struct task_struct *task, - const struct proc_ns_operations *ns_ops) +char *ns_get_name(struct task_struct *task, + const struct proc_ns_operations *ns_ops) { struct ns_common *ns; - int res = -ENOENT; + char *res = ERR_PTR(-ENOENT); + ns = ns_ops->get(task); if (ns) { - res = snprintf(buf, size, "%s:[%u]", ns_ops->name, ns->inum); + /* 10 for unsigned int in decimal + 3 extra chars + term null */ + size_t size = strlen(ns_ops->name) + 14; + + res = kmalloc(size, GFP_KERNEL); + if (!res) + res = ERR_PTR(-ENOMEM); + else + snprintf(res, size, "%s:[%u]", ns_ops->name, ns->inum); ns_ops->put(ns); } return res; diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c index 9c9a1683791a..9c7209734b05 100644 --- a/fs/proc/namespaces.c +++ b/fs/proc/namespaces.c @@ -33,8 +33,6 @@ static const struct proc_ns_operations *ns_entries[] = { #endif }; -#define PROC_NS_LINK_MAX 50 - static const char *proc_ns_get_link(struct dentry *dentry, struct inode *inode, struct delayed_call *done) @@ -59,21 +57,9 @@ static const char *proc_ns_get_link(struct dentry *dentry, if (!res) nd_jump_link(&ns_path); } else { - char *name = kmalloc(PROC_NS_LINK_MAX, GFP_KERNEL); - int err; - - res = ERR_PTR(-ENOMEM); - if (!name) - goto out_put; - - err = ns_get_name(name, PROC_NS_LINK_MAX, task, ns_ops); - if (err < 0) { - kfree(name); - res = ERR_PTR(err); - goto out_put; - } - set_delayed_call(done, kfree_link, name); - res = name; + res = ns_get_name(task, ns_ops); + if (!IS_ERR(res)) + set_delayed_call(done, kfree_link, res); } out_put: put_task_struct(task); diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h index de0e7719d4c5..9ab3fb9b9101 100644 --- a/include/linux/proc_ns.h +++ b/include/linux/proc_ns.h @@ -74,8 +74,8 @@ extern struct file *proc_ns_fget(int fd); extern void *ns_get_path(struct path *path, struct task_struct *task, const struct proc_ns_operations *ns_ops); -extern int ns_get_name(char *buf, size_t size, struct task_struct *task, - const struct proc_ns_operations *ns_ops); +char *ns_get_name(struct task_struct *task, + const struct proc_ns_operations *ns_ops); extern void nsfs_init(void); #endif /* _LINUX_PROC_NS_H */