Patchwork [net-next] : net: remove ifalias on empty given alias

login
register
mail settings
Submitter Oliver Hartkopp
Date Sept. 23, 2008, 7:52 p.m.
Message ID <48D948E8.6090804@hartkopp.net>
Download mbox | patch
Permalink /patch/1164/
State Accepted
Delegated to: David Miller
Headers show

Comments

Oliver Hartkopp - Sept. 23, 2008, 7:52 p.m.
This patch removes the potentially allocated ifalias when the (new) 
given alias is empty.

E.g. when setting

echo "" > /sys/class/net/eth0/ifalias

Signed-off-by: Oliver Hartkopp <oliver@hartkopp.net>
---

Hello Stephen,

this patch allows to 'remove' or reset the ifalias by giving an empty alias.
The patch is tested.
Btw. ifalias is a nice idea also for CAN bus people to 'name' a given 
CAN bus.

Thanks & regards,
Oliver
stephen hemminger - Sept. 23, 2008, 8:14 p.m.
On Tue, 23 Sep 2008 21:52:08 +0200
Oliver Hartkopp <oliver@hartkopp.net> wrote:

> This patch removes the potentially allocated ifalias when the (new) 
> given alias is empty.
> 
> E.g. when setting
> 
> echo "" > /sys/class/net/eth0/ifalias
> 
> Signed-off-by: Oliver Hartkopp <oliver@hartkopp.net>
> ---
> 
> Hello Stephen,
> 
> this patch allows to 'remove' or reset the ifalias by giving an empty alias.
> The patch is tested.
> Btw. ifalias is a nice idea also for CAN bus people to 'name' a given 
> CAN bus.
> 
> Thanks & regards,
> Oliver
> 
> 

Acked-by: Stephen Hemminger <shemminger@vyatta.com>

Also, udev could put a default value in based on the slot information it has.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - Sept. 24, 2008, 4:23 a.m.
From: Stephen Hemminger <shemminger@vyatta.com>
Date: Tue, 23 Sep 2008 13:14:52 -0700

> On Tue, 23 Sep 2008 21:52:08 +0200
> Oliver Hartkopp <oliver@hartkopp.net> wrote:
> 
> > This patch removes the potentially allocated ifalias when the (new) 
> > given alias is empty.
> > 
> > E.g. when setting
> > 
> > echo "" > /sys/class/net/eth0/ifalias
> > 
> > Signed-off-by: Oliver Hartkopp <oliver@hartkopp.net>
> > ---
> > 
> > Hello Stephen,
> > 
> > this patch allows to 'remove' or reset the ifalias by giving an empty alias.
> > The patch is tested.
> > Btw. ifalias is a nice idea also for CAN bus people to 'name' a given 
> > CAN bus.
> > 
> > Thanks & regards,
> > Oliver
> > 
> > 
> 
> Acked-by: Stephen Hemminger <shemminger@vyatta.com>
> 
> Also, udev could put a default value in based on the slot information it has.

I've applied Oliver's patch.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index e913905..a90737f 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -967,6 +967,14 @@  int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
 	if (len >= IFALIASZ)
 		return -EINVAL;
 
+	if (!len) {
+		if (dev->ifalias) {
+			kfree(dev->ifalias);
+			dev->ifalias = NULL;
+		}
+		return 0;
+	}
+
 	dev->ifalias = krealloc(dev->ifalias, len+1, GFP_KERNEL);
 	if (!dev->ifalias)
 		return -ENOMEM;