Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751501AbcLEDVe (ORCPT ); Sun, 4 Dec 2016 22:21:34 -0500 Received: from m12-18.163.com ([220.181.12.18]:43803 "EHLO m12-18.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751223AbcLEDVd (ORCPT ); Sun, 4 Dec 2016 22:21:33 -0500 From: Pan Bian To: Artem Bityutskiy , Richard Weinberger , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Cyrille Pitchen , linux-mtd@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 2/2] mtd: ubi: fix improper return value Date: Mon, 5 Dec 2016 11:19:29 +0800 Message-Id: <1480907969-19960-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: EsCowACXx8vA3ERY_BF4Ew--.64502S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrtrWfWF45GrW5CFyxGr15Jwb_yoWfWwbE93 4fXrsavrnI9F43K3WIkry8Xry2va1Y9F18CF1SgwnxAF47Ca1vvFyktrZxZa1Uua1IkFyD Zr4qv34fCrnrKjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU5EXdUUUUUU== X-Originating-IP: [106.120.213.17] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBzwI3claDsdPfcwAAsT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 879 Lines: 30 When __vmalloc() returns a NULL pointer, the data is not really tested, and we cannot conclude that the data matches. Thus, returning 0 seems improper. This patch fixes it, returns "-ENOMEM" and removes the warning. Signed-off-by: Pan Bian --- drivers/mtd/ubi/io.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 00d7f44..6707277 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c @@ -1347,10 +1347,8 @@ static int self_check_write(struct ubi_device *ubi, const void *buf, int pnum, return 0; buf1 = __vmalloc(len, GFP_NOFS, PAGE_KERNEL); - if (!buf1) { - ubi_err(ubi, "cannot allocate memory to check writes"); - return 0; - } + if (!buf1) + return -ENOMEM; err = mtd_read(ubi->mtd, addr, len, &read, buf1); if (err && !mtd_is_bitflip(err)) -- 1.9.1