Skip to contentSkip to conversation

misc: set error code when devm_kstrdup fails

PATCH New Pan Bian 1 participant 1 message Dec 3, 2016 Char and misc drivers

lore
Share & tools
lore

Pan Bian

author
#0 lore raw

PATCH 1/1 misc: set error code when devm_kstrdup fails

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

---
 drivers/misc/sram.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/misc/sram.c +3 -1
index f84b53d..0ef7d65 100644
@@ -244,8 +244,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,
Signature · 1 line
1.9.1