Skip to content

Commit

Permalink
i2s: fix slab leak in i2s_buf_write()
Browse files Browse the repository at this point in the history
A failed return value from i2s_write() requires that the
slab we allocated earlier be freed.

Signed-off-by: Andrew Boie <[email protected]>
  • Loading branch information
Andrew Boie authored and nashif committed Nov 16, 2018
1 parent eae05d9 commit d5f464c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion drivers/i2s/i2s_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ int _impl_i2s_buf_write(struct device *dev, void *buf, size_t size)

memcpy(mem_block, (void *)buf, size);

return i2s_write((struct device *)dev, mem_block, size);
ret = i2s_write((struct device *)dev, mem_block, size);
if (ret != 0) {
k_mem_slab_free(tx_cfg->mem_slab, &mem_block);
}

return ret;
}
7 changes: 6 additions & 1 deletion drivers/i2s/i2s_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ Z_SYSCALL_HANDLER(i2s_buf_write, dev, buf, size)
Z_OOPS(ret);
}

return i2s_write((struct device *)dev, mem_block, size);
ret = i2s_write((struct device *)dev, mem_block, size);
if (ret != 0) {
k_mem_slab_free(tx_cfg->mem_slab, &mem_block);
}

return ret;
}

Z_SYSCALL_HANDLER(i2s_trigger, dev, dir, cmd)
Expand Down

0 comments on commit d5f464c

Please sign in to comment.