Skip to content

Commit a6c0f82

Browse files
Denis Kirjanovdavem330
authored andcommitted
ieee802154: Fix possible NULL pointer dereference in wpan_phy_alloc
Check for NULL pointer after kzalloc Signed-off-by: Denis Kirjanov <dkirjanov@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 418c437 commit a6c0f82

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎net/ieee802154/wpan-class.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,15 @@ struct wpan_phy *wpan_phy_alloc(size_t priv_size)
147147
struct wpan_phy *phy = kzalloc(sizeof(*phy) + priv_size,
148148
GFP_KERNEL);
149149

150+
if (!phy)
151+
goto out;
150152
mutex_lock(&wpan_phy_mutex);
151153
phy->idx = wpan_phy_idx++;
152154
if (unlikely(!wpan_phy_idx_valid(phy->idx))) {
153155
wpan_phy_idx--;
154156
mutex_unlock(&wpan_phy_mutex);
155157
kfree(phy);
156-
return NULL;
158+
goto out;
157159
}
158160
mutex_unlock(&wpan_phy_mutex);
159161

@@ -168,6 +170,9 @@ struct wpan_phy *wpan_phy_alloc(size_t priv_size)
168170
phy->current_page = 0; /* for compatibility */
169171

170172
return phy;
173+
174+
out:
175+
return NULL;
171176
}
172177
EXPORT_SYMBOL(wpan_phy_alloc);
173178

0 commit comments

Comments
 (0)