Skip to content

Commit d5a73ec

Browse files
JiangJiasdavem330
authored andcommitted
fsl/fman: Check for null pointer after calling devm_ioremap
As the possible failure of the allocation, the devm_ioremap() may return NULL pointer. Take tgec_initialization() as an example. If allocation fails, the params->base_addr will be NULL pointer and will be assigned to tgec->regs in tgec_config(). Then it will cause the dereference of NULL pointer in set_mac_address(), which is called by tgec_init(). Therefore, it should be better to add the sanity check after the calling of the devm_ioremap(). Fixes: 3933961 ("fsl/fman: Add FMan MAC driver") Signed-off-by: Jiasheng Jiang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 43d0121 commit d5a73ec

File tree

1 file changed

+16
-5
lines changed
  • drivers/net/ethernet/freescale/fman

1 file changed

+16
-5
lines changed

drivers/net/ethernet/freescale/fman/mac.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,17 @@ static void mac_exception(void *handle, enum fman_mac_exceptions ex)
9494
__func__, ex);
9595
}
9696

97-
static void set_fman_mac_params(struct mac_device *mac_dev,
98-
struct fman_mac_params *params)
97+
static int set_fman_mac_params(struct mac_device *mac_dev,
98+
struct fman_mac_params *params)
9999
{
100100
struct mac_priv_s *priv = mac_dev->priv;
101101

102102
params->base_addr = (typeof(params->base_addr))
103103
devm_ioremap(priv->dev, mac_dev->res->start,
104104
resource_size(mac_dev->res));
105+
if (!params->base_addr)
106+
return -ENOMEM;
107+
105108
memcpy(&params->addr, mac_dev->addr, sizeof(mac_dev->addr));
106109
params->max_speed = priv->max_speed;
107110
params->phy_if = mac_dev->phy_if;
@@ -112,6 +115,8 @@ static void set_fman_mac_params(struct mac_device *mac_dev,
112115
params->event_cb = mac_exception;
113116
params->dev_id = mac_dev;
114117
params->internal_phy_node = priv->internal_phy_node;
118+
119+
return 0;
115120
}
116121

117122
static int tgec_initialization(struct mac_device *mac_dev)
@@ -123,7 +128,9 @@ static int tgec_initialization(struct mac_device *mac_dev)
123128

124129
priv = mac_dev->priv;
125130

126-
set_fman_mac_params(mac_dev, &params);
131+
err = set_fman_mac_params(mac_dev, &params);
132+
if (err)
133+
goto _return;
127134

128135
mac_dev->fman_mac = tgec_config(&params);
129136
if (!mac_dev->fman_mac) {
@@ -169,7 +176,9 @@ static int dtsec_initialization(struct mac_device *mac_dev)
169176

170177
priv = mac_dev->priv;
171178

172-
set_fman_mac_params(mac_dev, &params);
179+
err = set_fman_mac_params(mac_dev, &params);
180+
if (err)
181+
goto _return;
173182

174183
mac_dev->fman_mac = dtsec_config(&params);
175184
if (!mac_dev->fman_mac) {
@@ -218,7 +227,9 @@ static int memac_initialization(struct mac_device *mac_dev)
218227

219228
priv = mac_dev->priv;
220229

221-
set_fman_mac_params(mac_dev, &params);
230+
err = set_fman_mac_params(mac_dev, &params);
231+
if (err)
232+
goto _return;
222233

223234
if (priv->max_speed == SPEED_10000)
224235
params.phy_if = PHY_INTERFACE_MODE_XGMII;

0 commit comments

Comments
 (0)