Revert "usbtmc: convert to devm_kzalloc"
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Sep 2016 09:48:44 +0000 (11:48 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Oct 2016 13:23:47 +0000 (15:23 +0200)
commit ab21b63e8aedfc73565dd9cdd51eb338341177cb upstream.

This reverts commit e6c7efdcb76f11b04e3d3f71c8d764ab75c9423b.

Turns out it was totally wrong.  The memory is supposed to be bound to
the kref, as the original code was doing correctly, not the
device/driver binding as the devm_kzalloc() would cause.

This fixes an oops when read would be called after the device was
unbound from the driver.

Reported-by: Ladislav Michl <ladis@linux-mips.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/class/usbtmc.c

index 7a11a8263171caad8ccba867bfa4e2e9734c2c3f..deaddb950c20d6cffbfff91754f30485e4a52c4f 100644 (file)
@@ -121,6 +121,7 @@ static void usbtmc_delete(struct kref *kref)
        struct usbtmc_device_data *data = to_usbtmc_data(kref);
 
        usb_put_dev(data->usb_dev);
+       kfree(data);
 }
 
 static int usbtmc_open(struct inode *inode, struct file *filp)
@@ -1104,7 +1105,7 @@ static int usbtmc_probe(struct usb_interface *intf,
 
        dev_dbg(&intf->dev, "%s called\n", __func__);
 
-       data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL);
+       data = kmalloc(sizeof(*data), GFP_KERNEL);
        if (!data)
                return -ENOMEM;