Skip to content

Commit

Permalink
can: softing: Fix potential memory leak in softing_load_fw()
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Alexey Khoroshilov authored and Marc Kleine-Budde committed Aug 24, 2012
1 parent a0dfb26 commit ef813c4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/net/can/softing/softing_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ef813c4

Please sign in to comment.