Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1424933ybp; Fri, 11 Oct 2019 14:08:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYMTUQIqpsy0iURS1TXZ2SoolO9l8Iqmv0soWjhKsRmDsBrkmkkkKkpVsVEQ8GUmcIUf9s X-Received: by 2002:a17:906:8286:: with SMTP id h6mr15951991ejx.258.1570828133890; Fri, 11 Oct 2019 14:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570828133; cv=none; d=google.com; s=arc-20160816; b=KNIMW4VWkjMo1BcfNGK5AP9iDq7jtEIzLa8HXsWHieCsBnPQ8pFHC7vKewMhdszigL tTtjWjoLPs1efmtNIauzXzQnLaugbueb0+HLBuOlOKjH7vtvsFg3Z+B07hj3vRbKuIBB slMAeeDjnRurxUw1cu6BR9Omn9UFdiuxnsH8NtUFWRxmdqfBS/SpkpGZi/KqTEuAK8po dd0FSk1eQIQ0+pfwJR4X1/hEhW00+Ou0okJOQaFIr+kQdqTfmp9V5VITqgyclF37Rb5a sFca0KYFzH/Ipe9FADZti8yVyFULi3aJFZHTRmn6cqaFCgN44JYQ/gVE7Zn88GWf2pZQ AvGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=mqKrOA4KB3b8vrjSq0Kp4tT5A0a3DDbpcu6SdOiguto=; b=vC9DNpsmfjLNCeC9fHbeyvw0Q6JugSj9zg2LmaX36zt9r48o9UiARS1K8btkl/qQrs CvWZdlq4PusWlKg6Ypz5slAq8xPTHd3BVJIYlVmnGCsHFnvladqttx9XnCJIP3u4JA+n MC44ed98uywam5ep/GEdu+dMxyySRdiIN7BP7dHiHpvemFNnuiJbgWx8Zxvq/MlR66Zm wR/NYBYIdQAIlb3ZG9CAzdxVvf5hXev64lziOI60ItF8uew9LkLkX9QDE8qxdSoUqNcm rhm0T9zVeexMJL5ptqAXgj2zmuu0YqjMb1OdIACnZMQP/TPAgIIVQK7vbjXJX8OBK7AC INhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VZnIl42N; 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 e5si6115257ejj.70.2019.10.11.14.08.15; Fri, 11 Oct 2019 14:08:53 -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=VZnIl42N; 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 S1729193AbfJKVCq (ORCPT + 99 others); Fri, 11 Oct 2019 17:02:46 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:42400 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726843AbfJKVCq (ORCPT ); Fri, 11 Oct 2019 17:02:46 -0400 Received: by mail-lj1-f196.google.com with SMTP id y23so11081434lje.9; Fri, 11 Oct 2019 14:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mqKrOA4KB3b8vrjSq0Kp4tT5A0a3DDbpcu6SdOiguto=; b=VZnIl42NrQS9PFUpMDN5U44yRNwQrRJtKxfOsmhCcaQ/FlrENZuAP47jOjh8mnyIY3 P+WlKto7vhqZ+ZFP1SkTglF2VkGAvg5GYbDhDFdmhu62mXNzh1jFqXHETpc7SavYMzlc IqAuyEeSY4dIEUHcSMMiKqfGZI21K3ZLW0W0d4GNTJQXFFHOUIeWDOQRwesh4h4ob9Bo WcDnpPsPbd5jGRax+edAWk99MLBcMWhFxk14A4RMEKbiaCTkYSp0EOR+OtBlvzJ/T70p BT0sThdvtJoipy2XstY7M7wSiRNEYBR9ehQm9nIVhbKVSH/+wd4uXvgZZhzWsXfXkx5V ngKA== 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=mqKrOA4KB3b8vrjSq0Kp4tT5A0a3DDbpcu6SdOiguto=; b=QVLEQTeb3jAaT7Zsmuwhn4WkVaQ3SSY6pDDlGORsSv6CuCsFBLuDejnlj1buzjZG19 D/CkeHagjLMK4TCN95kbBEre4mvWupzc0HHvTJabH2zy87Sme7VXxi3SdYJKKnQcXemq 4tko5m5wIosCfTYGN4WEHacL5UPh7O/8dNlPmYIl/lR13QDjtPwugL0ZCPgtKTVXnsPo zDN4vRTxGRJBmrMGgmGWcOaKECfzwz5lDmacMA/Sn5FzF1/300ydOI7NAHOZXlvpWhvW LkMoDcbpWBcFkYxugScOMW7KceIXVPbyoXMHi4QFxE8LdnULZW8TIKSdkMJSuga6Zlty ocOg== X-Gm-Message-State: APjAAAWVjzpJT6cScGsznEBVCUAMXuIVa5hmsGjvxO5wlRzbT4aHXnhj AovfJQprv9ys4SbbLBNZM+NtW+DlNsusKYCzqk4= X-Received: by 2002:a2e:97ca:: with SMTP id m10mr8789741ljj.168.1570827762839; Fri, 11 Oct 2019 14:02:42 -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: Andrey Smirnov Date: Fri, 11 Oct 2019 14:02:30 -0700 Message-ID: Subject: Re: [PATCH 1/3] HID: logitech-hidpp: use devres to manage FF private data To: Dmitry Torokhov Cc: Benjamin Tissoires , "open list:HID CORE LAYER" , Jiri Kosina , Henrik Rydberg , Sam Bazely , "Pierre-Loup A . Griffais" , Austin Palmer , lkml , "3.8+" Content-Type: text/plain; charset="UTF-8" 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 1: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() 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. > What do you think of creating input_ff_create_with_private() which would take a pointer to private memory and set a new "borrowed_private" flag in struct ff_device which input_ff_destroy() can check to determine if it needs to free ->private or not? Thanks, Andrey Smirnov