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: 5668331 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A4F98C058D for ; Tue, 20 Jan 2015 11:37:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D03320396 for ; Tue, 20 Jan 2015 11:37:52 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A3A592025A for ; Tue, 20 Jan 2015 11:37:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YDX60-0001KH-DD; Tue, 20 Jan 2015 11:35:44 +0000 Received: from sauhun.de ([89.238.76.85] helo=pokefinder.org) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YDX5w-0001Gp-1H for linux-arm-kernel@lists.infradead.org; Tue, 20 Jan 2015 11:35:40 +0000 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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150120_033540_262125_D2986932 X-CRM114-Status: GOOD ( 19.62 ) X-Spam-Score: -0.0 (/) 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: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP > > 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 */