stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Mike Looijmans <mike.looijmans@topic.nl>,
	Kalle Valo <kvalo@codeaurora.org>
Subject: [PATCH 4.1 08/78] rsi: Fix failure to load firmware after memory leak fix and fix the leak
Date: Fri, 11 Sep 2015 15:49:09 -0700	[thread overview]
Message-ID: <20150911224607.827573703@linuxfoundation.org> (raw)
In-Reply-To: <20150911224606.758437370@linuxfoundation.org>

4.1-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Mike Looijmans <mike.looijmans@topic.nl>

commit 5d5cd85ff441534a52f23f821d0a7c644d3b6cce upstream.

Fixes commit eae79b4f3e82 ("rsi: fix memory leak in rsi_load_ta_instructions()")
which stopped the driver from functioning.

Firmware data has been allocated using vmalloc(), resulting in memory
that cannot be used for DMA. Hence the firmware was first copied to a
buffer allocated with kmalloc() in the original code. This patch reverts
the commit and only calls "kfree()" to release the buffer after sending
the data. This fixes the memory leak without breaking the driver.

Add a comment to the kmemdup() calls to explain why this is done, and abort
if memory allocation fails.

Tested on a Topic Miami-Florida board which contains the rsi SDIO chip.

Also added the same kfree() call to the USB glue driver. This was not
tested on actual hardware though, as I only have the SDIO version.

Fixes: eae79b4f3e82 ("rsi: fix memory leak in rsi_load_ta_instructions()")
Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/net/wireless/rsi/rsi_91x_sdio_ops.c |    8 +++++++-
 drivers/net/wireless/rsi/rsi_91x_usb_ops.c  |    4 ++++
 2 files changed, 11 insertions(+), 1 deletion(-)

--- a/drivers/net/wireless/rsi/rsi_91x_sdio_ops.c
+++ b/drivers/net/wireless/rsi/rsi_91x_sdio_ops.c
@@ -172,6 +172,7 @@ static int rsi_load_ta_instructions(stru
 		(struct rsi_91x_sdiodev *)adapter->rsi_dev;
 	u32 len;
 	u32 num_blocks;
+	const u8 *fw;
 	const struct firmware *fw_entry = NULL;
 	u32 block_size = dev->tx_blk_size;
 	int status = 0;
@@ -200,6 +201,10 @@ static int rsi_load_ta_instructions(stru
 		return status;
 	}
 
+	/* Copy firmware into DMA-accessible memory */
+	fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
+	if (!fw)
+		return -ENOMEM;
 	len = fw_entry->size;
 
 	if (len % 4)
@@ -210,7 +215,8 @@ static int rsi_load_ta_instructions(stru
 	rsi_dbg(INIT_ZONE, "%s: Instruction size:%d\n", __func__, len);
 	rsi_dbg(INIT_ZONE, "%s: num blocks: %d\n", __func__, num_blocks);
 
-	status = rsi_copy_to_card(common, fw_entry->data, len, num_blocks);
+	status = rsi_copy_to_card(common, fw, len, num_blocks);
+	kfree(fw);
 	release_firmware(fw_entry);
 	return status;
 }
--- a/drivers/net/wireless/rsi/rsi_91x_usb_ops.c
+++ b/drivers/net/wireless/rsi/rsi_91x_usb_ops.c
@@ -146,7 +146,10 @@ static int rsi_load_ta_instructions(stru
 		return status;
 	}
 
+	/* Copy firmware into DMA-accessible memory */
 	fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
+	if (!fw)
+		return -ENOMEM;
 	len = fw_entry->size;
 
 	if (len % 4)
@@ -158,6 +161,7 @@ static int rsi_load_ta_instructions(stru
 	rsi_dbg(INIT_ZONE, "%s: num blocks: %d\n", __func__, num_blocks);
 
 	status = rsi_copy_to_card(common, fw, len, num_blocks);
+	kfree(fw);
 	release_firmware(fw_entry);
 	return status;
 }



  parent reply	other threads:[~2015-09-11 22:50 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-11 22:49 [PATCH 4.1 00/78] 4.1.6-stable review Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 01/78] ipc,sem: fix use after free on IPC_RMID after a task using same semaphore set exits Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 02/78] ipc/sem.c: update/correct memory barriers Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 03/78] mm/hwpoison: fix page refcount of unknown non LRU page Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 04/78] mm/hwpoison: fix fail isolate hugetlbfs page w/ refcount held Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 05/78] clk: pxa: pxa3xx: fix CKEN register access Greg Kroah-Hartman
2015-09-11 22:49 ` Greg Kroah-Hartman [this message]
2015-09-11 22:49 ` [PATCH 4.1 09/78] perf: Fix fasync handling on inherited events Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 10/78] perf: Fix running time accounting Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 11/78] perf: Fix double-free of the AUX buffer Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 12/78] perf: Fix PERF_EVENT_IOC_PERIOD migration race Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 13/78] iwlwifi: pcie: fix prepare card flow Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 14/78] rtlwifi: rtl8723be: Add module parameter for MSI interrupts Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 15/78] rtlwifi: Fix NULL dereference when PCI driver used as an AP Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 16/78] x86/xen: build "Xen PV" APIC driver for domU as well Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 17/78] xen/xenbus: Dont leak memory when unmapping the ring on HVM backend Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 18/78] dm thin metadata: delete btrees when releasing metadata snapshot Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 19/78] localmodconfig: Use Kbuild files too Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 20/78] EDAC, ppc4xx: Access mci->csrows array elements properly Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 21/78] HID: hid-input: Fix accessing freed memory during device disconnect Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 22/78] HID: uclogic: fix limit in uclogic_tablet_enable() Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 23/78] drm/radeon: add new OLAND pci id Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 24/78] drm/vmwgfx: Fix execbuf locking issues Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 25/78] libfc: Fix fc_exch_recv_req() error path Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 26/78] libfc: Fix fc_fcp_cleanup_each_cmd() Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 27/78] ARM: imx6: correct i.MX6 PCIe interrupt routing Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 28/78] ARM: dts: omap243x: Fix broken pbias device creation Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 29/78] ARM: dts: dra7: " Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 30/78] ARM: dts: OMAP4: " Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 31/78] ARM: dts: OMAP5: " Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 32/78] ARM: 8385/1: VDSO: group link options Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 33/78] ARM: 8384/1: VDSO: force use of BFD linker Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 34/78] ARM: v7 setup function should invalidate L1 cache Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 35/78] ARM: invalidate L1 before enabling coherency Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 36/78] mfd: arizona: Fix initialisation of the PM runtime Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 37/78] Revert x86 sigcontext cleanups Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 38/78] regmap: regcache-rbtree: Clean new present bits on present bitmap resize Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 39/78] MIPS: Fix seccomp syscall argument for MIPS64 Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 40/78] libiscsi: Fix host busy blocking during connection teardown Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 41/78] sd: Fix maximum I/O size for BLOCK_PC requests Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 42/78] crypto: nx - respect sg limit bounds when building sg lists for SHA Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 43/78] crypto: caam - fix memory corruption in ahash_final_ctx Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 44/78] Revert "libata-eh: Set information field for autosense" Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 45/78] Revert "libata: Implement support for sense data reporting" Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 46/78] Revert "libata: Implement NCQ autosense" Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 48/78] ALSA: usb-audio: Fix runtime PM unbalance Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 49/78] ALSA: hda - Fix the white noise on Dell laptop Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 50/78] ALSA: usb: Add native DSD support for Gustard DAC-X20U Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 51/78] ALSA: hda - Shutdown CX20722 on reboot/free to avoid spurious noises Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 52/78] ALSA: hda - Check all inputs for is_active_nid_for_any() Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 53/78] ALSA: hda - Fix path power activation Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 54/78] ALSA: hda: fix possible NULL dereference Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 55/78] mac80211: fix invalid read in minstrel_sort_best_tp_rates() Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 56/78] target/iscsi: Fix double free of a TUR followed by a solicited NOPOUT Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 57/78] PCI: Dont use 64-bit bus addresses on PA-RISC Greg Kroah-Hartman
2015-09-11 22:49 ` [PATCH 4.1 58/78] Input: gpio_keys_polled - request GPIO pin as input Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 59/78] drm/atmel-hlcdc: Compile suspend/resume for PM_SLEEP only Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 60/78] drm/i915: Flag the execlists context object as dirty after every use Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 63/78] 9p: ensure err is initialized to 0 in p9_client_read/write Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 64/78] irqchip/crossbar: Restore the irq_set_type() mechanism Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 65/78] irqchip/crossbar: Restore the mask on suspend behaviour Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 66/78] irqchip/crossbar: Restore set_wake functionality Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 67/78] ARM: OMAP: wakeupgen: Restore the irq_set_type() mechanism Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 68/78] genirq: Dont return ENOSYS in irq_chip_retrigger_hierarchy Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 69/78] genirq: Introduce irq_chip_set_type_parent() helper Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 71/78] can: pcan_usb: dont provide CAN FD bittimings by non-FD adapters Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 72/78] Add factory recertified Crucial M500s to blacklist Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 73/78] fnic: Use the local variable instead of I/O flag to acquire io_req_lock in fnic_queuecommand() to avoid deadloack Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 74/78] arm64: KVM: Fix host crash when injecting a fault into a 32bit guest Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 75/78] arm64: perf: fix unassigned cpu_pmu->plat_device when probing PMU PPIs Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 76/78] x86/xen: make CONFIG_XEN depend on CONFIG_X86_LOCAL_APIC Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 77/78] x86/apic: Fix fallout from x2apic cleanup Greg Kroah-Hartman
2015-09-11 22:50 ` [PATCH 4.1 78/78] x86/idle: Restore trace_cpu_idle to mwait_idle() calls Greg Kroah-Hartman
2015-09-11 23:15 ` [PATCH 4.1 00/78] 4.1.6-stable review Christoph Biedl
2015-09-12  0:59   ` Greg KH
2015-09-11 23:16 ` Holger Hoffstätte
2015-09-12  0:59   ` Greg KH
2015-09-12  0:16 ` Shuah Khan
2015-09-12  1:00   ` Greg Kroah-Hartman
2015-09-12  1:00 ` [PATCH 4.1 00/78] 4.1.7-stable review Greg Kroah-Hartman
2015-09-12  2:10   ` Shuah Khan
2015-09-12  4:39     ` Greg Kroah-Hartman
2015-09-12  4:25   ` Guenter Roeck
2015-09-12  4:39     ` Greg Kroah-Hartman
2015-09-12  8:53   ` Sudip Mukherjee
2015-09-12 15:55     ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150911224607.827573703@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mike.looijmans@topic.nl \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).