]> git.baikalelectronics.ru Git - kernel.git/commit
ser_gigaset: use container_of() instead of detour
authorPaul Bolle <pebolle@tiscali.nl>
Thu, 18 Feb 2016 20:29:08 +0000 (21:29 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 19 Feb 2016 20:52:41 +0000 (15:52 -0500)
commit16ea6935c0852b9baa9cfcd754861f69eb47cde6
treee72809a721c5fb5ba5e0e90ee0a9d54175aeec1e
parent40ba398a6f38c8921751def7a09500577db3ef1d
ser_gigaset: use container_of() instead of detour

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 0cf72c42601b
("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 d6a0a1246999 ("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 <dvyukov@google.com>
Tested-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
Acked-by: Tilman Schmidt <tilman@imap.cc>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/isdn/gigaset/ser-gigaset.c