net: remove ifalias on empty given alias
authorOliver Hartkopp <oliver@hartkopp.net>
Wed, 24 Sep 2008 04:23:19 +0000 (21:23 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 24 Sep 2008 04:23:19 +0000 (21:23 -0700)
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>
Acked-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/dev.c

index e91390533999fe35e2609efbaf07e10c24426d59..a90737fe24726222ecffba1f63682337c89bf1bb 100644 (file)
@@ -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;