Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1338458

Re: [PATCH 1/1] ser_gigaset: use container_of() instead of detour

From David Miller <davem@davemloft.net>
Newsgroups linux.kernel
Subject Re: [PATCH 1/1] ser_gigaset: use container_of() instead of detour
Date 2016-02-19 22:00 +0100
Message-ID <r40jE-2yF-11@gated-at.bofh.it> (permalink)
References <r3Dn5-2Bf-41@gated-at.bofh.it> <r3Dn5-2Bf-39@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Paul Bolle <pebolle@tiscali.nl>
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 <dvyukov@google.com>
> Tested-by: Dmitry Vyukov <dvyukov@google.com>
> Signed-off-by: Paul Bolle <pebolle@tiscali.nl>

Applied, thanks.

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH 1/1] ser_gigaset: use container_of() instead of detour Paul Bolle <pebolle@tiscali.nl> - 2016-02-18 21:30 +0100
  Re: [PATCH 1/1] ser_gigaset: use container_of() instead of detour Tilman Schmidt <tilman@imap.cc> - 2016-02-18 22:50 +0100
    Re: [PATCH 1/1] ser_gigaset: use container_of() instead of detour Paul Bolle <pebolle@tiscali.nl> - 2016-02-18 23:20 +0100
  Re: [PATCH 1/1] ser_gigaset: use container_of() instead of detour Greg KH <gregkh@linuxfoundation.org> - 2016-02-19 00:50 +0100
    Re: [PATCH 1/1] ser_gigaset: use container_of() instead of detour Paul Bolle <pebolle@tiscali.nl> - 2016-02-19 01:00 +0100
  Re: [PATCH 1/1] ser_gigaset: use container_of() instead of detour David Miller <davem@davemloft.net> - 2016-02-19 22:00 +0100

csiph-web