Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1810056ybh; Fri, 13 Mar 2020 07:49:09 -0700 (PDT) X-Google-Smtp-Source: ADFU+vub8kr14lZ743kLH9HROOE0Zn+aSfLgO38djizs7KrTAy/yNOlpSitkvOmk0VqtMLNXn0D9 X-Received: by 2002:aca:5c8b:: with SMTP id q133mr2551931oib.38.1584110949500; Fri, 13 Mar 2020 07:49:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584110949; cv=none; d=google.com; s=arc-20160816; b=mBx2E5dXzlzt51Syirfk8gNGJBdmFFbt7UD5ODa4HGAy4eoMUZU1/+iecCWIRbS9pW 0IJdkQJd79KBJhFe3vT0ZoQ+44xgvBxhSsdCMnE83vboePt2k9y05Ov8PoNbi45DbTQB 6ODbNru5c0DYqVHZ4E2+l/4Z3PrwO8j4SgU4T7WgNOMIVytnXm9hU9R/XKYMW2rxZi+g /B/kyjGZfYHERFbaPLBVOskqeVnYt3iCb8whZbRHpkpxdMAare06+KtcS+4RA8/d/RYQ aCj70ntDe1YJgVaT5HjDnQTgOqNflEnm3efoJPEAzzK2RLBf3spTCTMZVON1Cn9jo6oK 3+ig== 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=Ro1R5ehcYhRf1s0gupnhw5Q+nbHwvID0ows7ral5AwA=; b=gKeKbEpKqnPnV9lmoeFBiBZkegJz+1uS18c0FQsI8z7IsweQQTlYrU0jB45yg+81Uv OYqhMKrChPYvlrCFnma62vn+x1UYk3UouvEozPPwSK6yoyLqmlhXnf7qZwT/4ed1r2dr vYZk+XqtZZAfjTcikD3EqWa7afe+Vz+7g0AZ3E9FgUQcXAXjZKrIErJPpajt7QsWpPBG vSsU/mvrKgR56vUf9VZBT1+HnjQotHNYIfUPOZRc0SeKkKHEIEk+p+Fo8WpRCxW4Zf60 GhYPynaDUcA/pvdSMwUi4luNW95KfXB0W76DPONdnRuJpMNemNWfVhq0TIhN6m+3p7Pg +pNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=UULHVhHo; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1si19912oto.260.2020.03.13.07.48.56; Fri, 13 Mar 2020 07:49: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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=UULHVhHo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726979AbgCMOrk (ORCPT + 99 others); Fri, 13 Mar 2020 10:47:40 -0400 Received: from mail-il1-f196.google.com ([209.85.166.196]:36479 "EHLO mail-il1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726557AbgCMOrk (ORCPT ); Fri, 13 Mar 2020 10:47:40 -0400 Received: by mail-il1-f196.google.com with SMTP id h3so9166058ils.3 for ; Fri, 13 Mar 2020 07:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Ro1R5ehcYhRf1s0gupnhw5Q+nbHwvID0ows7ral5AwA=; b=UULHVhHoV9B8wA8pT06k5F7CEKhKPJTemEriB5P4jsfUl+0MFuocFV+cKfEBUwJOZR 44SDm19Y7MNYFx7IBYDxU1eeSaW08Y1QdU5wPqJ476lvQgn0/8iH8LZarWTvyzQ8f8Pq /yfiAazoYMLLCZA+WD2VvC0CB+j3dinbmK52mQS15VrJHiRU+hrdzgsvFqZQERc3wsoQ g+ZBlhE9WbwRtM/eaNTiBOiVTrV5D3Y6m0xAntdjTsJR7LHKx3cw/ImN5JlKvRE2sZTY CaoeXluOwsKMbIdEpQHSRSCk8Y3XWPOtb/vcDpCSafXtfOW3R/wFvDbweG9ep+FTXkfs 6jCQ== 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:content-transfer-encoding; bh=Ro1R5ehcYhRf1s0gupnhw5Q+nbHwvID0ows7ral5AwA=; b=tKqLShk3TTeXMEsyrFFcSd12F1e+Ic3exe1KBb9GCrffy0z3zZV9tVzysClZbiW1UF LfFkcx9Ukasj96SJV4fCHN76xbFHDTYf4WePrfma95jAf/YKsPEaNu8sW481mVF8nOQx Z4JZYLcWcOSZybmNISMc+mM91p4OC+T12es3MRxFbf/bboAPTntHqB1Qe8yikI0PnhIW 9ZDNtVOCxW9DQvGNmb7bCwJF5A6RtHVmshlSzvO9VDRh+j/BRP0OvMphUhZG0AotA3vM 2VICkswkZXz/vGJO0DmsZcIvG99mtvLFklEiZE7ZPHF8BbbtAFE/OQqPrEUkz1Q4J/TQ 9LlA== X-Gm-Message-State: ANhLgQ23dMWpZsgpi/njMm2sTsxexaAm38+qr2ptQ9uRwF9ITn7FfkrB gdXKS/ERSP0EcSsBu6cmLuZ/f/WFvUHLz5L6DseoOg== X-Received: by 2002:a92:d191:: with SMTP id z17mr14076733ilz.287.1584110859057; Fri, 13 Mar 2020 07:47:39 -0700 (PDT) MIME-Version: 1.0 References: <20200224094158.28761-1-brgl@bgdev.pl> <20200224094158.28761-3-brgl@bgdev.pl> In-Reply-To: From: Bartosz Golaszewski Date: Fri, 13 Mar 2020 15:47:28 +0100 Message-ID: Subject: Re: [PATCH 2/3] gpiolib: use kref in gpio_desc To: Linus Walleij Cc: Srinivas Kandagatla , Khouloud Touil , Geert Uytterhoeven , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , Bartosz Golaszewski 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 czw., 12 mar 2020 o 11:35 Linus Walleij napisa= =C5=82(a): > > Hi Bartosz, > > I'm struggling to figure out if this is the right way to count > references for gpio descriptors. > > I cleared up the situation of why we don't want to add kref > to gpio_chip in the previous message: I think we got that covered. > (If I'm not wrong about it, and I am frequently wrong.) > > This mail is about contrasting the suggested gpio_desc > kref with the existing managed resources, i.e. the > devm_* mechanisms. > > devm_* macros are elusive because they do not use > reference counting at all. > > Instead they put every devm_* requested resource with > a destruction function on a list associated with the struct > device. Functions get put on that list when we probe a > device driver, and the list is iterated and all release functions > are called when we exit .probe() with error or after calling the > optional .remove() function on the module. (More or less.) > > This means anything devm_* managed lives and dies > with the device driver attaching to the device. > Documentation/driver-api/driver-model/devres.rst > > If the intention of the patch is that this action is associated > with the detachment of the driver, then we are reinventing > the wheel we already invented. > In this case I was thinking about a situation where we pass a requested descriptor to some other framework (nvmem in this case) which internally doesn't know anything about who manages this resource externally. Now we can of course simply not do anything about it and expect the user (who passed us the descriptor) to handle the resources correctly. But what happens if the user releases the descriptor not on driver detach but somewhere else for whatever reason while nvmem doesn't know about it? It may try to use the descriptor which will now be invalid. Reference counting in this case would help IMHO. Bart > E.g. to devm_* it doesn't really matter if someone else is > using a struct gpio_desc, or not, but if the current driver > is using it, it will be kept around until that driver detaches. > No reference counting needed for that. > > So is this related to your problem or do I just get things > wrong?