Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751373AbcLDUdp (ORCPT ); Sun, 4 Dec 2016 15:33:45 -0500 Received: from smtprelay0065.hostedemail.com ([216.40.44.65]:33605 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750979AbcLDUdn (ORCPT ); Sun, 4 Dec 2016 15:33:43 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 50,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::,RULES_HIT:41:355:379:541:599:800:960:967:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2525:2560:2563:2682:2685:2693:2828:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3151:3352:3622:3865:3866:3867:3868:3871:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:5007:7576:8660:9025:10004:10400:10450:10455:10848:11026:11232:11658:11914:12043:12048:12296:12438:12555:12698:12737:12740:12760:13069:13148:13230:13311:13357:13439:14181:14659:14721:19904:19999:21063:21080:21451:30054:30070:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: wheel71_5a5be43879636 X-Filterd-Recvd-Size: 2389 Message-ID: <1480883619.4534.6.camel@perches.com> Subject: Re: [PATCH 1/1] mtd: ubi: fix improper return value From: Joe Perches To: Marek Vasut , Pan Bian , Artem Bityutskiy , Richard Weinberger , David Woodhouse , Brian Norris , Boris Brezillon , Cyrille Pitchen , linux-mtd@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Pan Bian Date: Sun, 04 Dec 2016 12:33:39 -0800 In-Reply-To: References: <1480831930-5449-1-git-send-email-bianpan201604@163.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.1-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1214 Lines: 32 On Sun, 2016-12-04 at 13:48 +0100, Marek Vasut wrote: > On 12/04/2016 07:12 AM, Pan Bian wrote: > > From: Pan Bian > > > > When __vmalloc() returns a NULL pointer, the region is not checked, and > > we cannot make sure that only 0xFF bytes are present at offset. Thus, > > returning 0 seems improper. > > > > Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189081 > > > > Signed-off-by: Pan Bian > > --- > > drivers/mtd/ubi/io.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c [] > > @@ -1413,7 +1413,7 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) > > buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL); > > if (!buf) { > > ubi_err(ubi, "cannot allocate memory to check for 0xFFs"); > > - return 0; > > + return -ENOMEM; > > I wonder if you shouldn't also nuke the ubi_err() , because when you run > out of memory, printk() will likely also fail. No, not really. printk doesn't allocate memory. But the ubi_err should be removed because all memory allocations that fail without a specific GFP_NOWARN flag already have a dump_stack() call.