Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751618AbcLEDVo (ORCPT ); Sun, 4 Dec 2016 22:21:44 -0500 Received: from m12-17.163.com ([220.181.12.17]:57889 "EHLO m12-17.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751244AbcLEDVj (ORCPT ); Sun, 4 Dec 2016 22:21:39 -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 1/2 v2] mtd: ubi: fix improper return value Date: Mon, 5 Dec 2016 11:19:18 +0800 Message-Id: <1480907958-19229-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: EcCowABXPQK33ERYNxTpDw--.62053S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7JF1fJFW3Ar4fAFWUtr4ktFb_yoWfZrbE93 4fXrsayr4qgr43Kw1IkrW8Wry29w4Y9rn7CFySqwnxZFsxGFWjqFyvgr9xJF4Uuw4IyF1D Z3yqvryxCr17JjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUYj4EtUUUUU== X-Originating-IP: [106.120.213.17] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiQBk3clSIRStd9QAAsG Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 907 Lines: 30 When __vmalloc() returns a NULL pointer, the region is not really checked, and we cannot conclude that only 0xFF bytes are present at offset. Thus, returing 0 seems improper. This patches 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 b6fb8f9..00d7f44 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c @@ -1411,10 +1411,8 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) return 0; buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL); - if (!buf) { - ubi_err(ubi, "cannot allocate memory to check for 0xFFs"); - return 0; - } + if (!buf) + return -ENOMEM; err = mtd_read(ubi->mtd, addr, len, &read, buf); if (err && !mtd_is_bitflip(err)) { -- 1.9.1