Skip to contentSkip to conversation

Staging: lustre: Remove print statement on function failure

PATCH In review Bhumika Goyal 2 participants 3 messages Feb 28, 2016 1 message not in the archive Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: lustre: Remove print statement on function failure

The memory allocation functions generates a call stack containing all the context information on failure, so print statements can be removed on failure of these functions. Also remove unwanted {} around if block after removal of these statements. Done using coccinelle:

@@
expression e;
@@

e=\(kmalloc\|kmalloc\|kmalloc_array\|alloc_netdev\|kzalloc\|
devm_kzalloc\|devm_ioremap\)(...);
...
if(!e){
- \(DBG_8723A\|printk\|pr_err\|CERROR\|DBG_88E\)(...); ...when any
}

---
 drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c | 1 -
 drivers/staging/lustre/lustre/obdclass/llog.c             | 5 ++---
 drivers/staging/lustre/lustre/obdecho/echo_client.c       | 2 --
 3 files changed, 2 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c +0 -1
index ec75801..6742270 100644
@@ -252,7 +252,6 @@ static int cfs_crypto_test_hashes(void)
 
 	data = kmalloc(data_len, 0);
 	if (!data) {
-		CERROR("Failed to allocate mem\n");
 		return -ENOMEM;
 	}
 
drivers/staging/lustre/lustre/obdclass/llog.c +2 -3
index f7ee605..d1d74ee 100644
@@ -365,10 +365,9 @@ int llog_process_or_fork(const struct lu_env *env,
 	int		      rc;
 
 	lpi = kzalloc(sizeof(*lpi), GFP_NOFS);
-	if (!lpi) {
-		CERROR("cannot alloc pointer\n");
+	if (!lpi)
 		return -ENOMEM;
-	}
+
 	lpi->lpi_loghandle = loghandle;
 	lpi->lpi_cb	= cb;
 	lpi->lpi_cbdata    = data;
drivers/staging/lustre/lustre/obdecho/echo_client.c +0 -2
index 2b13aa2..a5b6854 100644
@@ -1767,8 +1767,6 @@ static int echo_client_setup(const struct lu_env *env,
 
 	ocd = kzalloc(sizeof(*ocd), GFP_NOFS);
 	if (!ocd) {
-		CERROR("Can't alloc ocd connecting to %s\n",
-		       lustre_cfg_string(lcfg, 1));
 		return -ENOMEM;
 	}
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 30 lines · Bhumika Goyal

The memory allocation functions generates a call stack containing all the context information on failure, so print statements can be removed on failure of these functions. Also remove unwanted {} around if block after removal of these statements. Done using coccinelle:

@@
expression e;
@@

e=\(kmalloc\|kmalloc\|kmalloc_array\|alloc_netdev\|kzalloc\|
devm_kzalloc\|devm_ioremap\)(...);
...
if(!e){
- \(DBG_8723A\|printk\|pr_err\|CERROR\|DBG_88E\)(...); ...when any
}

---
 drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c | 1 -
 drivers/staging/lustre/lustre/obdclass/llog.c             | 5 ++---
 drivers/staging/lustre/lustre/obdecho/echo_client.c       | 2 --
 3 files changed, 2 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c +0 -0
index ec75801..6742270 100644

drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c static int cfs_crypto_test_hashes(void) · line 256

Quoted 6 lines
drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c +0 -1
@@ -252,7 +252,6 @@ static int cfs_crypto_test_hashes(void)
 
 	data = kmalloc(data_len, 0);
 	if (!data) {
-		CERROR("Failed to allocate mem\n");
 		return -ENOMEM;
 	}

You need to drop the braces here too.

Quoted 23 lines
drivers/staging/lustre/lustre/obdclass/llog.c +2 -3
index f7ee605..d1d74ee 100644
@@ -365,10 +365,9 @@ int llog_process_or_fork(const struct lu_env *env,
 	int		      rc;
 
 	lpi = kzalloc(sizeof(*lpi), GFP_NOFS);
-	if (!lpi) {
-		CERROR("cannot alloc pointer\n");
+	if (!lpi)
 		return -ENOMEM;
-	}
+
 	lpi->lpi_loghandle = loghandle;
 	lpi->lpi_cb	= cb;
 	lpi->lpi_cbdata    = data;
drivers/staging/lustre/lustre/obdecho/echo_client.c +0 -0
index 2b13aa2..a5b6854 100644

drivers/staging/lustre/lustre/obdecho/echo_client.c static int echo_client_setup(const struct lu_env *env, · line 1771

Quoted 7 lines
drivers/staging/lustre/lustre/obdecho/echo_client.c +0 -2
@@ -1767,8 +1767,6 @@ static int echo_client_setup(const struct lu_env *env,
 
 	ocd = kzalloc(sizeof(*ocd), GFP_NOFS);
 	if (!ocd) {
-		CERROR("Can't alloc ocd connecting to %s\n",
-		       lustre_cfg_string(lcfg, 1));
 		return -ENOMEM;
 	}

Extra braces here too. You may want to make a special case for your semantic patch to detect the case where there is exactly one print and one other statement. It is easy to overlook this issue, and you may as well let Coccinelle do the work for you.

julia

Quoted 10 lines
Signature · 8 lines
1.9.1

-- 
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1456680358-31613-1-git-send-email-bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

A message that is not in the archive (sent off-list or not yet received): CAOH+1jF9Gr0qni4cKbccXc1nuq+qmzxT4bJshzNmYq+WfeBcAw@mail.gmail.com

#3 lore raw

PATCH 1/1 Staging: lustre: Remove print statement on function failure

Quoted 33 lines · Julia Lawall
Quoted 31 lines · Bhumika Goyal

The memory allocation functions generates a call stack containing all the context information on failure, so print statements can be removed on failure of these functions. Also remove unwanted {} around if block after removal of these statements. Done using coccinelle:

@@
expression e;
@@

e=\(kmalloc\|kmalloc\|kmalloc_array\|alloc_netdev\|kzalloc\|
devm_kzalloc\|devm_ioremap\)(...);
...
if(!e){
- \(DBG_8723A\|printk\|pr_err\|CERROR\|DBG_88E\)(...); ...when any
}

---
 drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c | 1 -
 drivers/staging/lustre/lustre/obdclass/llog.c             | 5 ++---
 drivers/staging/lustre/lustre/obdecho/echo_client.c       | 2 --
 3 files changed, 2 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c +0 -0
index ec75801..6742270 100644
@@ -252,7 +252,6 @@ static int cfs_crypto_test_hashes(void)
 
Quoted 8 lines

drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c static int cfs_crypto_test_hashes(void) · line 256

Quoted 5 lines
drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c +0 -1
      data = kmalloc(data_len, 0);
      if (!data) {
-             CERROR("Failed to allocate mem\n");
              return -ENOMEM;
      }

You need to drop the braces here too.

Oh yes. I will redo and send a v2.

Quoted 36 lines
Quoted 23 lines
drivers/staging/lustre/lustre/obdclass/llog.c +2 -3
index f7ee605..d1d74ee 100644
@@ -365,10 +365,9 @@ int llog_process_or_fork(const struct lu_env *env,
      int                   rc;
 
      lpi = kzalloc(sizeof(*lpi), GFP_NOFS);
-     if (!lpi) {
-             CERROR("cannot alloc pointer\n");
+     if (!lpi)
              return -ENOMEM;
-     }
+
      lpi->lpi_loghandle = loghandle;
      lpi->lpi_cb     = cb;
      lpi->lpi_cbdata    = data;
drivers/staging/lustre/lustre/obdecho/echo_client.c +0 -0
index 2b13aa2..a5b6854 100644

drivers/staging/lustre/lustre/obdecho/echo_client.c static int echo_client_setup(const struct lu_env *env, · line 1771

Quoted 7 lines
drivers/staging/lustre/lustre/obdecho/echo_client.c +0 -2
@@ -1767,8 +1767,6 @@ static int echo_client_setup(const struct lu_env *env,
 
      ocd = kzalloc(sizeof(*ocd), GFP_NOFS);
      if (!ocd) {
-             CERROR("Can't alloc ocd connecting to %s\n",
-                    lustre_cfg_string(lcfg, 1));
              return -ENOMEM;
      }

Extra braces here too. You may want to make a special case for your semantic patch to detect the case where there is exactly one print and one other statement. It is easy to overlook this issue, and you may as well let Coccinelle do the work for you.

Quoted 2 lines

julia

I thought of doing so but then I did it manually. I will send a v2 with revised semantic patch.

Thanks
Bhumika

Quoted 10 lines
Quoted 10 lines
drivers/staging/lustre/lustre/obdecho/echo_client.c +0 -1
--

1.9.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1456680358-31613-1-git-send-email-bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.