Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1592577

[PATCH 2/3] staging: speakup: Clean up tests if NULL returned on failure

From simran singhal <singhalsimran0@gmail.com>
Newsgroups linux.kernel
Subject [PATCH 2/3] staging: speakup: Clean up tests if NULL returned on failure
Date 2017-03-04 17:50 +0100
Message-ID <thl2x-3tD-19@gated-at.bofh.it> (permalink)
References <thl2x-3tD-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Some functions like kmalloc/kzalloc return NULL on failure.
When NULL represents failure, !x is commonly used.

This was done using Coccinelle:
@@
expression *e;
identifier l1;
@@

e = \(kmalloc\|kzalloc\|kcalloc\|devm_kzalloc\)(...);
...
- e == NULL
+ !e

Signed-off-by: simran singhal <singhalsimran0@gmail.com>
---
 drivers/staging/speakup/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c
index c2f70ef..e8268bc 100644
--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -1324,7 +1324,7 @@ static int speakup_allocate(struct vc_data *vc)
 	if (speakup_console[vc_num] == NULL) {
 		speakup_console[vc_num] = kzalloc(sizeof(*speakup_console[0]),
 						  GFP_ATOMIC);
-		if (speakup_console[vc_num] == NULL)
+		if (!speakup_console[vc_num])
 			return -ENOMEM;
 		speakup_date(vc);
 	} else if (!spk_parked)
-- 
2.7.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/3] staging: Clean up tests if NULL returned on failure simran singhal <singhalsimran0@gmail.com> - 2017-03-04 17:50 +0100
  [PATCH 1/3] staging: rtl8192u: Clean up tests if NULL returned on failure simran singhal <singhalsimran0@gmail.com> - 2017-03-04 17:50 +0100
  [PATCH 2/3] staging: speakup: Clean up tests if NULL returned on failure simran singhal <singhalsimran0@gmail.com> - 2017-03-04 17:50 +0100
  [PATCH 3/3] staging: vc04_services: Clean up tests if NULL returned on failure simran singhal <singhalsimran0@gmail.com> - 2017-03-04 17:50 +0100
  Re: [Outreachy kernel] [PATCH 0/3] staging: Clean up tests if NULL  returned on failure Julia Lawall <julia.lawall@lip6.fr> - 2017-03-04 18:40 +0100

csiph-web