From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2993745AbcBSU4H (ORCPT ); Fri, 19 Feb 2016 15:56:07 -0500 Received: from shards.monkeyblade.net ([149.20.54.216]:38387 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423122AbcBSU4E (ORCPT ); Fri, 19 Feb 2016 15:56:04 -0500 Date: Fri, 19 Feb 2016 15:56:01 -0500 (EST) Message-Id: <20160219.155601.1374391949104594889.davem@davemloft.net> To: pebolle@tiscali.nl Cc: netdev@vger.kernel.org, dvyukov@google.com, u.kleine-koenig@pengutronix.de, gregkh@linuxfoundation.org, Martin.Wilck@ts.fujitsu.com, jarkko.sakkinen@linux.intel.com, tilman@imap.cc, linux-kernel@vger.kernel.org, gigaset307x-common@lists.sourceforge.net Subject: Re: [PATCH 1/1] ser_gigaset: use container_of() instead of detour From: David Miller In-Reply-To: <1455827348-8574-2-git-send-email-pebolle@tiscali.nl> References: <1455827348-8574-1-git-send-email-pebolle@tiscali.nl> <1455827348-8574-2-git-send-email-pebolle@tiscali.nl> X-Mailer: Mew version 6.6 on Emacs 24.5 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Fri, 19 Feb 2016 12:56:03 -0800 (PST) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paul Bolle Date: Thu, 18 Feb 2016 21:29:08 +0100 > The purpose of gigaset_device_release() is to kfree() the struct > ser_cardstate that contains our struct device. This is done via a bit of > a detour. First we make our struct device's driver_data point to the > container of our struct ser_cardstate (which is a struct cardstate). In > gigaset_device_release() we then retrieve that driver_data again. And > after that we finally kfree() the struct ser_cardstate that was saved in > the struct cardstate. > > All of this can be achieved much easier by using container_of() to get > from our struct device to its container, struct ser_cardstate. Do so. > > Note that at the time the detour was implemented commit b8b2c7d845d5 > ("base/platform: assert that dev_pm_domain callbacks are called > unconditionally") had just entered the tree. That commit disconnected > our platform_device and our platform_driver. These were reconnected > again in v4.5-rc2 through commit 25cad69f21f5 ("base/platform: Fix > platform drivers with no probe callback"). And one of the consequences > of that fix was that it broke the detour via driver_data. That's because > it made __device_release_driver() stop being a NOP for our struct device > and actually do stuff again. One of the things it now does, is setting > our driver_data to NULL. That, in turn, makes it impossible for > gigaset_device_release() to get to our struct cardstate. Which has the > net effect of leaking a struct ser_cardstate at every call of this > driver's tty close() operation. So using container_of() has the > additional benefit of actually working. > > Reported-by: Dmitry Vyukov > Tested-by: Dmitry Vyukov > Signed-off-by: Paul Bolle Applied, thanks.