Skip to contentSkip to conversation

Staging: speakup: Remove print following unsuccessful kmalloc

PATCH In review Meghana Madhyastha 2 participants 2 messages Sep 16, 2017 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: speakup: Remove print following unsuccessful kmalloc

Remove print statement following unsuccessful kmalloc when there is not enough memory. Kmalloc and variants normally produce a backtrace in such a case. Hence, a print statement is not necessary.

Found using the following Coccinelle semantic patch:

@@
identifier i;
@@

i = (\(kmalloc\|devm_kzalloc\|kmalloc_array\| devm_ioremap\|usb_alloc_urb\|alloc_netdev\|dev_alloc_skb\| kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...));
(
if (i == NULL)
{ -\(DBG_8723A\|printk\|pr_err\|CERROR\|DBG_88E\)(...); ...when any
}
|
if (!i)
{ -\(DBG_8723A\|printk\|pr_err\|CERROR\|DBG_88E\)(...); ...when any
}
)

@@
identifier i;
@@
(
- if (i == NULL) {
+ if (i == NULL)

       return ...;

- }
|
- if (!i) {
+ if (!i)

       return ...;

- }
)

---
 drivers/staging/speakup/spk_ttyio.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/speakup/spk_ttyio.c +1 -3
index 4d7d8f2..a6330e2 100644
@@ -51,10 +51,8 @@ static int spk_ttyio_ldisc_open(struct tty_struct *tty)
 	speakup_tty = tty;
 
 	ldisc_data = kmalloc(sizeof(struct spk_ldisc_data), GFP_KERNEL);
-	if (!ldisc_data) {
-		pr_err("speakup: Failed to allocate ldisc_data.\n");
+	if (!ldisc_data)
 		return -ENOMEM;
-	}
 
 	sema_init(&ldisc_data->sem, 0);
 	ldisc_data->buf_free = true;
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Meghana Madhyastha

Remove print statement following unsuccessful kmalloc when there is not enough memory. Kmalloc and variants normally produce a backtrace in such a case. Hence, a print statement is not necessary.

Found using the following Coccinelle semantic patch:

@@
identifier i;
@@

Quoted 8 lines

i = (\(kmalloc\|devm_kzalloc\|kmalloc_array\| devm_ioremap\|usb_alloc_urb\|alloc_netdev\|dev_alloc_skb\| kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...));
(
if (i == NULL)
{ -\(DBG_8723A\|printk\|pr_err\|CERROR\|DBG_88E\)(...);

In general, you don't really know what the possible printing functions could be. But most would have a string argument. So you can say:

@@
identifier print;
constant char [] c;
@@

print(...,c,...);

to match a print function. Of course it is a bit less safe, because other functions may have a string argument. But it is not so likely in error handling code. And if you get false positives, ie reports that are incorrect, you can just ignore them. There should not be a large number.

Quoted 21 lines

...when any
}
|
if (!i)
{ -\(DBG_8723A\|printk\|pr_err\|CERROR\|DBG_88E\)(...); ...when any
}
)

@@
identifier i;
@@
(
- if (i == NULL) {
+ if (i == NULL)

       return ...;

- }
|
- if (!i) {
+ if (!i)

Quoted 5 lines
       return ...;

- }
)

Quoted 30 lines
---
 drivers/staging/speakup/spk_ttyio.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/speakup/spk_ttyio.c +1 -4
index 4d7d8f2..a6330e2 100644
@@ -51,10 +51,8 @@ static int spk_ttyio_ldisc_open(struct tty_struct *tty)
 	speakup_tty = tty;
 
 	ldisc_data = kmalloc(sizeof(struct spk_ldisc_data), GFP_KERNEL);
-	if (!ldisc_data) {
-		pr_err("speakup: Failed to allocate ldisc_data.\n");
+	if (!ldisc_data)
 		return -ENOMEM;
-	}
 
 	sema_init(&ldisc_data->sem, 0);
 	ldisc_data->buf_free = true;
--

2.7.4

--
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/20170916050400.GA31327%40meghana-HP-Pavilion-Notebook.
For more options, visit https://groups.google.com/d/optout.