netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Missing return check against Null for return value of netdev_alloc_dev_skb()
@ 2014-06-15  4:05 Nick
  2014-06-15  4:39 ` Nick Krause
  2014-06-15  6:53 ` David Miller
  0 siblings, 2 replies; 7+ messages in thread
From: Nick @ 2014-06-15  4:05 UTC (permalink / raw)
  To: davem
  Cc: andriy.shevchenko, dvhart, jeffrey.t.kirsher, ast, dborkman,
	bhutchings, netdev, linux-kernel

Signed-off-by: Nick <xerofoify@gmail.com>
---
 drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
index 73e6683..704cf63 100644
--- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
+++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
@@ -1515,6 +1515,8 @@ static void pch_gbe_alloc_tx_buffers(struct pch_gbe_adapter *adapter,
 	for (i = 0; i < tx_ring->count; i++) {
 		buffer_info = &tx_ring->buffer_info[i];
 		skb = netdev_alloc_skb(adapter->netdev, bufsz);
+		if (!skb)
+			return NULL;
 		skb_reserve(skb, PCH_GBE_DMA_ALIGN);
 		buffer_info->skb = skb;
 		tx_desc = PCH_GBE_TX_DESC(*tx_ring, i);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Missing return check against Null for return value of netdev_alloc_dev_skb()
  2014-06-15  4:05 [PATCH] Missing return check against Null for return value of netdev_alloc_dev_skb() Nick
@ 2014-06-15  4:39 ` Nick Krause
  2014-06-15  6:53 ` David Miller
  1 sibling, 0 replies; 7+ messages in thread
From: Nick Krause @ 2014-06-15  4:39 UTC (permalink / raw)
  To: davem
  Cc: andriy.shevchenko, dvhart, jeffrey.t.kirsher, ast, dborkman,
	netdev, linux-kernel, bwh

I am resending this patch as the email for Ben is wrong in the
maintainer script due to getting automated message from solarflare.
Signed-off-by: Nick <xerofoify@gmail.com>
---
 drivers/net/ethernet/oki-semi/
pch_gbe/pch_gbe_main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
index 73e6683..704cf63 100644
--- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
+++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
@@ -1515,6 +1515,8 @@ static void pch_gbe_alloc_tx_buffers(struct
pch_gbe_adapter *adapter,
        for (i = 0; i < tx_ring->count; i++) {
                buffer_info = &tx_ring->buffer_info[i];
                skb = netdev_alloc_skb(adapter->netdev, bufsz);
+               if (!skb)
+                       return NULL;
                skb_reserve(skb, PCH_GBE_DMA_ALIGN);
                buffer_info->skb = skb;
                tx_desc = PCH_GBE_TX_DESC(*tx_ring, i);
Thanks Nick

On Sun, Jun 15, 2014 at 12:05 AM, Nick <xerofoify@gmail.com> wrote:
> Signed-off-by: Nick <xerofoify@gmail.com>
> ---
>  drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
> index 73e6683..704cf63 100644
> --- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
> +++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
> @@ -1515,6 +1515,8 @@ static void pch_gbe_alloc_tx_buffers(struct pch_gbe_adapter *adapter,
>         for (i = 0; i < tx_ring->count; i++) {
>                 buffer_info = &tx_ring->buffer_info[i];
>                 skb = netdev_alloc_skb(adapter->netdev, bufsz);
> +               if (!skb)
> +                       return NULL;
>                 skb_reserve(skb, PCH_GBE_DMA_ALIGN);
>                 buffer_info->skb = skb;
>                 tx_desc = PCH_GBE_TX_DESC(*tx_ring, i);
> --
> 1.9.1
>

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Missing return check against Null for return value of netdev_alloc_dev_skb()
  2014-06-15  4:05 [PATCH] Missing return check against Null for return value of netdev_alloc_dev_skb() Nick
  2014-06-15  4:39 ` Nick Krause
@ 2014-06-15  6:53 ` David Miller
  2014-06-15 20:27   ` Nick Krause
  1 sibling, 1 reply; 7+ messages in thread
From: David Miller @ 2014-06-15  6:53 UTC (permalink / raw)
  To: xerofoify
  Cc: andriy.shevchenko, dvhart, jeffrey.t.kirsher, ast, dborkman,
	bhutchings, netdev, linux-kernel

From: Nick <xerofoify@gmail.com>
Date: Sun, 15 Jun 2014 00:05:39 -0400

> Signed-off-by: Nick <xerofoify@gmail.com>
> ---
>  drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
> index 73e6683..704cf63 100644
> --- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
> +++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
> @@ -1515,6 +1515,8 @@ static void pch_gbe_alloc_tx_buffers(struct pch_gbe_adapter *adapter,
>  	for (i = 0; i < tx_ring->count; i++) {
>  		buffer_info = &tx_ring->buffer_info[i];
>  		skb = netdev_alloc_skb(adapter->netdev, bufsz);
> +		if (!skb)
> +			return NULL;

You didn't even compile test this.

The function has a void return type, you can't return NULL.

Furthermore, you have to adjust things so that the caller knows that
this operation failed, because the device cannot be brought up
successfully unless all the TX buffer slots get allocated properly.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Missing return check against Null for return value of netdev_alloc_dev_skb()
  2014-06-15  6:53 ` David Miller
@ 2014-06-15 20:27   ` Nick Krause
  2014-06-16  2:26     ` David Miller
  2014-06-16 13:32     ` Sergei Shtylyov
  0 siblings, 2 replies; 7+ messages in thread
From: Nick Krause @ 2014-06-15 20:27 UTC (permalink / raw)
  To: David Miller
  Cc: andriy.shevchenko, dvhart, jeffrey.t.kirsher, ast, dborkman,
	bhutchings, netdev, linux-kernel

>From 62b0d77a1430f74b7f5c008c5e8bec11604b33b0 Mon Sep 17 00:00:00 2001
From: Nick <xerofoify@gmail.com>
Date: Sun, 15 Jun 2014 16:16:14 -0400
Subject: [PATCHv2] Fixes return logic of function of pch_gbe_alloc_tx_buffers()
Here is the fixed patch changed return type of function to int in
order to use return -ENOMEM as with the function above it , seems to
fit , otherwise returns 0.
 Report if it breaks anything related to this driver.
Signed-off-by: Nick <xerofoify@gmail.com>
---
 drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
index 704cf63..7d5efd7 100644
--- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
+++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
@@ -1500,7 +1500,7 @@ pch_gbe_alloc_rx_buffers_pool(struct
pch_gbe_adapter *adapter,
  * @adapter:   Board private structure
  * @tx_ring:   Tx descriptor ring
  */
-static void pch_gbe_alloc_tx_buffers(struct pch_gbe_adapter *adapter,
+static int pch_gbe_alloc_tx_buffers(struct pch_gbe_adapter *adapter
 struct pch_gbe_tx_ring *tx_ring)
 {
     struct pch_gbe_buffer *buffer_info;
@@ -1516,13 +1516,13 @@ static void pch_gbe_alloc_tx_buffers(struct
pch_gbe_adapter *adapter,
         buffer_info = &tx_ring->buffer_info[i];
         skb = netdev_alloc_skb(adapter->netdev, bufsz);
         if(!skb)
+            return -ENOMEM;
         skb_reserve(skb, PCH_GBE_DMA_ALIGN);
         buffer_info->skb = skb;
         tx_desc = PCH_GBE_TX_DESC(*tx_ring, i);
         tx_desc->gbec_status = (DSC_INIT16);
     }
-    return;
+    return 0;
 }

 /**
-- 
1.9.1
Thanks for the Comments,
Nick

On Sun, Jun 15, 2014 at 2:53 AM, David Miller <davem@davemloft.net> wrote:
> From: Nick <xerofoify@gmail.com>
> Date: Sun, 15 Jun 2014 00:05:39 -0400
>
>> Signed-off-by: Nick <xerofoify@gmail.com>
>> ---
>>  drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
>> index 73e6683..704cf63 100644
>> --- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
>> +++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
>> @@ -1515,6 +1515,8 @@ static void pch_gbe_alloc_tx_buffers(struct pch_gbe_adapter *adapter,
>>       for (i = 0; i < tx_ring->count; i++) {
>>               buffer_info = &tx_ring->buffer_info[i];
>>               skb = netdev_alloc_skb(adapter->netdev, bufsz);
>> +             if (!skb)
>> +                     return NULL;
>
> You didn't even compile test this.
>
> The function has a void return type, you can't return NULL.
>
> Furthermore, you have to adjust things so that the caller knows that
> this operation failed, because the device cannot be brought up
> successfully unless all the TX buffer slots get allocated properly.

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Missing return check against Null for return value of netdev_alloc_dev_skb()
  2014-06-15 20:27   ` Nick Krause
@ 2014-06-16  2:26     ` David Miller
  2014-06-16  3:28       ` Nick Krause
  2014-06-16 13:32     ` Sergei Shtylyov
  1 sibling, 1 reply; 7+ messages in thread
From: David Miller @ 2014-06-16  2:26 UTC (permalink / raw)
  To: xerofoify
  Cc: andriy.shevchenko, dvhart, jeffrey.t.kirsher, ast, dborkman,
	bhutchings, netdev, linux-kernel

From: Nick Krause <xerofoify@gmail.com>
Date: Sun, 15 Jun 2014 16:27:23 -0400

> From 62b0d77a1430f74b7f5c008c5e8bec11604b33b0 Mon Sep 17 00:00:00 2001
> From: Nick <xerofoify@gmail.com>
> Date: Sun, 15 Jun 2014 16:16:14 -0400
> Subject: [PATCHv2] Fixes return logic of function of pch_gbe_alloc_tx_buffers()
> Here is the fixed patch changed return type of function to int in
> order to use return -ENOMEM as with the function above it , seems to
> fit , otherwise returns 0.
>  Report if it breaks anything related to this driver.
> Signed-off-by: Nick <xerofoify@gmail.com>

Nobody is checking the return value, you can't just change the function to
return an error code, you have to make the caller act upon it appropriately
as well.

I'm very much not confident that you are willing to put in the effort
necessary to fix this problem properly.

I told you explicitly that if this memory allocation failure occurs, the
bringup of the device has to fail.

Your patch is making the situation worse, it breaks when there is an
allocation failure, leaving the TX run partially allocated so that the
driver will crash with an OOPS later.

>From your first iteration, you aren't build testing this change, and I
therefore severely doubt you are functionally testing this change either.

I hate to be harsh, but this is an extremely _poor_ patch submission.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Missing return check against Null for return value of netdev_alloc_dev_skb()
  2014-06-16  2:26     ` David Miller
@ 2014-06-16  3:28       ` Nick Krause
  0 siblings, 0 replies; 7+ messages in thread
From: Nick Krause @ 2014-06-16  3:28 UTC (permalink / raw)
  To: David Miller
  Cc: andriy.shevchenko, dvhart, jeffrey.t.kirsher, ast, dborkman,
	bhutchings, netdev, linux-kernel

Fair enjoy I was wondering if it fails I can run a goto statement and
then free the memory for the tx as needed.
Cheers Nick
P.S. That was really stupid I didn't think that through at all :)

On Sun, Jun 15, 2014 at 10:26 PM, David Miller <davem@davemloft.net> wrote:
> From: Nick Krause <xerofoify@gmail.com>
> Date: Sun, 15 Jun 2014 16:27:23 -0400
>
>> From 62b0d77a1430f74b7f5c008c5e8bec11604b33b0 Mon Sep 17 00:00:00 2001
>> From: Nick <xerofoify@gmail.com>
>> Date: Sun, 15 Jun 2014 16:16:14 -0400
>> Subject: [PATCHv2] Fixes return logic of function of pch_gbe_alloc_tx_buffers()
>> Here is the fixed patch changed return type of function to int in
>> order to use return -ENOMEM as with the function above it , seems to
>> fit , otherwise returns 0.
>>  Report if it breaks anything related to this driver.
>> Signed-off-by: Nick <xerofoify@gmail.com>
>
> Nobody is checking the return value, you can't just change the function to
> return an error code, you have to make the caller act upon it appropriately
> as well.
>
> I'm very much not confident that you are willing to put in the effort
> necessary to fix this problem properly.
>
> I told you explicitly that if this memory allocation failure occurs, the
> bringup of the device has to fail.
>
> Your patch is making the situation worse, it breaks when there is an
> allocation failure, leaving the TX run partially allocated so that the
> driver will crash with an OOPS later.
>
> From your first iteration, you aren't build testing this change, and I
> therefore severely doubt you are functionally testing this change either.
>
> I hate to be harsh, but this is an extremely _poor_ patch submission.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Missing return check against Null for return value of netdev_alloc_dev_skb()
  2014-06-15 20:27   ` Nick Krause
  2014-06-16  2:26     ` David Miller
@ 2014-06-16 13:32     ` Sergei Shtylyov
  1 sibling, 0 replies; 7+ messages in thread
From: Sergei Shtylyov @ 2014-06-16 13:32 UTC (permalink / raw)
  To: Nick Krause, David Miller
  Cc: andriy.shevchenko, dvhart, jeffrey.t.kirsher, ast, dborkman,
	bhutchings, netdev, linux-kernel

Hello.

On 06/16/2014 12:27 AM, Nick Krause wrote:

>  From 62b0d77a1430f74b7f5c008c5e8bec11604b33b0 Mon Sep 17 00:00:00 2001
> From: Nick <xerofoify@gmail.com>
> Date: Sun, 15 Jun 2014 16:16:14 -0400
> Subject: [PATCHv2] Fixes return logic of function of pch_gbe_alloc_tx_buffers()
> Here is the fixed patch changed return type of function to int in
> order to use return -ENOMEM as with the function above it , seems to
> fit , otherwise returns 0.
>   Report if it breaks anything related to this driver.
> Signed-off-by: Nick <xerofoify@gmail.com>

    You should specify your full name in the "Signed-off:" line.

WBR, Sergei

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-06-16 13:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-15  4:05 [PATCH] Missing return check against Null for return value of netdev_alloc_dev_skb() Nick
2014-06-15  4:39 ` Nick Krause
2014-06-15  6:53 ` David Miller
2014-06-15 20:27   ` Nick Krause
2014-06-16  2:26     ` David Miller
2014-06-16  3:28       ` Nick Krause
2014-06-16 13:32     ` Sergei Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).