Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1519262ybp; Fri, 11 Oct 2019 15:51:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwx9OxirFMepvz/Tr2x3alf2+6p/rYglSE3Kiut0RJPpDG/4cbLyHA50C2hNC/jDwCDPESo X-Received: by 2002:a17:906:940a:: with SMTP id q10mr16448179ejx.250.1570834291680; Fri, 11 Oct 2019 15:51:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570834291; cv=none; d=google.com; s=arc-20160816; b=px7CoTorP7WP6omlxNoZLkzJ0Ie0kq1jH0yad9dLEf4wVV9iNFgeYu0CvugGxTPJfb SBMR/TS2DGFs9YhI8WJp0bw7AoJsoniZIRDEVWjOGRCAYWIX1BZxddy14py4AVyTaQ6s R17j76PWmvlrnPw3MItpH57PVmpoz93foVlpnZ/D/QzckqTL4u1LK/D43XetRMrd6bKe rrgh01GsEzktP7wlTgMovaiEUd+rVWK5zNDSvzoqqCXPv9rcRFUyQsEpTvIkQNPFonux haqYmn6BUnbVXKsNwWnjYRFzfyeVs6XXdQSBdBVXtZFBmB2CfTNi1APk9CL8wb1GB9pS U6Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=xaCx4BwzuaSKoJi0tA/bbvHgniT7bfXHnSLmKvXpCng=; b=xn/z4cW8b2mvMXLuW6DNH5CL8id9gec7LxeogR1WQz49IRaPW/cW6I8/TzfWcyIExO wiIqXWicmwbGYHZwog9Xem9DzCt6DzEMARBqoGLQQ2LSqUmnWXQfUtwiPZQeCvDWsZHW lnsgwlLuaYYRrM/jUaoIFj3hU5bUel9QleUv+CchkxCcKFU9wHkozC6rDw8i5WPX4oXp ACjYLCpKRmSQWTTjcmzdINxE0FotcyuS3zQATcRTGsyJbY8cRUjD0Ugwifmcr6zvh/Qs wXvcxX3ZKT/TdGTGzPzTIDukgFKSn+LpakuNyTNvo4Dwba1IZViFNs824I73oc5im1Xa Hi8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YidGgP0k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si6869437ejc.382.2019.10.11.15.51.08; Fri, 11 Oct 2019 15:51:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YidGgP0k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727525AbfJKWes (ORCPT + 99 others); Fri, 11 Oct 2019 18:34:48 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:57897 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727473AbfJKWer (ORCPT ); Fri, 11 Oct 2019 18:34:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1570833286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xaCx4BwzuaSKoJi0tA/bbvHgniT7bfXHnSLmKvXpCng=; b=YidGgP0kjumZ0CqNuzZirEQRzYK/w9S4MQPjRdAnWrTt8vF/RSFHwwLJ3zsqJ8RrCTgKh4 5REIxIhA/CSHtwgo7sryDyFFDvNp84UPciKckBv/DOV24tPlDdUO1IQaWcyEkI/6o/TDnI X3BywlEq0pRhv/KLLoaC4Sjj26S7OhA= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-264-RPTxOyLvMmCYYyv_2A4AEw-1; Fri, 11 Oct 2019 18:34:42 -0400 Received: by mail-qk1-f198.google.com with SMTP id n135so10387305qke.23 for ; Fri, 11 Oct 2019 15:34:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fEQj8SZLHc+CmCdZ+zyTylgWZdpd8h+Hxcmb3WKQW5g=; b=Tx/6enVr1Ygvpa7/hBJyFwi38CRCD/zZweyHaTv0/cacfAJbGd77YNFDLEFfiyADrl mpmqB/Ze/w+u6Y+ShHTEtifMzQymSILBYvplciJoiCyzFq83N9V+QBur4QUjn5nw3kYY gjwqMzOLq9LZV1BQ+NWxdWeeOmZ64T5KwXKwDvZVjnpBYE0eJx1i8yatAzQucFyYe8nx BE8rdumazj8knRlr56582BQoU3w4RYkphxAeyyfX0hm1yL086Reeg/9iZ7xH3ctjBsQY 7UQ2xpGTXtlUe8uB+Uh+tSQ04Q5XTVqsHSHX4XEWAzRUTBrHO6joMjgO5HfD8yWI96Ys A6CQ== X-Gm-Message-State: APjAAAXDPwR8WFtTW63jbDtUj4mcfogKXsW8Eg9xxLFykvxUniy+oes1 lSwrgAkEyFQY+wtQtMAZHk9v563LxDZoX7dBbpl8HuiMcLSP49Qf8s1ht+hvkBfRlh+8nNW1aq0 6Mh+gsAxH8QcWUGjAVdEIkrPv9Nb6df7oTXi/d7fl X-Received: by 2002:ae9:f306:: with SMTP id p6mr18364135qkg.169.1570833281889; Fri, 11 Oct 2019 15:34:41 -0700 (PDT) X-Received: by 2002:ae9:f306:: with SMTP id p6mr18364103qkg.169.1570833281628; Fri, 11 Oct 2019 15:34:41 -0700 (PDT) MIME-Version: 1.0 References: <20191007051240.4410-1-andrew.smirnov@gmail.com> <20191007051240.4410-2-andrew.smirnov@gmail.com> <20191011182617.GE229325@dtor-ws> <20191011203303.GF229325@dtor-ws> In-Reply-To: <20191011203303.GF229325@dtor-ws> From: Benjamin Tissoires Date: Sat, 12 Oct 2019 00:34:30 +0200 Message-ID: Subject: Re: [PATCH 1/3] HID: logitech-hidpp: use devres to manage FF private data To: Dmitry Torokhov Cc: Andrey Smirnov , "open list:HID CORE LAYER" , Jiri Kosina , Henrik Rydberg , Sam Bazely , "Pierre-Loup A . Griffais" , Austin Palmer , lkml , "3.8+" X-MC-Unique: RPTxOyLvMmCYYyv_2A4AEw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 11, 2019 at 10:33 PM Dmitry Torokhov wrote: > > On Fri, Oct 11, 2019 at 09:25:52PM +0200, Benjamin Tissoires wrote: > > On Fri, Oct 11, 2019 at 8:26 PM Dmitry Torokhov > > 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 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() sw= itch > > > > > driver code to use devres to manage the life-cycle of FF private = data. > > > > > > > > > > Signed-off-by: Andrey Smirnov > > > > > Cc: Jiri Kosina > > > > > Cc: Benjamin Tissoires > > > > > Cc: Henrik Rydberg > > > > > Cc: Sam Bazely > > > > > Cc: Pierre-Loup A. Griffais > > > > > Cc: Austin Palmer > > > > > 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-l= ogitech-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_dev= ice *ff) > > > > > struct hidpp_ff_private_data *data =3D 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 assign= ed > > > 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. > > I do not think we want devm_input_ff_create() explicitly, I think the > fact that you can "build up" an input device by allocating it, then > adding slots, poller, ff support, etc, and input core cleans it up is > all good. It is just the ownership if the driver-private data block is > not very obvious and is not compatible with allocating via devm. Yep, that's what I meant: input_ff_create() already handles its cleanup, so there is no point in devm_input_ff_create() as the input core should clean it up for us. Cheers, Benjamin > > > > > 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 n= ot > > > 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 the= y > > > 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. > > Yeah, well, that is a common issue with mixing devm and normal resources > (and workqueue here is that "normal" resource), and we should either: > > - not use devm > - use devm_add_action_or_reset() to work in custom actions that work > freeing of non-managed resources into devm flow. > > Thanks. > > -- > Dmitry