From mboxrd@z Thu Jan 1 00:00:00 1970 From: Al Viro Subject: Re: [PATCH] vfio-pci: Use fdget() rather than eventfd_fget() Date: Tue, 20 Aug 2013 22:18:14 +0100 Message-ID: <20130820211814.GM27005@ZenIV.linux.org.uk> References: <20130820191712.9006.4890.stgit@bling.home> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org To: Alex Williamson Return-path: Content-Disposition: inline In-Reply-To: <20130820191712.9006.4890.stgit@bling.home> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Tue, Aug 20, 2013 at 01:18:07PM -0600, Alex Williamson wrote: > eventfd_fget() tests to see whether the file is an eventfd file, which > we then immediately pass to eventfd_ctx_fileget(), which again tests > whether the file is an eventfd file. Simplify slightly by using > fdget() so that we only test that we're looking at an eventfd once. > fget() could also be used, but fdget() makes use of fget_light() for > another slight optimization. Umm... > @@ -210,8 +210,8 @@ fail: > if (ctx && !IS_ERR(ctx)) > eventfd_ctx_put(ctx); > > - if (file && !IS_ERR(file)) > - fput(file); > + if (irqfd.file) > + fdput(irqfd); > > kfree(virqfd); IMO it's a bad style; you have three failure exits leading here, and those ifs are nothing but "how far did we get before we'd failed". fail3: eventfd_ctx_put(ctx); fail2: fdput(irqfd); fail1: kfree(virqfd); is much easier to analyse. It's a very common pattern and IME it's more robust than this kind of "flexibility"...