Skip to content

Commit

Permalink
net: sxgbe: fix potential null dereference
Browse files Browse the repository at this point in the history
This fixes following:

drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c:1828 sxgbe_hw_init()
error: potential null dereference 'priv->hw'.  (kmalloc returns null)

Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Byungho An <bh74.an@samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Byungho An authored and David S. Miller committed Mar 28, 2014
1 parent 40b92ca commit 2405e8f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2039,11 +2039,13 @@ static void sxgbe_get_ops(struct sxgbe_ops * const ops_ptr)
* Description: this function checks the HW capability
* (if supported) and sets the driver's features.
*/
static void sxgbe_hw_init(struct sxgbe_priv_data * const priv)
static int sxgbe_hw_init(struct sxgbe_priv_data * const priv)
{
u32 ctrl_ids;

priv->hw = kmalloc(sizeof(*priv->hw), GFP_KERNEL);
if(!priv->hw)
return -ENOMEM;

/* get the hardware ops */
sxgbe_get_ops(priv->hw);
Expand All @@ -2064,6 +2066,8 @@ static void sxgbe_hw_init(struct sxgbe_priv_data * const priv)

if (priv->hw_cap.rx_csum_offload)
pr_info("RX Checksum offload supported\n");

return 0;
}

/**
Expand Down Expand Up @@ -2102,7 +2106,9 @@ struct sxgbe_priv_data *sxgbe_drv_probe(struct device *device,
sxgbe_verify_args();

/* Init MAC and get the capabilities */
sxgbe_hw_init(priv);
ret = sxgbe_hw_init(priv);
if (ret)
goto error_free_netdev;

/* allocate memory resources for Descriptor rings */
ret = txring_mem_alloc(priv);
Expand Down

0 comments on commit 2405e8f

Please sign in to comment.