Browse Source

net: use NLMSG_DEFAULT_SIZE in nlmsg_new() allocations

nlmsg_new() adds the size of the netlink header to the value
that has been passed as parameter. If NLMSG_GOODSIZE is selected,
we request an allocation of one memory page plus the size of the
header. Instead, NLMSG_DEFAULT_SIZE should be used since it
already substracts the size of the Netlink header.

I have the impression that the similar naming in both constant
is error prone when using it with nlmsg_new(). This is already
documented in include/net/netlink.h

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Pablo Neira Ayuso 16 years ago
parent
commit
fd2120ca0d
2 changed files with 17 additions and 17 deletions
  1. 1 1
      net/irda/irnetlink.c
  2. 16 16
      net/wireless/nl80211.c

+ 1 - 1
net/irda/irnetlink.c

@@ -87,7 +87,7 @@ static int irda_nl_get_mode(struct sk_buff *skb, struct genl_info *info)
 	if (!dev)
 	if (!dev)
 		return -ENODEV;
 		return -ENODEV;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg) {
 	if (!msg) {
 		dev_put(dev);
 		dev_put(dev);
 		return -ENOMEM;
 		return -ENOMEM;

+ 16 - 16
net/wireless/nl80211.c

@@ -388,7 +388,7 @@ static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
 	if (IS_ERR(dev))
 	if (IS_ERR(dev))
 		return PTR_ERR(dev);
 		return PTR_ERR(dev);
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg)
 	if (!msg)
 		goto out_err;
 		goto out_err;
 
 
@@ -716,7 +716,7 @@ static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg)
 	if (!msg)
 		goto out_err;
 		goto out_err;
 
 
@@ -989,7 +989,7 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
 		goto out;
 		goto out;
 	}
 	}
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg) {
 	if (!msg) {
 		err = -ENOMEM;
 		err = -ENOMEM;
 		goto out;
 		goto out;
@@ -1600,7 +1600,7 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
 	if (err)
 	if (err)
 		goto out;
 		goto out;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg)
 	if (!msg)
 		goto out;
 		goto out;
 
 
@@ -1994,7 +1994,7 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
 	if (err)
 	if (err)
 		goto out;
 		goto out;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg)
 	if (!msg)
 		goto out;
 		goto out;
 
 
@@ -2310,7 +2310,7 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
 		goto out;
 		goto out;
 
 
 	/* Draw up a netlink message to send back */
 	/* Draw up a netlink message to send back */
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg) {
 	if (!msg) {
 		err = -ENOBUFS;
 		err = -ENOBUFS;
 		goto out;
 		goto out;
@@ -2488,7 +2488,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
 	if (!cfg80211_regdomain)
 	if (!cfg80211_regdomain)
 		goto out;
 		goto out;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg) {
 	if (!msg) {
 		err = -ENOBUFS;
 		err = -ENOBUFS;
 		goto out;
 		goto out;
@@ -3541,7 +3541,7 @@ void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
 {
 {
 	struct sk_buff *msg;
 	struct sk_buff *msg;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg)
 	if (!msg)
 		return;
 		return;
 
 
@@ -3582,7 +3582,7 @@ void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
 {
 {
 	struct sk_buff *msg;
 	struct sk_buff *msg;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg)
 	if (!msg)
 		return;
 		return;
 
 
@@ -3600,7 +3600,7 @@ void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
 {
 {
 	struct sk_buff *msg;
 	struct sk_buff *msg;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg)
 	if (!msg)
 		return;
 		return;
 
 
@@ -3622,7 +3622,7 @@ void nl80211_send_reg_change_event(struct regulatory_request *request)
 	struct sk_buff *msg;
 	struct sk_buff *msg;
 	void *hdr;
 	void *hdr;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg)
 	if (!msg)
 		return;
 		return;
 
 
@@ -3676,7 +3676,7 @@ static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
 	struct sk_buff *msg;
 	struct sk_buff *msg;
 	void *hdr;
 	void *hdr;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
 	if (!msg)
 	if (!msg)
 		return;
 		return;
 
 
@@ -3739,7 +3739,7 @@ static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
 	struct sk_buff *msg;
 	struct sk_buff *msg;
 	void *hdr;
 	void *hdr;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
 	if (!msg)
 	if (!msg)
 		return;
 		return;
 
 
@@ -3787,7 +3787,7 @@ void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
 	struct sk_buff *msg;
 	struct sk_buff *msg;
 	void *hdr;
 	void *hdr;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
 	if (!msg)
 	if (!msg)
 		return;
 		return;
 
 
@@ -3822,7 +3822,7 @@ void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
 	struct sk_buff *msg;
 	struct sk_buff *msg;
 	void *hdr;
 	void *hdr;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
 	if (!msg)
 	if (!msg)
 		return;
 		return;
 
 
@@ -3862,7 +3862,7 @@ void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
 	void *hdr;
 	void *hdr;
 	struct nlattr *nl_freq;
 	struct nlattr *nl_freq;
 
 
-	msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
 	if (!msg)
 	if (!msg)
 		return;
 		return;