Skip to content

Commit

Permalink
ieee802154: Fix possible NULL pointer dereference in wpan_phy_alloc
Browse files Browse the repository at this point in the history
Check for NULL pointer after kzalloc

Signed-off-by: Denis Kirjanov <dkirjanov@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Denis Kirjanov authored and David S. Miller committed May 24, 2010
1 parent 418c437 commit a6c0f82
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion net/ieee802154/wpan-class.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ struct wpan_phy *wpan_phy_alloc(size_t priv_size)
struct wpan_phy *phy = kzalloc(sizeof(*phy) + priv_size,
GFP_KERNEL);

if (!phy)
goto out;
mutex_lock(&wpan_phy_mutex);
phy->idx = wpan_phy_idx++;
if (unlikely(!wpan_phy_idx_valid(phy->idx))) {
wpan_phy_idx--;
mutex_unlock(&wpan_phy_mutex);
kfree(phy);
return NULL;
goto out;
}
mutex_unlock(&wpan_phy_mutex);

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

return phy;

out:
return NULL;
}
EXPORT_SYMBOL(wpan_phy_alloc);

Expand Down

0 comments on commit a6c0f82

Please sign in to comment.