Skip to contentSkip to conversation

staging: netlogic: Remove unnecessary error print

PATCH In review Himadri Pandya 2 participants 4 messages Mar 21, 2019 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: netlogic: Remove unnecessary error print

Kmalloc normally produces a backtrace when there is not enough memory. So it is unnecessary to print an error message that provides only this information. Hence, remove pr_error() from memory allocation check. Issue found using Coccinelle.

---
 drivers/staging/netlogic/xlr_net.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/netlogic/xlr_net.c +1 -3
index 8554fcf4321b..afba1248e100 100644
@@ -389,10 +389,8 @@ static void *xlr_config_spill(struct xlr_net_priv *priv, int reg_start_0,
 	base = priv->base_addr;
 	spill_size = size;
 	spill = kmalloc(spill_size + SMP_CACHE_BYTES, GFP_ATOMIC);
-	if (!spill) {
-		pr_err("Unable to allocate memory for spill area!\n");
+	if (!spill)
 		return ZERO_SIZE_PTR;
-	}
 
 	spill = PTR_ALIGN(spill, SMP_CACHE_BYTES);
 	phys_addr = virt_to_phys(spill);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 15 lines · Himadri Pandya

Kmalloc normally produces a backtrace when there is not enough memory. So it is unnecessary to print an error message that provides only this information. Hence, remove pr_error() from memory allocation check. Issue found using Coccinelle.

---
 drivers/staging/netlogic/xlr_net.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/netlogic/xlr_net.c +0 -0
index 8554fcf4321b..afba1248e100 100644

drivers/staging/netlogic/xlr_net.c static void *xlr_config_spill(struct xlr_net_priv *priv, int reg_start_0, · line 393

Quoted 7 lines
drivers/staging/netlogic/xlr_net.c +1 -2
@@ -389,10 +389,8 @@ static void *xlr_config_spill(struct xlr_net_priv *priv, int reg_start_0,
 	base = priv->base_addr;
 	spill_size = size;
 	spill = kmalloc(spill_size + SMP_CACHE_BYTES, GFP_ATOMIC);
-	if (!spill) {
-		pr_err("Unable to allocate memory for spill area!\n");
+	if (!spill)
 		return ZERO_SIZE_PTR;

This seems to be the only driver that uses ZERO_SIZE_PTR as the result for kmalloc. It could be worth looking into what happens to this value afterwards.

julia

Quoted 14 lines
drivers/staging/netlogic/xlr_net.c +0 -2
-	}
 
 	spill = PTR_ALIGN(spill, SMP_CACHE_BYTES);
 	phys_addr = virt_to_phys(spill);
--

2.17.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/20190321095717.24155-1-himadri18.07%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw
Quoted 29 lines · Julia Lawall

Review

Quoted 11 lines · Himadri Pandya

Kmalloc normally produces a backtrace when there is not enough memory. So it is unnecessary to print an error message that provides only this information. Hence, remove pr_error() from memory allocation check. Issue found using Coccinelle.

---
 drivers/staging/netlogic/xlr_net.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/netlogic/xlr_net.c

drivers/staging/netlogic/xlr_net.c static void *xlr_config_spill(struct xlr_net_priv

Quoted 4 lines

index 8554fcf4321b..afba1248e100 100644

drivers/staging/netlogic/xlr_net.c +0 -0
@@ -389,10 +389,8 @@ static void *xlr_config_spill(struct xlr_net_priv

*priv, int reg_start_0,

drivers/staging/netlogic/xlr_net.c static void *xlr_config_spill(struct xlr_net_priv *priv, int reg_start_0, · line 393

Quoted 7 lines
drivers/staging/netlogic/xlr_net.c +1 -2
      base = priv->base_addr;
      spill_size = size;
      spill = kmalloc(spill_size + SMP_CACHE_BYTES, GFP_ATOMIC);
-     if (!spill) {
-             pr_err("Unable to allocate memory for spill area!\n");
+     if (!spill)
              return ZERO_SIZE_PTR;
Quoted 6 lines

This seems to be the only driver that uses ZERO_SIZE_PTR as the result for kmalloc. It could be worth looking into what happens to this value afterwards.

julia

This is interesting. Later the pointer *spill* is aligned with *SMP_CACHE_BYTE**S (which is defined using L1_CACHE_BYTES). * As per my understanding, *xlr_config_spill() *returns ZERO_SIZE_PTR if *kmalloc()* cannot allocate sufficient memory(equivalent to *spill_size*) as the return value is being used to configure network accelerator's communication interface.

Please correct me if I am mistaken.

Thank you.

- Himadri

Quoted 20 lines
Quoted 10 lines
drivers/staging/netlogic/xlr_net.c +0 -2
-     }
 
      spill = PTR_ALIGN(spill, SMP_CACHE_BYTES);
      phys_addr = virt_to_phys(spill);
--

2.17.1

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send

an email to [email protected].

Quoted 2 lines

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/20190321095717.24155-1-himadri18.07%40gmail.com
.

Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.

#3 lore raw
Quoted 34 lines · Himadri Pandya

On Thu, Mar 21, 2019 at 3:38 PM Julia Lawall <[email protected]> wrote:

On Thu, 21 Mar 2019, Himadri Pandya wrote:

> Kmalloc normally produces a backtrace when there is not enough memory.
> So it is unnecessary to print an error message that provides only this
> information. Hence, remove pr_error() from memory allocation check.
> Issue found using Coccinelle.
>
> Signed-off-by: Himadri Pandya <[email protected]>
> ---
>ᅵ drivers/staging/netlogic/xlr_net.c | 4 +---
>ᅵ 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/staging/netlogic/xlr_net.c b/drivers/staging/netlogic/xlr_net.c > index 8554fcf4321b..afba1248e100 100644
> --- a/drivers/staging/netlogic/xlr_net.c
> +++ b/drivers/staging/netlogic/xlr_net.c
> @@ -389,10 +389,8 @@ static void *xlr_config_spill(struct xlr_net_priv *priv, int reg_start_0, >ᅵ ᅵ ᅵ ᅵbase = priv->base_addr;
>ᅵ ᅵ ᅵ ᅵspill_size = size;
>ᅵ ᅵ ᅵ ᅵspill = kmalloc(spill_size + SMP_CACHE_BYTES, GFP_ATOMIC);
> -ᅵ ᅵ ᅵif (!spill) {
> -ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵpr_err("Unable to allocate memory for spill area!\n"); > +ᅵ ᅵ ᅵif (!spill)
>ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵ ᅵreturn ZERO_SIZE_PTR;

This seems to be the only driver that uses ZERO_SIZE_PTR as the result for kmalloc.ᅵ It could be worth looking into what happens to this value afterwards.

Quoted 5 lines

julia

This is interesting. Later the pointer spillᅵis aligned withᅵSMP_CACHE_BYTES (which is defined using L1_CACHE_BYTES).ᅵᅵAs per my understanding,ᅵxlr_config_spill() returns ZERO_SIZE_PTR if kmalloc()ᅵcannot allocate sufficient memory(equivalent to spill_size) as the return value is being used to configure network accelerator's communication interface.

The questin is who is checking the return value and whether it is checked in the right manner. I looked quickly at the cal site, and it seemed that the result as stored in a structure field with no checking, But perhaps some checking is done afterwards.

julia

Quoted 31 lines

Please correct me if I am mistaken.

Thank you.

- Himadri
ᅵ

      > -ᅵ ᅵ ᅵ}
      >
      >ᅵ ᅵ ᅵ ᅵspill = PTR_ALIGN(spill, SMP_CACHE_BYTES);
      >ᅵ ᅵ ᅵ ᅵphys_addr = virt_to_phys(spill);
      > --
      > 2.17.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/20190321095717.24155-1-himadri18.07%40gmail.com.
      > For more options, visit https://groups.google.com/d/optout.
      >

--
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/CAPnhUpaXwEBMFa_ukU9uauFuEaUojMju_kG%2BWHnJ9SQcAXrSpA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.