Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1785611imm; Wed, 16 May 2018 03:05:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrd9XVAhKWxbtpqerbey+RZw4ju9OZm6qcTyi1BcuAVzboIjL3fzMtGNfKJk7ee+JrEFqwn X-Received: by 2002:a63:8c19:: with SMTP id m25-v6mr195773pgd.178.1526465143257; Wed, 16 May 2018 03:05:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526465143; cv=none; d=google.com; s=arc-20160816; b=ALvs4dGfuo4tb9bSBj5gcFD2Y8/R8tNi/+1Mv6KBf1qydokXy4gicNNc6s9g9g6uV4 HreDfHvTtPAhhxxuRk3f/sAdUeXLxobGpOsas4c/eMqP4j3OB6M5CY2kIu2J/TSkOdnH wQnQ8PtfhX6e+c7xHp5l2z868iDpne5Ay9WVQWBvrbqDJojx11n8zKuu2ypHM2wWf4YK SvjgLcPa9H5v38ULyyYb6pXHOta8kyvbl+R9MTGWqxeEoxCYaYTGjBBrejTbv3/djbvr 31pKJcq2lCDtRMYFG3Rzb4r3xh4bIXKq5kUY6KA4RtoglwMX8NwdZrs0w6P3EO4t5fZ1 zF+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=jjtc+BylkCQRbUezIax8ZwcWkqWdXi49U0dtgSfXUiE=; b=ZnT2b2KfD7N4oxyHvhkYMmfUrNANVh+cDGuaHcws/jqHWAaRMDbxPwhRtTZAeZXnJb AHN2f4cLPaielqnhVzCc1c+SDadhzFl7Z+GrtHWTkDhrphGzl2zMomuMvLGeCLqMjih1 t0b/nPE2JEdIZTs1EWmPVQbh6KSo7zVHbExOtBmJeutrha+mTVMoW0VDaVfJ1+g1sSSD 5tit9r+p+kPk+kmnmpKT/HAy6c1FzGBWE/cOlpDthqlRy8kp/d5jymfEOOYTIhVYUuDe 6rjCGotB69h45EPjOn026Zt4YUNwEbrpdJ2NmxmD1rpClWaZOlXDoVFLwN0fXAs1gjip zAeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=tdE2ofw3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m32-v6si2203826pld.438.2018.05.16.03.05.29; Wed, 16 May 2018 03:05:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=tdE2ofw3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752824AbeEPJpM (ORCPT + 99 others); Wed, 16 May 2018 05:45:12 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:47240 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752710AbeEPJo7 (ORCPT ); Wed, 16 May 2018 05:44:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=jjtc+BylkCQRbUezIax8ZwcWkqWdXi49U0dtgSfXUiE=; b=tdE2ofw36HVUePY90ZqUE68Lk dMBHuucDhPoGB/aoSqMyh4A3uisdDsXdB1Y2JG5eQUZNLN8bSf+zW93lRNLl1XsQabwrGPXoZ28f7 3xgutV1WfQVmqZZGHgwC3KKZjxc6XF27SZzPbcptqZS1x6KNEHrfLyJS+jWnoHeclilOJLgC5x5OC Y0SSj/9PeAgBPJ3P+4RWBST9FyAEL8t9m/N6ZjoKnGaqhU2n9n4iC5Z18Vg7plP2htrQDDu3pozf0 iWKYHBh1B8gBlDKm60hpYq/Z/Z67EHejZmNaOzr0T8FiF0Er8yc/J7HzsZoq6qq4PY1lhv5MhzDvM GKtgpEA1A==; Received: from 089144199016.atnat0008.highway.a1.net ([89.144.199.16] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIsyf-0004xv-FD; Wed, 16 May 2018 09:44:10 +0000 From: Christoph Hellwig To: Andrew Morton , Alexander Viro Cc: Alexey Dobriyan , Greg Kroah-Hartman , Jiri Slaby , Alessandro Zummo , Alexandre Belloni , linux-acpi@vger.kernel.org, drbd-dev@lists.linbit.com, linux-ide@vger.kernel.org, netdev@vger.kernel.org, linux-rtc@vger.kernel.org, megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, devel@driverdev.osuosl.org, linux-afs@lists.infradead.org, linux-ext4@vger.kernel.org, jfs-discussion@lists.sourceforge.net, netfilter-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/42] proc: add a proc_create_reg helper Date: Wed, 16 May 2018 11:43:09 +0200 Message-Id: <20180516094346.20506-6-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180516094346.20506-1-hch@lst.de> References: <20180516094346.20506-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Common code for creating a regular file. Factor out of proc_create_data, to be reused by other functions soon. Signed-off-by: Christoph Hellwig --- fs/proc/generic.c | 44 +++++++++++++++++++++++++------------------- fs/proc/internal.h | 2 ++ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/fs/proc/generic.c b/fs/proc/generic.c index bd8480ff0d35..ab6a321076b8 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -511,33 +511,39 @@ struct proc_dir_entry *proc_create_mount_point(const char *name) } EXPORT_SYMBOL(proc_create_mount_point); -struct proc_dir_entry *proc_create_data(const char *name, umode_t mode, - struct proc_dir_entry *parent, - const struct file_operations *proc_fops, - void *data) +struct proc_dir_entry *proc_create_reg(const char *name, umode_t mode, + struct proc_dir_entry **parent, void *data) { - struct proc_dir_entry *pde; + struct proc_dir_entry *p; + if ((mode & S_IFMT) == 0) mode |= S_IFREG; - - if (!S_ISREG(mode)) { - WARN_ON(1); /* use proc_mkdir() */ + if ((mode & S_IALLUGO) == 0) + mode |= S_IRUGO; + if (WARN_ON_ONCE(!S_ISREG(mode))) return NULL; + + p = __proc_create(parent, name, mode, 1); + if (p) { + p->proc_iops = &proc_file_inode_operations; + p->data = data; } + return p; +} + +struct proc_dir_entry *proc_create_data(const char *name, umode_t mode, + struct proc_dir_entry *parent, + const struct file_operations *proc_fops, void *data) +{ + struct proc_dir_entry *p; BUG_ON(proc_fops == NULL); - if ((mode & S_IALLUGO) == 0) - mode |= S_IRUGO; - pde = __proc_create(&parent, name, mode, 1); - if (!pde) - goto out; - pde->proc_fops = proc_fops; - pde->data = data; - pde->proc_iops = &proc_file_inode_operations; - return proc_register(parent, pde); -out: - return NULL; + p = proc_create_reg(name, mode, &parent, data); + if (!p) + return NULL; + p->proc_fops = proc_fops; + return proc_register(parent, p); } EXPORT_SYMBOL(proc_create_data); diff --git a/fs/proc/internal.h b/fs/proc/internal.h index 488e67490312..dd1e11400b97 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -162,6 +162,8 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i /* * generic.c */ +struct proc_dir_entry *proc_create_reg(const char *name, umode_t mode, + struct proc_dir_entry **parent, void *data); struct proc_dir_entry *proc_register(struct proc_dir_entry *dir, struct proc_dir_entry *dp); extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int); -- 2.17.0