Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1423224ybp; Fri, 11 Oct 2019 14:07:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYO+OkDjGaeW1W5l0iMFMlk6zTul5H1s3qHz0CM0JK6LT1XZeZGCOXLx+OL+f+zePsX0sq X-Received: by 2002:a17:906:e108:: with SMTP id gj8mr16464908ejb.1.1570828029833; Fri, 11 Oct 2019 14:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570828029; cv=none; d=google.com; s=arc-20160816; b=XlgxpdzmrzfChPVFf8LkYn/QGFzXS0JBK1AjreiszWaYV9yMWypou/wwfitEoidiCN RtC03+HWJPx8PIyT3+f2inACFIkntMlh+7fHEgRcc2NCZEQVbjkG5+g31DCXJPmhNAvw TN5ZBg9flqwYhlvCqKi4LxngTuRvLoYjLVSfyJ7fmtXit0wr6fogjzLJ7MgrtkSj9M9+ o/gwLn05ANyaDIl7oEAI5we6FbfvJyEPJ2v/iWnsnKyI85PtfhxkCoHpknABNiuVAbJB Po0KTaQSpbbvsd+6jIK/PRSXk2Viv9p1HCskh4EgaCeXGjPM/yWfp5ImAwWkNGuDGhaf VxnA== 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=g7/73Rc0SKWAOwZoR7q0+hWJYXz555sJEfwUC/bv8II=; b=YnDxW56N/fS8VaNtqwLrQX/5PI54qGFX4t/bO793aFaMowIxTtZMG9tXyOtYu6nsAs jYI9zu71vKOEa6W2587lz317MQNa9wox7Eyg3Wy/0TqJczwcp91fyykmf+OdjPXGQiPe 34s3GN0vf8WxKQlKAnJwsw0k3pMbCTWCifnDAibOMm8W88pXcdyVnoucngOi2SUxIMLT T6fAoeHiXgVJnqqKlA/x8dnfB0G1CNj34zCALT6XhKSs3t5f+YHqUc8WzuD8/LPLXhdH iHc6luNFykREV0D45ItK3rhFyvNkNYn62l9YK01mcB/RtFs/01W+55OwmQDhMNMJOTb4 KK+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NOwHJfGG; 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 a54si6107324edc.333.2019.10.11.14.06.46; Fri, 11 Oct 2019 14:07:09 -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=NOwHJfGG; 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 S1728842AbfJKUwS (ORCPT + 99 others); Fri, 11 Oct 2019 16:52:18 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:34486 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726354AbfJKUwS (ORCPT ); Fri, 11 Oct 2019 16:52:18 -0400 Received: by mail-lf1-f67.google.com with SMTP id r22so7965910lfm.1; Fri, 11 Oct 2019 13:52:14 -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=g7/73Rc0SKWAOwZoR7q0+hWJYXz555sJEfwUC/bv8II=; b=NOwHJfGGX76/mb9z7ZvBAt5mN+Brvb/Xtk/F0Ja6c4sBN69CNSgGQg0iJT4Z9z5x1v C0X8Wd9H7/wZ9RrIBeIr74t2GbayrJoX/pyDnBrJ2L5VkJy1oTLYHP8UJyn0He0M+pK2 HmRyJbX653VgAAclfTJdJbQ88gPeLSrVLNK2D0F74BaMPrqeRB2HK8Oi+JUx8ruvdm7u 6PHVTpaZh+9s26ZXn4P6/sKa0u7wxWCQYMySNwnVCURBV48Sz6TzEkpw5CHfUdeN5qYn eIhiYNwZm/2m4JHSCyrqikzZ6e//4fq01KpWXMDZMyw9qcmGMi7UH6FUIIzm/07XOc9s b58w== 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=g7/73Rc0SKWAOwZoR7q0+hWJYXz555sJEfwUC/bv8II=; b=ehwChliZaBTylb60u2J1Oj0lRipwoT2ds25hjptPB8ixo15H1Nz1y6ZfBLFKyHFQVt Q0cnRSaAHjbApeP517PzdfjR4Lhrq1vQWITCQx0pMTJzUpSyxrpjPfkiaj6bFFxvjctf cn0Lx2P7b6WWmxILihvWh7IjaAvglTpgjfsMnpkVgjJk+AIHIFsMGriqfsY+LdAG2Lky Dp5dfz18eiXrHyzIIZSMErcIZzjYhaYiMSkD78BJpeAJhepuLjs63Wwb3gB7tHMPfqrW qRbkivukJQKUt+lKZbUD+W/mEQ7RthcLAE79MFV1IW7tYn5ZtE0Vhv61S5dpBzKUtch+ h+Gw== X-Gm-Message-State: APjAAAXHyqSQnw0iMLwtErx1sLzW+aLMuhfTh2O/90qw3msaQ2+4P+5z gNuqJIUyTrJcw0fpemPiM+1xTqFOzhrZ2GRBLn0tp9qSG2A= X-Received: by 2002:a19:fc0b:: with SMTP id a11mr9878797lfi.105.1570827133788; Fri, 11 Oct 2019 13:52:13 -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> In-Reply-To: From: Andrey Smirnov Date: Fri, 11 Oct 2019 13:52:02 -0700 Message-ID: Subject: Re: [PATCH 1/3] HID: logitech-hidpp: use devres to manage FF private data To: Benjamin Tissoires Cc: Dmitry Torokhov , "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 12:26 PM 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. > > 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. Sure, I'll add this to the series as a separate patch. Thanks, Andrey Smirnov