mac80211: Fix memory leak in ieee80211_if_write()
authorEric Dumazet <eric.dumazet@gmail.com>
Wed, 10 Mar 2010 16:13:36 +0000 (17:13 +0100)
committerJohn W. Linville <linville@tuxdriver.com>
Wed, 10 Mar 2010 21:29:11 +0000 (16:29 -0500)
Fix memory leak and use kmalloc() instead of kzalloc() as we are going
to overwrite the allocated buffer.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
net/mac80211/debugfs_netdev.c

index 9affe2cd185f2ec3cae1b5a8e8ad3ce046db5746..b4ddb2f839146a2b48a62a5e3df2b9f6c44dc1df 100644 (file)
@@ -48,20 +48,24 @@ static ssize_t ieee80211_if_write(
        ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
 {
        u8 *buf;
-       ssize_t ret = -ENODEV;
+       ssize_t ret;
 
-       buf = kzalloc(count, GFP_KERNEL);
+       buf = kmalloc(count, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
 
+       ret = -EFAULT;
        if (copy_from_user(buf, userbuf, count))
-               return -EFAULT;
+               goto freebuf;
 
+       ret = -ENODEV;
        rtnl_lock();
        if (sdata->dev->reg_state == NETREG_REGISTERED)
                ret = (*write)(sdata, buf, count);
        rtnl_unlock();
 
+freebuf:
+       kfree(buf);
        return ret;
 }