Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1414554ybp; Fri, 11 Oct 2019 13:59:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxww9knIuqEa+n2ajywtWm2KcDb9rBJboUezaV5+b1TY/1H/NK6tv8S6LenkHD01zqecK4G X-Received: by 2002:a17:906:fca8:: with SMTP id qw8mr16345437ejb.188.1570827547663; Fri, 11 Oct 2019 13:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570827547; cv=none; d=google.com; s=arc-20160816; b=w6Q+wvoN9/1SRzKzDuJGDSz6ncnjeLHuB702q4PZWQKFhFfqMkT1XgLlxk1IQD++I6 dvmjxPvxWFYZ4oqN3iCx0PCN5YTRRpVNpX7hACJiPc1MKUYOwAJ1+oOvk1T6C36qGh59 rSHMLqxTgS25YAVnmVNyk+Cdf4vLQN0FYoJzjSbTorMg9EnukJ6romuo0+ufJoWzuJFa nNXrTXsVm/QdgYb3f5t06O0ML4mDB10RIK5uOH/9eCL4/8VigRMAWrpG1+jaV0C6mccT ezc4NDfvgfvHqJSbyzmUlt+9fWTVgVvaEv4+iv7tH6JPYkQ0YCz89CenI2NPfslCDRIR bZWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YRRaZLNTEpMegqxe9gWgkWVmOKd35yZiW006NDQBsR4=; b=ByLm9JkH5FrGwit5p6wt1qA66Dww8+r/kwGukHoGWgJBnEjVXhb27fY/cFwNv0ReIK mmBqg9ck4N7AgvQNSs4DNUfOLzLnmRDsawniqaRSXa3mOoaC7bftJl63lE3VMB4fOwvo 5Tj+tSlrNyl/16Guy/dkAgaVL5aTeO2HFfCp0Yu8d8Gq+gwlzcnazmPsSyd7K7xufwEo Ky4y1PTOv9HxGtCFx1p3/rGD1PmzaEjuFOrjvmR2g4WJ5Y0zt62+lRpbR54FWJsuREkc 1b5GVJtbjvVbsF33pC4BGNuGZPJMivz42IwSNCvsqMkTp0MC14L5/dvHRqyDh4MSVsdX 34+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CMeemMVr; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 52si7155994edz.413.2019.10.11.13.58.44; Fri, 11 Oct 2019 13:59:07 -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=@gmail.com header.s=20161025 header.b=CMeemMVr; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729141AbfJKUdK (ORCPT + 99 others); Fri, 11 Oct 2019 16:33:10 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:37179 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728911AbfJKUdK (ORCPT ); Fri, 11 Oct 2019 16:33:10 -0400 Received: by mail-pl1-f196.google.com with SMTP id u20so4975620plq.4; Fri, 11 Oct 2019 13:33:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=YRRaZLNTEpMegqxe9gWgkWVmOKd35yZiW006NDQBsR4=; b=CMeemMVrniI/ikUjxmc37aSZTdSPy3tWPjZ7XEXq089HTeymZ4GBrghzE1UN4PPv1+ s9SsDUDdLIMgygAX68Lij11RykAbmzWJblLnNB5fwv2z0ZCBL7yfcRP6BSs80rrGqrB9 vft+fHFwNT5+748kzkmAUtjtr9bVikQPqk+qar2ck7z0h81hQ2qTow9UVagJizKCqsnm iVMXEJgzAk5z29/mCAyeqxiDPFaPwvSCbuRSjOhwfzZ9buyDz7j/8wzQ81W12/s5799w uxlCLdwbO6tIeHqIuMfY5B8cIGDx1whyycYk6bpZCFElDSKK+ofwAjUZbFyB0ps3hjeu sTXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=YRRaZLNTEpMegqxe9gWgkWVmOKd35yZiW006NDQBsR4=; b=ks2uq2Ljo5K2MMDX351M990NL13O3B+0HThSeUMKLXsEBRg7H6vaUMNg+m+o5BaMaZ jzt3v5M7l09OQ+tQ+dAR+8z/3thrjB60vGGOujZArIoO2EnqJ2ZBoLENQE3B1L5QlPhD 3+wZkH/yk1sLJhsWsKhl9nN890ozCCStaxklZlezAnF6Hu40hq4VLDYwA6pmBAZAUxRT 0CbO1a1x/nNeHEdXsF+t4vhEnydu69+mdfCcZoLEnayY/xisL/cZTom5EpfgUfsv94jK cizX6ZYLG4nPx5aQ1IRQ2x31RIvy+mi3A1Q1p4Be7XpxbChZDDY7HR0XAvGH2UoApZVm OW+Q== X-Gm-Message-State: APjAAAVAFGNm4mSXPlht2maUDwWE99wu0LHQb2Z/nOoXwAJg+LpFZcHK /KgKJABZsHuEDt0Vtb85rJk= X-Received: by 2002:a17:902:8642:: with SMTP id y2mr16058538plt.187.1570825987061; Fri, 11 Oct 2019 13:33:07 -0700 (PDT) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id r19sm9164591pgj.43.2019.10.11.13.33.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 13:33:05 -0700 (PDT) Date: Fri, 11 Oct 2019 13:33:03 -0700 From: Dmitry Torokhov To: Benjamin Tissoires Cc: Andrey Smirnov , "open list:HID CORE LAYER" , Jiri Kosina , Henrik Rydberg , Sam Bazely , "Pierre-Loup A . Griffais" , Austin Palmer , lkml , "3.8+" Subject: Re: [PATCH 1/3] HID: logitech-hidpp: use devres to manage FF private data Message-ID: <20191011203303.GF229325@dtor-ws> References: <20191007051240.4410-1-andrew.smirnov@gmail.com> <20191007051240.4410-2-andrew.smirnov@gmail.com> <20191011182617.GE229325@dtor-ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) 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 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() switch > > > > 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-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. 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. > > 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. 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