linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can/softing: Fix potential memory leak in softing_load_fw()
@ 2012-08-08 15:15 Alexey Khoroshilov
  2012-08-08 17:18 ` Marc Kleine-Budde
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Khoroshilov @ 2012-08-08 15:15 UTC (permalink / raw)
  To: Kurt Van Dijck
  Cc: Alexey Khoroshilov, Wolfgang Grandegger, Marc Kleine-Budde,
	linux-can, netdev, linux-kernel, ldv-project

Do not leak memory by updating pointer with potentially NULL realloc return value.

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

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 drivers/net/can/softing/softing_fw.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/softing/softing_fw.c b/drivers/net/can/softing/softing_fw.c
index 3105961..b595d34 100644
--- a/drivers/net/can/softing/softing_fw.c
+++ b/drivers/net/can/softing/softing_fw.c
@@ -150,7 +150,7 @@ int softing_load_fw(const char *file, struct softing *card,
 	const uint8_t *mem, *end, *dat;
 	uint16_t type, len;
 	uint32_t addr;
-	uint8_t *buf = NULL;
+	uint8_t *buf = NULL, *new_buf;
 	int buflen = 0;
 	int8_t type_end = 0;
 
@@ -199,11 +199,12 @@ int softing_load_fw(const char *file, struct softing *card,
 		if (len > buflen) {
 			/* align buflen */
 			buflen = (len + (1024-1)) & ~(1024-1);
-			buf = krealloc(buf, buflen, GFP_KERNEL);
-			if (!buf) {
+			new_buf = krealloc(buf, buflen, GFP_KERNEL);
+			if (!new_buf) {
 				ret = -ENOMEM;
 				goto failed;
 			}
+			buf = new_buf;
 		}
 		/* verify record data */
 		memcpy_fromio(buf, &dpram[addr + offset], len);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] can/softing: Fix potential memory leak in softing_load_fw()
  2012-08-08 15:15 [PATCH] can/softing: Fix potential memory leak in softing_load_fw() Alexey Khoroshilov
@ 2012-08-08 17:18 ` Marc Kleine-Budde
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Kleine-Budde @ 2012-08-08 17:18 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Kurt Van Dijck, Wolfgang Grandegger, linux-can, netdev,
	linux-kernel, ldv-project

[-- Attachment #1: Type: text/plain, Size: 603 bytes --]

On 08/08/2012 05:15 PM, Alexey Khoroshilov wrote:
> Do not leak memory by updating pointer with potentially NULL realloc return value.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>

Thanks for the work,
applied to can/master.

Marc
-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-08 17:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-08 15:15 [PATCH] can/softing: Fix potential memory leak in softing_load_fw() Alexey Khoroshilov
2012-08-08 17:18 ` Marc Kleine-Budde

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).