Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754530Ab0AHAzq (ORCPT ); Thu, 7 Jan 2010 19:55:46 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754513Ab0AHAzq (ORCPT ); Thu, 7 Jan 2010 19:55:46 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:63015 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1754506Ab0AHAzp (ORCPT ); Thu, 7 Jan 2010 19:55:45 -0500 Message-ID: <4B46828C.5000703@cn.fujitsu.com> Date: Fri, 08 Jan 2010 08:55:40 +0800 From: Li Zefan User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Thunderbird/3.0b2 MIME-Version: 1.0 To: "Kirill A. Shutemov" CC: Paul Menage , containers@lists.linux-foundation.org, linux-mm@kvack.org, Andrew Morton , KAMEZAWA Hiroyuki , Balbir Singh , Pavel Emelyanov , Dan Malek , Vladislav Buzov , Daisuke Nishimura , Alexander Shishkin , linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 1/4] cgroup: implement eventfd-based generic API for notifications References: <9411cbdd545e1232c916bfef03a60cf95510016d.1262186098.git.kirill@shutemov.name> <6599ad831001061701x72098dacn7a5d916418396e33@mail.gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1348 Lines: 47 Kirill A. Shutemov wrote: > On Thu, Jan 7, 2010 at 3:01 AM, Paul Menage wrote: >> On Wed, Dec 30, 2009 at 7:57 AM, Kirill A. Shutemov >> wrote: >>> + >>> + if (!IS_ERR(efile)) >>> + fput(efile); >> While this is OK currently, it's a bit fragile. efile starts as NULL, >> and IS_ERR(NULL) is false. So if we jump to fail: before trying to do >> the eventfd_fget() then we'll try to fput(NULL), which will oops. This >> works because we don't currently jump to fail: until after >> eventfd_fget(), but someone could add an extra setup step between the >> kzalloc() and the eventfd_fget() which could fail. > > So we need to use IS_ERR_OR_NULL here instread of IS_ERR, don't we? > Use multi labels is much better: label4:: fput(cfile); label3: eventfd_ctx_put(event->eventfd); label2: fput(efile); label1: kfree(event); compared to: +fail: + if (!IS_ERR(cfile)) + fput(cfile); + + if (event && event->eventfd && !IS_ERR(event->eventfd)) + eventfd_ctx_put(event->eventfd); + + if (!IS_ERR(efile)) + fput(efile); + + kfree(event); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/