Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751892AbcLCJ37 (ORCPT ); Sat, 3 Dec 2016 04:29:59 -0500 Received: from m50-135.163.com ([123.125.50.135]:53614 "EHLO m50-135.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751082AbcLCJ35 (ORCPT ); Sat, 3 Dec 2016 04:29:57 -0500 From: Pan Bian To: Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] misc: set error code when devm_kstrdup fails Date: Sat, 3 Dec 2016 17:29:28 +0800 Message-Id: <1480757368-3921-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: D9GowADn7eV4kEJY1dyAIA--.5109S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrZrWxXF48WF4UGryUZr18Zrb_yoWDWFbE9F 40vwn7Xwn5KF43Cw18Cr1SkrWSk3y5uFn3Cr1agasIvry7Cwsxu3y2qrs8ArZ8Wan7uas8 Kwn8XFWSkrnFvjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUev385UUUUU== X-Originating-IP: [222.131.246.88] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiVBo1clUL+mqCvgAAs7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1003 Lines: 32 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 --- drivers/misc/sram.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c index f84b53d..0ef7d65 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c @@ -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, -- 1.9.1