Skip to contentSkip to conversation

IRDA: Fix genlmsg_put() return value check.

PATCH In review Julius Volz 4 participants 9 messages Jun 23, 2008 – Jun 30, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IRDA: Fix genlmsg_put() return value check.

Fix an incorrect return value check of genlmsg_put() in irda_nl_get_mode(). genlmsg_put() does not use ERR_PTR() to encode return values, it just returns NULL on error.

---
 net/irda/irnetlink.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/irda/irnetlink.c +2 -2
index 9e1fb82..ea11cb4 100644
@@ -101,8 +101,8 @@ static int irda_nl_get_mode(struct sk_buff *skb, struct genl_info *info)
 
 	hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
 			  &irda_nl_family, 0,  IRDA_NL_CMD_GET_MODE);
-	if (IS_ERR(hdr)) {
-		ret = PTR_ERR(hdr);
+	if (hdr == NULL) {
+		ret = -ENOMEM;
 		goto err_out;
 	}
 
Signature · 1 line
1.5.3.6
#1 lore raw
Quoted 14 lines · Julius Volz

Fix an incorrect return value check of genlmsg_put() in irda_nl_get_mode(). genlmsg_put() does not use ERR_PTR() to encode return values, it just returns NULL on error.

---
 net/irda/irnetlink.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/irda/irnetlink.c +0 -0
index 9e1fb82..ea11cb4 100644

net/irda/irnetlink.c static int irda_nl_get_mode(struct sk_buff *skb, struct genl_info *info) · line 107

Quoted 9 lines
net/irda/irnetlink.c +2 -2
@@ -101,8 +101,8 @@ static int irda_nl_get_mode(struct sk_buff *skb, struct genl_info *info)
 
 	hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
 			  &irda_nl_family, 0,  IRDA_NL_CMD_GET_MODE);
-	if (IS_ERR(hdr)) {
-		ret = PTR_ERR(hdr);
+	if (hdr == NULL) {
+		ret = -ENOMEM;
 		goto err_out;
 	}

Good catch, but the correct return value for insufficient space in the skb is -ENOSPC.

#2 lore raw

On Mon, 23 Jun 2008 21:43:31 +0200, Patrick McHardy <[email protected]>

Quoted 50 lines · wrote:
Quoted 1 line · Julius Volz

Fix an incorrect return value check of genlmsg_put() in

irda_nl_get_mode().

net/irda/irnetlink.c static int irda_nl_get_mode(struct sk_buff *skb,

Quoted 25 lines

genlmsg_put() does not use ERR_PTR() to encode return values, it just

returns NULL on error.

---

 net/irda/irnetlink.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/irda/irnetlink.c +0 -0

index 9e1fb82..ea11cb4 100644

--- a/net/irda/irnetlink.c

+++ b/net/irda/irnetlink.c

net/irda/irnetlink.c +0 -0
@@ -101,8 +101,8 @@ static int irda_nl_get_mode(struct sk_buff *skb,

struct genl_info *info)

Quoted 15 lines
net/irda/irnetlink.c +2 -2
 	hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
 
 			  &irda_nl_family, 0,  IRDA_NL_CMD_GET_MODE);
 
-	if (IS_ERR(hdr)) {
 
-		ret = PTR_ERR(hdr);
 
+	if (hdr == NULL) {
 
+		ret = -ENOMEM;
 
 		goto err_out;
Quoted 7 lines
Quoted 1 line

}

Good catch, but the correct return value for insufficient

space in the skb is -ENOSPC.

Thanks Julius, Patrick. I'll take this one and send it with

my next IrDA patch set.

Cheers,

Samuel.

#3 lore raw
In reply to Patrick McHardy
Quoted 2 lines · Patrick McHardy

Good catch, but the correct return value for insufficient space in the skb is -ENOSPC.

Hm, seems we have many inconsistent values returned in exactly this situation (in response to genlmsg_put), but none of them are -ENOSPC:

fs/dlm/netlink.c: -EINVAL
net/netlink/genetlink.c: -1
net/netlabel/netlabel_unlabeled.c: -ENOMEM
net/netlabel/netlabel_cipso_v4.c: -ENOMEM
net/netlabel/netlabel_mgmt.c: -ENOMEM
net/wireless/nl80211.c: -1
drivers/acpi/event.c: -ENOMEM
kernel/taskstats.c: -EINVAL

Seems like -ENOMEM is most common, don't know if that means it's correct, though...

I was also using -ENOMEM in my Netlink code, so better convert all my new uses to -ENOSPC?

Julius

Signature · 1 line
Google Switzerland GmbH
#4 lore raw
Quoted 16 lines · Julius Volz
Quoted 2 lines · Patrick McHardy

Good catch, but the correct return value for insufficient space in the skb is -ENOSPC.

Hm, seems we have many inconsistent values returned in exactly this situation (in response to genlmsg_put), but none of them are -ENOSPC:

fs/dlm/netlink.c: -EINVAL
net/netlink/genetlink.c: -1
net/netlabel/netlabel_unlabeled.c: -ENOMEM
net/netlabel/netlabel_cipso_v4.c: -ENOMEM
net/netlabel/netlabel_mgmt.c: -ENOMEM
net/wireless/nl80211.c: -1
drivers/acpi/event.c: -ENOMEM
kernel/taskstats.c: -EINVAL

Quoted 5 lines

Seems like -ENOMEM is most common, don't know if that means it's correct, though...

I was also using -ENOMEM in my Netlink code, so better convert all my new uses to -ENOSPC?

Yes, all those should be using ENOSPC as well. nl80211 returns inconsistent errors currently (-1/EMSGSIZE), but doesn't propagate them back to userspace. That should probably be fixed as well.

Actually I was wrong, its EMSGSIZE, not ENOSPC that should be returned, its more fitting and what other netlink users do as well.

#5 lore raw
Quoted 7 lines · Patrick McHardy

Yes, all those should be using ENOSPC as well. nl80211 returns inconsistent errors currently (-1/EMSGSIZE), but doesn't propagate them back to userspace. That should probably be fixed as well.

Actually I was wrong, its EMSGSIZE, not ENOSPC that should be returned, its more fitting and what other netlink users do as well.

Thanks, I will use that then!

Julius

Signature · 1 line
Google Switzerland GmbH
#6 lore raw

PATCH 1/1 IRDA: Fix genlmsg_put() return value check.

In reply to Julius Volz

Fix an incorrect return value check of genlmsg_put() in irda_nl_get_mode(). genlmsg_put() does not use ERR_PTR() to encode return values, it just returns NULL on error.

---
 net/irda/irnetlink.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/irda/irnetlink.c +2 -2
index 9e1fb82..ea11cb4 100644
@@ -101,8 +101,8 @@ static int irda_nl_get_mode(struct sk_buff *skb, struct genl_info *info)
 
 	hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
 			  &irda_nl_family, 0,  IRDA_NL_CMD_GET_MODE);
-	if (IS_ERR(hdr)) {
-		ret = PTR_ERR(hdr);
+	if (hdr == NULL) {
+		ret = -EMSGSIZE;
 		goto err_out;
 	}
 
Signature · 1 line
1.5.3.6
maintainer
#7 lore raw

From: Julius Volz <[email protected]>
Date: Tue, 24 Jun 2008 11:29:14 +0200

Quoted 5 lines

Fix an incorrect return value check of genlmsg_put() in irda_nl_get_mode(). genlmsg_put() does not use ERR_PTR() to encode return values, it just returns NULL on error.

I'm assuming Samuel will grab this and send it to me in his next IRDA merge to me.

#8 lore raw

On Fri, 27 Jun 2008 20:01:33 -0700 (PDT), David Miller

Quoted 16 lines · <[email protected]> wrote:

From: Julius Volz <[email protected]>

Date: Tue, 24 Jun 2008 11:29:14 +0200

Quoted 1 line

Fix an incorrect return value check of genlmsg_put() in

irda_nl_get_mode().

Quoted 5 lines

genlmsg_put() does not use ERR_PTR() to encode return values, it just

returns NULL on error.

Quoted 7 lines
Quoted 1 line

I'm assuming Samuel will grab this and send it to me in his

next IRDA merge to me.

That's right. This should happen this week.

Cheers,

Samuel.