diff mbox

ixgbe: correctly handling failed allocation

Message ID 1451426117-30986-1-git-send-email-wuninsu@gmail.com
State Not Applicable
Headers show

Commit Message

Insu Yun Dec. 29, 2015, 9:55 p.m. UTC
Since kzalloc can be failed in memory pressure,
NULL derefence could be happened.

Signed-off-by: Insu Yun <wuninsu@gmail.com>
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Alexander Duyck Dec. 29, 2015, 11:51 p.m. UTC | #1
On Tue, Dec 29, 2015 at 1:55 PM, Insu Yun <wuninsu@gmail.com> wrote:
> Since kzalloc can be failed in memory pressure,
> NULL derefence could be happened.
>
> Signed-off-by: Insu Yun <wuninsu@gmail.com>
> ---
>  drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> index aed8d02..aa5eda0 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> @@ -5331,6 +5331,8 @@ static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
>         adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
>                                      hw->mac.num_rar_entries,
>                                      GFP_ATOMIC);
> +       if (!adapter->mac_table)
> +               return -ENOMEM;
>
>         /* Set MAC specific capability flags and exceptions */
>         switch (hw->mac.type) {
> --
> 1.9.1

That change is already present in the current net-next.

Take a look at commit 530fd82a9fea ("ixgbe: Return error on failure to
allocate mac_table").

- Alex
Insu Yun Dec. 30, 2015, 12:01 a.m. UTC | #2
Ok. Thank you.

On Tue, Dec 29, 2015 at 6:51 PM, Alexander Duyck <alexander.duyck@gmail.com>
wrote:

> On Tue, Dec 29, 2015 at 1:55 PM, Insu Yun <wuninsu@gmail.com> wrote:
> > Since kzalloc can be failed in memory pressure,
> > NULL derefence could be happened.
> >
> > Signed-off-by: Insu Yun <wuninsu@gmail.com>
> > ---
> >  drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> > index aed8d02..aa5eda0 100644
> > --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> > +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> > @@ -5331,6 +5331,8 @@ static int ixgbe_sw_init(struct ixgbe_adapter
> *adapter)
> >         adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
> >                                      hw->mac.num_rar_entries,
> >                                      GFP_ATOMIC);
> > +       if (!adapter->mac_table)
> > +               return -ENOMEM;
> >
> >         /* Set MAC specific capability flags and exceptions */
> >         switch (hw->mac.type) {
> > --
> > 1.9.1
>
> That change is already present in the current net-next.
>
> Take a look at commit 530fd82a9fea ("ixgbe: Return error on failure to
> allocate mac_table").
>
> - Alex
>
diff mbox

Patch

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index aed8d02..aa5eda0 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -5331,6 +5331,8 @@  static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
 	adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
 				     hw->mac.num_rar_entries,
 				     GFP_ATOMIC);
+	if (!adapter->mac_table)
+		return -ENOMEM;
 
 	/* Set MAC specific capability flags and exceptions */
 	switch (hw->mac.type) {