2016-12-03 11:34:12

by Pan Bian

[permalink] [raw]
Subject: [PATCH 1/1] net: bridge: set error code on failure

Function br_sysfs_addbr() does not set error code when the call
kobject_create_and_add() returns a NULL pointer. It may be better to
return "-ENOMEM" when kobject_create_and_add() fails.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188781

Signed-off-by: Pan Bian <[email protected]>
---
net/bridge/br_sysfs_br.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
index e120307..f88c4df 100644
--- a/net/bridge/br_sysfs_br.c
+++ b/net/bridge/br_sysfs_br.c
@@ -898,6 +898,7 @@ int br_sysfs_addbr(struct net_device *dev)
if (!br->ifobj) {
pr_info("%s: can't add kobject (directory) %s/%s\n",
__func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
+ err = -ENOMEM;
goto out3;
}
return 0;
--
1.9.1



2016-12-05 16:37:25

by Stephen Hemminger

[permalink] [raw]
Subject: Re: [PATCH 1/1] net: bridge: set error code on failure

On Sat, 3 Dec 2016 19:33:23 +0800
Pan Bian <[email protected]> wrote:

> Function br_sysfs_addbr() does not set error code when the call
> kobject_create_and_add() returns a NULL pointer. It may be better to
> return "-ENOMEM" when kobject_create_and_add() fails.
>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188781
>
> Signed-off-by: Pan Bian <[email protected]>
> ---
> net/bridge/br_sysfs_br.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
> index e120307..f88c4df 100644
> --- a/net/bridge/br_sysfs_br.c
> +++ b/net/bridge/br_sysfs_br.c
> @@ -898,6 +898,7 @@ int br_sysfs_addbr(struct net_device *dev)
> if (!br->ifobj) {
> pr_info("%s: can't add kobject (directory) %s/%s\n",
> __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
> + err = -ENOMEM;
> goto out3;
> }
> return 0;

Makes sense. Although such a small allocation should never fail.

Acked-by: Stephen Hemminger <[email protected]>

2016-12-05 18:28:05

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 1/1] net: bridge: set error code on failure

From: Pan Bian <[email protected]>
Date: Sat, 3 Dec 2016 19:33:23 +0800

> Function br_sysfs_addbr() does not set error code when the call
> kobject_create_and_add() returns a NULL pointer. It may be better to
> return "-ENOMEM" when kobject_create_and_add() fails.
>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188781
>
> Signed-off-by: Pan Bian <[email protected]>

Applied.