Skip to content

Commit

Permalink
misc: set error code when devm_kstrdup fails
Browse files Browse the repository at this point in the history
In function sram_reserve_regions(), the value of return variable ret
should be negative on failures. However, the value of ret may be 0 even
if the call to devm_kstrdup() returns a NULL pointer. This patch
explicitly assigns "-ENOMEM" to ret on the path that devm_kstrdup()
fails.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188651

Signed-off-by: Pan Bian <bianpan2016@163.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Pan Bian authored and Greg Kroah-Hartman committed Jan 10, 2017
1 parent d77044d commit ddc5c9a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/misc/sram.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,10 @@ static int sram_reserve_regions(struct sram_dev *sram, struct resource *res)

block->label = devm_kstrdup(sram->dev,
label, GFP_KERNEL);
if (!block->label)
if (!block->label) {
ret = -ENOMEM;
goto err_chunks;
}

dev_dbg(sram->dev, "found %sblock '%s' 0x%x-0x%x\n",
block->export ? "exported " : "", block->label,
Expand Down

0 comments on commit ddc5c9a

Please sign in to comment.