Skip to content

Commit 2405e8f

Browse files
Byungho Andavem330
authored andcommitted
net: sxgbe: fix potential null dereference
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 <[email protected]> Signed-off-by: Byungho An <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 40b92ca commit 2405e8f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,11 +2039,13 @@ static void sxgbe_get_ops(struct sxgbe_ops * const ops_ptr)
20392039
* Description: this function checks the HW capability
20402040
* (if supported) and sets the driver's features.
20412041
*/
2042-
static void sxgbe_hw_init(struct sxgbe_priv_data * const priv)
2042+
static int sxgbe_hw_init(struct sxgbe_priv_data * const priv)
20432043
{
20442044
u32 ctrl_ids;
20452045

20462046
priv->hw = kmalloc(sizeof(*priv->hw), GFP_KERNEL);
2047+
if(!priv->hw)
2048+
return -ENOMEM;
20472049

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

20652067
if (priv->hw_cap.rx_csum_offload)
20662068
pr_info("RX Checksum offload supported\n");
2069+
2070+
return 0;
20672071
}
20682072

20692073
/**
@@ -2102,7 +2106,9 @@ struct sxgbe_priv_data *sxgbe_drv_probe(struct device *device,
21022106
sxgbe_verify_args();
21032107

21042108
/* Init MAC and get the capabilities */
2105-
sxgbe_hw_init(priv);
2109+
ret = sxgbe_hw_init(priv);
2110+
if (ret)
2111+
goto error_free_netdev;
21062112

21072113
/* allocate memory resources for Descriptor rings */
21082114
ret = txring_mem_alloc(priv);

0 commit comments

Comments
 (0)