stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>,
	"open list:HID CORE LAYER" <linux-input@vger.kernel.org>,
	Jiri Kosina <jikos@kernel.org>,
	Henrik Rydberg <rydberg@bitmath.org>,
	Sam Bazely <sambazley@fastmail.com>,
	"Pierre-Loup A . Griffais" <pgriffais@valvesoftware.com>,
	Austin Palmer <austinp@valvesoftware.com>,
	lkml <linux-kernel@vger.kernel.org>,
	"3.8+" <stable@vger.kernel.org>
Subject: Re: [PATCH 1/3] HID: logitech-hidpp: use devres to manage FF private data
Date: Fri, 11 Oct 2019 21:25:52 +0200	[thread overview]
Message-ID: <CAO-hwJLH6SMkLb1kZGj1E+BUHJ+ZsE1n+d=xeJgsvTCjHH1Wzw@mail.gmail.com> (raw)
In-Reply-To: <20191011182617.GE229325@dtor-ws>

On Fri, Oct 11, 2019 at 8:26 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> On Fri, Oct 11, 2019 at 04:52:04PM +0200, Benjamin Tissoires wrote:
> > Hi Andrey,
> >
> > On Mon, Oct 7, 2019 at 7:13 AM Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
> > >
> > > To simplify resource management in commit that follows as well as to
> > > save a couple of extra kfree()s and simplify hidpp_ff_deinit() switch
> > > driver code to use devres to manage the life-cycle of FF private data.
> > >
> > > Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> > > Cc: Jiri Kosina <jikos@kernel.org>
> > > Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> > > Cc: Henrik Rydberg <rydberg@bitmath.org>
> > > Cc: Sam Bazely <sambazley@fastmail.com>
> > > Cc: Pierre-Loup A. Griffais <pgriffais@valvesoftware.com>
> > > Cc: Austin Palmer <austinp@valvesoftware.com>
> > > Cc: linux-input@vger.kernel.org
> > > Cc: linux-kernel@vger.kernel.org
> > > Cc: stable@vger.kernel.org
> >
> > This patch doesn't seem to fix any error, is there a reason to send it
> > to stable? (besides as a dependency of the rest of the series).
> >
> > > ---
> > >  drivers/hid/hid-logitech-hidpp.c | 53 +++++++++++++++++---------------
> > >  1 file changed, 29 insertions(+), 24 deletions(-)
> > >
> > > diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
> > > index 0179f7ed77e5..58eb928224e5 100644
> > > --- a/drivers/hid/hid-logitech-hidpp.c
> > > +++ b/drivers/hid/hid-logitech-hidpp.c
> > > @@ -2079,6 +2079,11 @@ static void hidpp_ff_destroy(struct ff_device *ff)
> > >         struct hidpp_ff_private_data *data = ff->private;
> > >
> > >         kfree(data->effect_ids);
> >
> > Is there any reasons we can not also devm alloc data->effect_ids?
> >
> > > +       /*
> > > +        * Set private to NULL to prevent input_ff_destroy() from
> > > +        * freeing our devres allocated memory
> >
> > Ouch. There is something wrong here: input_ff_destroy() calls
> > kfree(ff->private), when the data has not been allocated by
> > input_ff_create(). This seems to lack a little bit of symmetry.
>
> Yeah, ff and ff-memless essentially take over the private data assigned
> to them. They were done before devm and the lifetime of the "private"
> data pieces was tied to the lifetime of the input device to simplify
> error handling and teardown.

Yeah, that stealing of the pointer is not good :)
But OTOH, it helps

>
> Maybe we should clean it up a bit... I'm open to suggestions.

The problem I had when doing the review was that there is no easy way
to have a "devm_input_ff_create_()", because the way it's built is
already "devres-compatible": the destroy gets called by input core.

So I don't have a good answer to simplify in a transparent manner
without breaking the API.

>
> In this case maybe best way is to get rid of hidpp_ff_destroy() and not
> set ff->private and rely on devm to free the buffers. One can get to
> device private data from ff methods via input_get_drvdata() since they
> all (except destroy) are passed input device pointer.

Sounds like a good idea. However, it seems there might be a race when
removing the workqueue:
the workqueue gets deleted in hidpp_remove, when the input node will
be freed by devres, so after the call of hidpp_remove.

So we should probably keep hidpp_ff_destroy() to clean up the ff bits,
and instead move the content of hidpp_ff_deinit() into
hidpp_ff_destroy() so we ensure proper ordering.

Andrey, note that ensuring the workqueue gets freed after the call of
input_destroy_device is something that should definitively go into
stable as this is a potential race problem.

Cheers,
Benjamin


  reply	other threads:[~2019-10-11 19:26 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-07  5:12 [PATCH 0/3] Logitech G920 fixes Andrey Smirnov
2019-10-07  5:12 ` [PATCH 1/3] HID: logitech-hidpp: use devres to manage FF private data Andrey Smirnov
2019-10-11 14:52   ` Benjamin Tissoires
2019-10-11 18:18     ` Andrey Smirnov
2019-10-11 19:16       ` Benjamin Tissoires
2019-10-11 18:26     ` Dmitry Torokhov
2019-10-11 19:25       ` Benjamin Tissoires [this message]
2019-10-11 20:33         ` Dmitry Torokhov
2019-10-11 20:35           ` Dmitry Torokhov
2019-10-11 21:33             ` Dmitry Torokhov
2019-10-11 22:48               ` Benjamin Tissoires
2019-10-11 23:23                 ` Dmitry Torokhov
2019-10-14  9:13                   ` Benjamin Tissoires
2019-10-11 21:02           ` Andrey Smirnov
2019-10-11 21:11             ` Dmitry Torokhov
2019-10-11 22:34           ` Benjamin Tissoires
2019-10-11 20:52         ` Andrey Smirnov
     [not found]   ` <20191014035417.4CE8F2083B@mail.kernel.org>
2019-10-15  4:45     ` Andrey Smirnov
2019-10-07  5:12 ` [PATCH 2/3] HID: logitech-hidpp: split g920_get_config() Andrey Smirnov
2019-10-07  5:12 ` [PATCH 3/3] HID: logitech-hidpp: add G920 device validation quirk Andrey Smirnov
2019-10-11 14:55   ` Benjamin Tissoires
2019-10-11 19:38     ` Andrey Smirnov
2019-10-11 22:32       ` Benjamin Tissoires
2019-10-11 23:32         ` Andrey Smirnov
2019-10-14  9:47           ` Benjamin Tissoires
2019-10-10 22:38 ` [PATCH 0/3] Logitech G920 fixes Sam Bazley
2019-10-11 14:53 ` Benjamin Tissoires
2019-10-11 18:19   ` Andrey Smirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAO-hwJLH6SMkLb1kZGj1E+BUHJ+ZsE1n+d=xeJgsvTCjHH1Wzw@mail.gmail.com' \
    --to=benjamin.tissoires@redhat.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=austinp@valvesoftware.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pgriffais@valvesoftware.com \
    --cc=rydberg@bitmath.org \
    --cc=sambazley@fastmail.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).