Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HID: intel_ish-hid: tx_buf memory leak on probe/remove

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>

authored by

Anton Vasilyev and committed by
Jiri Kosina
50fa9259 a1e9a9c0

+6 -5
+6 -3
drivers/hid/intel-ish-hid/ipc/ipc.c
··· 907 907 struct ishtp_device *dev; 908 908 int i; 909 909 910 - dev = kzalloc(sizeof(struct ishtp_device) + sizeof(struct ish_hw), 911 - GFP_KERNEL); 910 + dev = devm_kzalloc(&pdev->dev, 911 + sizeof(struct ishtp_device) + sizeof(struct ish_hw), 912 + GFP_KERNEL); 912 913 if (!dev) 913 914 return NULL; 914 915 ··· 926 925 for (i = 0; i < IPC_TX_FIFO_SIZE; ++i) { 927 926 struct wr_msg_ctl_info *tx_buf; 928 927 929 - tx_buf = kzalloc(sizeof(struct wr_msg_ctl_info), GFP_KERNEL); 928 + tx_buf = devm_kzalloc(&pdev->dev, 929 + sizeof(struct wr_msg_ctl_info), 930 + GFP_KERNEL); 930 931 if (!tx_buf) { 931 932 /* 932 933 * IPC buffers may be limited or not available
-2
drivers/hid/intel-ish-hid/ipc/pci-ish.c
··· 183 183 free_irq(pdev->irq, dev); 184 184 free_device: 185 185 pci_iounmap(pdev, hw->mem_addr); 186 - kfree(dev); 187 186 release_regions: 188 187 pci_release_regions(pdev); 189 188 disable_device: ··· 212 213 pci_release_regions(pdev); 213 214 pci_clear_master(pdev); 214 215 pci_disable_device(pdev); 215 - kfree(ishtp_dev); 216 216 } 217 217 218 218 static struct device __maybe_unused *ish_resume_device;