From patchwork Tue Jan 20 11:35:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 431028 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6C0D91402DF for ; Tue, 20 Jan 2015 22:36:01 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id 437E91A10C1 for ; Tue, 20 Jan 2015 22:36:01 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from pokefinder.org (sauhun.de [89.238.76.85]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 1444F1A0427 for ; Tue, 20 Jan 2015 22:35:20 +1100 (AEDT) Received: from p4fe24acf.dip0.t-ipconnect.de ([79.226.74.207]:52219 helo=localhost) by pokefinder.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1YDX5R-00083n-Ot; Tue, 20 Jan 2015 12:35:10 +0100 Date: Tue, 20 Jan 2015 12:35:08 +0100 From: Wolfram Sang To: Russell King - ARM Linux Subject: Re: [PATCH] i2c: drop ancient protection against sysfs refcounting issues Message-ID: <20150120113508.GA1067@katana> References: <1421693756-12917-1-git-send-email-wsa@the-dreams.de> <20150119190142.GA9451@kroah.com> <20150119230427.GH26493@n2100.arm.linux.org.uk> <20150120014159.GA3349@kroah.com> <54BDFE30.5090303@metafoo.de> <20150120071256.GA18983@kroah.com> <20150120101752.GI26493@n2100.arm.linux.org.uk> MIME-Version: 1.0 In-Reply-To: <20150120101752.GI26493@n2100.arm.linux.org.uk> User-Agent: Mutt/1.5.23 (2014-03-12) Cc: linux-mips@linux-mips.org, Lars-Peter Clausen , Greg Kroah-Hartman , Pantelis Antoniou , linux-kernel@vger.kernel.org, Julia Lawall , Jean Delvare , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" > > Right, and I'm not saying it should be, just move the existing logic > > into the release callback, and the code flow should be the same and we > > don't end up with an "empty" release callback. But as Russell says, even if we don't have the empty callback, we still create the problem shown by DEBUG_KOBJECT_RELEASE which wasn't there before? > IMHO there are two possibilities here: > > 1. leave it as-is, where we ensure that the remainder of i2c_del_adapter > does not complete until the release callback has been called. > > 2. fix it properly by taking (eg) the netdev approach to i2c_adapter, > or an alternative solution which results in decoupling the lifetime > of the struct device from the i2c_adapter. > > Either of these would be much better than removing the completion and > then moving a chunk of code to make it "look" safer than it actually is > and thereby introducing potential use-after-free bugs. I agree. As much as I'd love option 2) I don't see that on the horizon. So, let's keep things as they are. What probably makes sense is to update the comment with something like this? I took the liberty and used some wording from Russell: Thanks for all the input, it is very much appreciated! diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index e227dff62a85..1c89a08fae2a 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1778,11 +1778,14 @@ void i2c_del_adapter(struct i2c_adapter *adap) /* device name is gone after device_unregister */ dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); - /* clean up the sysfs representation */ + /* wait until all references to the device are gone + * + * FIXME: This is old code and should ideally be replaced by an + * alternative which results in decoupling the lifetime of the struct + * device from the i2c_adapter, like spi or netdev do. + */ init_completion(&adap->dev_released); device_unregister(&adap->dev); - - /* wait for sysfs to drop all references */ wait_for_completion(&adap->dev_released); /* free bus id */