HID: intel_ish-hid: tx_buf memory leak on probe/remove
authorAnton Vasilyev <vasilyev@ispras.ru>
Wed, 1 Aug 2018 11:26:51 +0000 (14:26 +0300)
committerJiri Kosina <jkosina@suse.cz>
Thu, 2 Aug 2018 11:27:54 +0000 (13:27 +0200)
ish_dev_init() allocates 512*176 bytes memory for tx_buf and stores it at
&dev->wr_free_list_head.link list on ish_probe().
But there is no deallocation of this memory in ish_remove() and in
ish_probe() error path.
So current intel-ish-ipc provides 88 KB memory leak for each
probe/release.

The patch replaces kzalloc allocation by devm_kzalloc and removes
ishtp_device *dev deallocation by kfree.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/intel-ish-hid/ipc/ipc.c
drivers/hid/intel-ish-hid/ipc/pci-ish.c

index 9a60ec13cb10967a20aa560033a90ac4abe9d65c..bfbca7ec54ce4a9c97228368a8264c693d3e38da 100644 (file)
@@ -907,8 +907,9 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev)
        struct ishtp_device *dev;
        int     i;
 
-       dev = kzalloc(sizeof(struct ishtp_device) + sizeof(struct ish_hw),
-               GFP_KERNEL);
+       dev = devm_kzalloc(&pdev->dev,
+                          sizeof(struct ishtp_device) + sizeof(struct ish_hw),
+                          GFP_KERNEL);
        if (!dev)
                return NULL;
 
@@ -925,7 +926,9 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev)
        for (i = 0; i < IPC_TX_FIFO_SIZE; ++i) {
                struct wr_msg_ctl_info  *tx_buf;
 
-               tx_buf = kzalloc(sizeof(struct wr_msg_ctl_info), GFP_KERNEL);
+               tx_buf = devm_kzalloc(&pdev->dev,
+                                     sizeof(struct wr_msg_ctl_info),
+                                     GFP_KERNEL);
                if (!tx_buf) {
                        /*
                         * IPC buffers may be limited or not available
index 4a55eab39b88bd8902fee7edf69898220b1a0cb7..050f9872f5c0dc7d465c71f505dcb995b53c4321 100644 (file)
@@ -183,7 +183,6 @@ free_irq:
        free_irq(pdev->irq, dev);
 free_device:
        pci_iounmap(pdev, hw->mem_addr);
-       kfree(dev);
 release_regions:
        pci_release_regions(pdev);
 disable_device:
@@ -213,7 +212,6 @@ static void ish_remove(struct pci_dev *pdev)
        pci_release_regions(pdev);
        pci_clear_master(pdev);
        pci_disable_device(pdev);
-       kfree(ishtp_dev);
 }
 
 static struct device __maybe_unused *ish_resume_device;