Commit ef813c41 authored by Alexey Khoroshilov's avatar Alexey Khoroshilov Committed by Marc Kleine-Budde

can: softing: Fix potential memory leak in softing_load_fw()

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

Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: default avatarAlexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent a0dfb263
...@@ -150,7 +150,7 @@ int softing_load_fw(const char *file, struct softing *card, ...@@ -150,7 +150,7 @@ int softing_load_fw(const char *file, struct softing *card,
const uint8_t *mem, *end, *dat; const uint8_t *mem, *end, *dat;
uint16_t type, len; uint16_t type, len;
uint32_t addr; uint32_t addr;
uint8_t *buf = NULL; uint8_t *buf = NULL, *new_buf;
int buflen = 0; int buflen = 0;
int8_t type_end = 0; int8_t type_end = 0;
...@@ -199,11 +199,12 @@ int softing_load_fw(const char *file, struct softing *card, ...@@ -199,11 +199,12 @@ int softing_load_fw(const char *file, struct softing *card,
if (len > buflen) { if (len > buflen) {
/* align buflen */ /* align buflen */
buflen = (len + (1024-1)) & ~(1024-1); buflen = (len + (1024-1)) & ~(1024-1);
buf = krealloc(buf, buflen, GFP_KERNEL); new_buf = krealloc(buf, buflen, GFP_KERNEL);
if (!buf) { if (!new_buf) {
ret = -ENOMEM; ret = -ENOMEM;
goto failed; goto failed;
} }
buf = new_buf;
} }
/* verify record data */ /* verify record data */
memcpy_fromio(buf, &dpram[addr + offset], len); memcpy_fromio(buf, &dpram[addr + offset], len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment