public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peng Tao <bergwolf@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org,
	"John L. Hammond" <john.hammond@intel.com>,
	Peng Tao <tao.peng@emc.com>,
	Andreas Dilger <andreas.dilger@intel.com>
Subject: [PATCH 37/48] staging/lustre/procfs: return -ENOMEM from lprocfs_register()
Date: Tue, 23 Jul 2013 00:06:58 +0800	[thread overview]
Message-ID: <1374509230-3324-38-git-send-email-bergwolf@gmail.com> (raw)
In-Reply-To: <1374509230-3324-1-git-send-email-bergwolf@gmail.com>

From: "John L. Hammond" <john.hammond@intel.com>

In lprocfs_register(), if proc_mkdir() fails then return
ERR_PTR(-ENOMEM) rather than NULL and hold _lprocfs_mutex for the
whole function.  In lprocfs_remove_nolock() return early if the entry
is an error pointer. Improve error handling around lprocfs_register()
in a few spots.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2650
Lustre-change: http://review.whamcloud.com/5161
Signed-off-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Emoly Liu <emoly.liu@intel.com>
Reviewed-by: Keith Mannthey <keith.mannthey@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: Peng Tao <tao.peng@emc.com>
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
---
 drivers/staging/lustre/lustre/ldlm/ldlm_pool.c     |    1 +
 drivers/staging/lustre/lustre/llite/super25.c      |    2 +-
 drivers/staging/lustre/lustre/lov/lov_obd.c        |    6 ++---
 .../lustre/lustre/obdclass/linux/linux-module.c    |    9 ++++++-
 .../lustre/lustre/obdclass/lprocfs_status.c        |   28 ++++++++++++--------
 .../staging/lustre/lustre/ptlrpc/gss/lproc_gss.c   |    6 +++--
 6 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
index 3277a0d..101af4b 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
@@ -750,6 +750,7 @@ static int ldlm_pool_proc_init(struct ldlm_pool *pl)
 	if (IS_ERR(pl->pl_proc_dir)) {
 		CERROR("LProcFS failed in ldlm-pool-init\n");
 		rc = PTR_ERR(pl->pl_proc_dir);
+		pl->pl_proc_dir = NULL;
 		GOTO(out_free_name, rc);
 	}
 
diff --git a/drivers/staging/lustre/lustre/llite/super25.c b/drivers/staging/lustre/lustre/llite/super25.c
index 82c14a9..ea06f1a 100644
--- a/drivers/staging/lustre/lustre/llite/super25.c
+++ b/drivers/staging/lustre/lustre/llite/super25.c
@@ -214,7 +214,7 @@ static void __exit exit_lustre_lite(void)
 	ll_remote_perm_cachep = NULL;
 
 	kmem_cache_destroy(ll_file_data_slab);
-	if (proc_lustre_fs_root)
+	if (proc_lustre_fs_root && !IS_ERR(proc_lustre_fs_root))
 		lprocfs_remove(&proc_lustre_fs_root);
 }
 
diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
index 0a9e40d..c7c1a8c 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -836,11 +836,11 @@ int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 	lprocfs_obd_setup(obd, lvars.obd_vars);
 #ifdef LPROCFS
 	{
-		int rc;
+		int rc1;
 
-		rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
+		rc1 = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
 					0444, &lov_proc_target_fops, obd);
-		if (rc)
+		if (rc1)
 			CWARN("Error adding the target_obd file\n");
 	}
 #endif
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
index d2c3072..2abacf2 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
@@ -385,14 +385,21 @@ struct file_operations obd_device_list_fops = {
 
 int class_procfs_init(void)
 {
-	int rc;
+	int rc = 0;
 	ENTRY;
 
 	obd_sysctl_init();
 	proc_lustre_root = lprocfs_register("fs/lustre", NULL,
 					    lprocfs_base, NULL);
+	if (IS_ERR(proc_lustre_root)) {
+		rc = PTR_ERR(proc_lustre_root);
+		proc_lustre_root = NULL;
+		goto out;
+	}
+
 	rc = lprocfs_seq_create(proc_lustre_root, "devices", 0444,
 				&obd_device_list_fops, NULL);
+out:
 	if (rc)
 		CERROR("error adding /proc/fs/lustre/devices file\n");
 	RETURN(0);
diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 85163f4..e57a922 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -179,17 +179,21 @@ struct proc_dir_entry *lprocfs_register(const char *name,
 					struct proc_dir_entry *parent,
 					struct lprocfs_vars *list, void *data)
 {
-	struct proc_dir_entry *newchild;
-
-	newchild = proc_mkdir(name, parent);
-	if (newchild != NULL && list != NULL) {
-		int rc = lprocfs_add_vars(newchild, list, data);
-		if (rc) {
-			lprocfs_remove(&newchild);
-			return ERR_PTR(rc);
+	struct proc_dir_entry *entry;
+
+	entry = proc_mkdir(name, parent);
+	if (entry == NULL)
+		GOTO(out, entry = ERR_PTR(-ENOMEM));
+
+	if (list != NULL) {
+		int rc = lprocfs_add_vars(entry, list, data);
+		if (rc != 0) {
+			lprocfs_remove(&entry);
+			entry = ERR_PTR(rc);
 		}
 	}
-	return newchild;
+out:
+	return entry;
 }
 EXPORT_SYMBOL(lprocfs_register);
 
@@ -1596,10 +1600,12 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
 					      NULL, NULL);
 	OBD_FREE(buffer, LNET_NIDSTR_SIZE);
 
-	if (new_stat->nid_proc == NULL) {
+	if (IS_ERR(new_stat->nid_proc)) {
 		CERROR("Error making export directory for nid %s\n",
 		       libcfs_nid2str(*nid));
-		GOTO(destroy_new_ns, rc = -ENOMEM);
+		rc = PTR_ERR(new_stat->nid_proc);
+		new_stat->nid_proc = NULL;
+		GOTO(destroy_new_ns, rc);
 	}
 
 	entry = lprocfs_add_simple(new_stat->nid_proc, "uuid",
diff --git a/drivers/staging/lustre/lustre/ptlrpc/gss/lproc_gss.c b/drivers/staging/lustre/lustre/ptlrpc/gss/lproc_gss.c
index 3404000..de100a1 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/gss/lproc_gss.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/gss/lproc_gss.c
@@ -199,15 +199,17 @@ int gss_init_lproc(void)
 	gss_proc_root = lprocfs_register("gss", sptlrpc_proc_root,
 					 gss_lprocfs_vars, NULL);
 	if (IS_ERR(gss_proc_root)) {
+		rc = PTR_ERR(gss_proc_root);
 		gss_proc_root = NULL;
-		GOTO(err_out, rc = PTR_ERR(gss_proc_root));
+		GOTO(err_out, rc);
 	}
 
 	gss_proc_lk = lprocfs_register("lgss_keyring", gss_proc_root,
 				       gss_lk_lprocfs_vars, NULL);
 	if (IS_ERR(gss_proc_lk)) {
+		rc = PTR_ERR(gss_proc_lk);
 		gss_proc_lk = NULL;
-		GOTO(err_out, rc = PTR_ERR(gss_proc_root));
+		GOTO(err_out, rc);
 	}
 
 	return 0;
-- 
1.7.9.5


  parent reply	other threads:[~2013-07-22 16:13 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-22 16:06 [PATCH 00/48] staging/lustre: minor cleanup and Intel Lustre sync Peng Tao
2013-07-22 16:06 ` [PATCH 01/48] staging/lustre: remove bogus ifndef EXPORT_SYMBOL Peng Tao
2013-07-22 16:06 ` [PATCH 02/48] staging/lustre/obdclass: restore lu_ref Peng Tao
2013-07-23 19:37   ` Greg Kroah-Hartman
2013-07-23 20:31     ` Dilger, Andreas
2013-07-23 20:52       ` Greg Kroah-Hartman
2013-07-24  6:06         ` Peng Tao
2013-07-22 16:06 ` [PATCH 03/48] staging/lustre/llite: use READ, WRITE around ll_rw_stats_tally() Peng Tao
2013-07-22 16:06 ` [PATCH 04/48] staging/lustre/llite: missing last bit in ll_have_md_lock Peng Tao
2013-07-22 16:06 ` [PATCH 05/48] staging/lustre: fix 'program hangs' errors Peng Tao
2013-07-22 16:06 ` [PATCH 06/48] staging/lustre/llite: check alloc in ll_file_data_get, ll_dir_ioctl Peng Tao
2013-07-22 16:06 ` [PATCH 07/48] staging/lustre/llite: A not locked mutex can be unlocked Peng Tao
2013-07-22 16:06 ` [PATCH 08/48] staging/lustre/llite: check ll_prep_md_op_data() using IS_ERR() Peng Tao
2013-07-22 16:06 ` [PATCH 09/48] staging/lustre/ldlm: print FID in lvbo_init(), lvbo_update Peng Tao
2013-07-22 16:06 ` [PATCH 10/48] staging/lustre/ptlrpc: race in pinger (use-after-free situation) Peng Tao
2013-07-22 16:06 ` [PATCH 11/48] staging/lustre/ptlrpc: Translate between host and network errnos Peng Tao
2013-07-22 16:29   ` Paul Bolle
2013-07-22 16:36     ` Peng Tao
2013-07-22 16:06 ` [PATCH 12/48] staging/lustre/mdc: layout lock rpc must not take rpc_lock Peng Tao
2013-07-22 16:06 ` [PATCH 13/48] staging/lustre/ldlm: split client namespaces into active and inactive Peng Tao
2013-07-22 16:06 ` [PATCH 14/48] staging/lustre: Only wake up ldlm_poold as frequently as the check interval Peng Tao
2013-07-22 16:06 ` [PATCH 15/48] staging/lustre: Make quota namespace refcounting consistent Peng Tao
2013-07-22 16:06 ` [PATCH 16/48] staging/lustre/dlmlock: compress out unused space Peng Tao
2013-07-22 16:06 ` [PATCH 17/48] staging/lustre/md: fix lu_ucred.c boilerplate Peng Tao
2013-07-22 16:06 ` [PATCH 18/48] staging/lustre/layout: introduce new layout for released files Peng Tao
2013-07-22 16:06 ` [PATCH 19/48] staging/lustre/mdt: add macros for fid string len Peng Tao
2013-07-22 16:06 ` [PATCH 20/48] staging/lustre/llapi: add user space method for lov_user_md Peng Tao
2013-07-22 16:06 ` [PATCH 21/48] staging/lustre/obdclass: use a dummy structure for lu_ref_link Peng Tao
2013-07-23 20:35   ` Greg Kroah-Hartman
2013-07-24  6:10     ` Peng Tao
2013-07-22 16:06 ` [PATCH 22/48] staging/lustre: fix 'code maintainability' errors Peng Tao
2013-07-22 16:06 ` [PATCH 23/48] staging/lustre/fid: prepare FID module for client server split Peng Tao
2013-07-22 16:06 ` [PATCH 24/48] staging/lustre/llite: force lvb_data update after layout change Peng Tao
2013-07-22 16:06 ` [PATCH 25/48] staging/lustre/lfsck: LFSCK 1.5 technical debts (3) Peng Tao
2013-07-22 16:06 ` [PATCH 26/48] staging/lustre/osc: Check return code for lu_kmem_init Peng Tao
2013-07-22 16:06 ` [PATCH 27/48] staging/lustre/ptlrpc: Race between start and stop service threads Peng Tao
2013-07-22 16:06 ` [PATCH 28/48] staging/lustre/crypto: add crc32c module loading to libcfs Peng Tao
2013-07-22 16:06 ` [PATCH 29/48] staging/lustre/mdt: duplicate link names in directory Peng Tao
2013-07-22 16:06 ` [PATCH 30/48] staging/lustre/llite: call simple_setattr() from ll_md_setattr() Peng Tao
2013-07-22 16:06 ` [PATCH 31/48] staging/lustre/ldlm: Fix flock deadlock detection race Peng Tao
2013-07-22 16:06 ` [PATCH 32/48] staging/lustre/lnet: remove empty file lnet/lnet/api-errno.c Peng Tao
2013-07-22 16:06 ` [PATCH 33/48] staging/lustre/fld: prepare FLD module for client server split Peng Tao
2013-07-22 16:06 ` [PATCH 34/48] staging/lustre/lmv: support DNE with HSM Peng Tao
2013-07-22 16:06 ` [PATCH 35/48] " Peng Tao
2013-07-23 20:39   ` Greg Kroah-Hartman
2013-07-22 16:06 ` [PATCH 36/48] staging/lustre/obdclass: add obd_target.h Peng Tao
2013-07-23 20:41   ` Greg Kroah-Hartman
2013-07-22 16:06 ` Peng Tao [this message]
2013-07-22 16:06 ` [PATCH 38/48] staging/lustre/lmv: fix duplicate directory entries Peng Tao
2013-07-22 16:07 ` [PATCH 39/48] staging/lustre/obdclass: be more careful processing server name Peng Tao
2013-07-22 16:07 ` [PATCH 40/48] staging/lustre/llite: return valid fsid for statfs Peng Tao
2013-07-22 16:07 ` [PATCH 41/48] staging/lustre/llite: error of listxattr when buffer is small Peng Tao
2013-07-22 16:07 ` [PATCH 42/48] staging/lustre/llite: Anonymous dentry incorrectly identified as root Peng Tao
2013-07-22 16:07 ` [PATCH 43/48] staging/lustre/build: fix 'data race condition' issues Peng Tao
2013-07-22 16:07 ` [PATCH 44/48] " Peng Tao
2013-07-23 20:44   ` Greg Kroah-Hartman
2013-07-22 16:07 ` [PATCH 45/48] staging/lustre/style: removes obsolete EXPORT_SYMTAB macros v2 Peng Tao
2013-07-22 16:07 ` [PATCH 46/48] staging/lustre/mdt: HSM on disk actions record Peng Tao
2013-07-22 16:07 ` [PATCH 47/48] staging/lustre/scrub: purge inconsistenct objects after OI scrub Peng Tao
2013-07-22 16:07 ` [PATCH 48/48] staging/lustre/mdc: Keep resend FLocks Peng Tao
2013-07-23 20:51 ` [PATCH 00/48] staging/lustre: minor cleanup and Intel Lustre sync Greg Kroah-Hartman
2013-07-24  6:05   ` Peng Tao

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=1374509230-3324-38-git-send-email-bergwolf@gmail.com \
    --to=bergwolf@gmail.com \
    --cc=andreas.dilger@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.hammond@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tao.peng@emc.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