Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp368098ybh; Thu, 12 Mar 2020 03:36:40 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsRlzjIfLL2lCpD8yYv9/LSwlWGzTgci36OykECx2tcyru3agpF1GhGuPxtzsITpO9++WlO X-Received: by 2002:aca:5887:: with SMTP id m129mr1964776oib.175.1584009400151; Thu, 12 Mar 2020 03:36:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584009400; cv=none; d=google.com; s=arc-20160816; b=KlyPaExPjHxVKiI8+B2SH6pB6ILNQ0BF7MNKoQJG8CtiSltdoYWkDm3XNesJTvM8iy xDY3/ne+GUb9AQrZyQEQMdY8Wigk4zwv2UD6ZGcnwlKikJ7JTRqhw3Y3pDzYceMXKowE Sx76DmyGClHnTAap8qmVBN1w1Azr44lLJdFk21e+rKqFioGOxgINwAsspBNn1m8WWtyi fi0HsGXuu05UVKPCg2/h7L5NRBYn5SGGjtSEx0ADiHgQtRhlBPdYpdJfrqoNF6neHzO6 FcrcdpEqVc8L0z3TIWBjVHQ1Wh6kNnu3TrqPkUshQ10OPMFrcoHCJStiYY6j+CFz1DoQ AaIQ== 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=TrLadEtBvTVTVcBt3bopoSIgtuqLiK80lSH0hCVtfuw=; b=eVGwfEfdgO139pHyUkxsjlOUeVFA5BHAtN7qYslmvHfzvuk/tNP55rJKQJWxI3qBgl QE1bv6UepqBg8v8+B773QDPuyyYTEeMS5bmXh7viuUOaOdtKeMHGIdYMXYYF/YcCK7NJ h2a9QTkCIX5qUYt0NPwvXte8s3u3W4lNjXGNzJmHQ+Tei/p4GOoFW2EEsSU57xJ4YzoX D0IWMpweU8knEP47txl6acK+Ia1tbLdGvBAiz4jniqKylgZtCWJ4Kyq5W7BkQlJQw2aM IdtID3G2x7fzAEN+CXuUOmummxW34EnLjhof7K4aY0Vem/Sjpvsv5LNumiMTKEfON4Rt VwTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AXUrdTEb; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si2699533oti.200.2020.03.12.03.36.27; Thu, 12 Mar 2020 03:36:40 -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=@linaro.org header.s=google header.b=AXUrdTEb; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726973AbgCLKf3 (ORCPT + 99 others); Thu, 12 Mar 2020 06:35:29 -0400 Received: from mail-ua1-f67.google.com ([209.85.222.67]:37981 "EHLO mail-ua1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726299AbgCLKf2 (ORCPT ); Thu, 12 Mar 2020 06:35:28 -0400 Received: by mail-ua1-f67.google.com with SMTP id y3so1911259uaq.5 for ; Thu, 12 Mar 2020 03:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TrLadEtBvTVTVcBt3bopoSIgtuqLiK80lSH0hCVtfuw=; b=AXUrdTEbrGYI5Xa4Ju23OdXl2u4/hn8Syww7t4gl9THWvx6gPnACLJY0G+ZZnH81k3 0qwMvbk5hWX+9SRuMreq0nve73Nc8/z7mOlf+34ddgh8XY2R9dL7WErn6ucyPRVc7wkI NgdjiV+vTXtpRQVWxatTxy1wc4+syToipQlg6RS97EvmbkoBdoJy4qNK3Tha1rze0oQk kDHLu4CEBtTmENhdb8SV65B6PgIWzXZ7jLloicG+YrtlH5NCc2CHdBGNMLPN9urYxvwK qb1hGaEduoyMC6FW3igtSCHds2fNMy9Om+Ws5IZdilgLlM+JTcjkxUAwM5JFIW3jTvEp ng3w== 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=TrLadEtBvTVTVcBt3bopoSIgtuqLiK80lSH0hCVtfuw=; b=AVjAZPCzz/Medb+CNa2LulNZyf2mPFkEbi5Eg2fB3Mmh/anQjXtfT6WD5Pup2MAmUj iXeiSWV/rx98FU2Ke9sS43aipA0aoEd2yhPkQzhWGD5ZVaMj9Ol6v+od9f2GmiQGeRiW 65sSjyHKhwpdR36iqHI5hRIJzRvLWz4+YguAjB0JvRn92qsdbC4U+iRkN3PO3VU5ocXk b3RY6o4cYndiqxIWXPz6FChKZwU/oYpyZpKqI1MTHip/6i9rzNZnDqIA2C9KAJziOFg1 9ND+FmOrSZ0O+oMzFm+2sU7nHIuV++pmTABMVfZStupOsFBO02f1bJ/Ed/lm+qxfJuKn NgsQ== X-Gm-Message-State: ANhLgQ1Pp9BrpsbH6x23arvv4oxgoqQuJsBNnwS7gucaCQXnuEynysSh D/pdINFvc4yXsWVdaVWdwT/l/n21CsiGxpujwlvdQA== X-Received: by 2002:ab0:5ea9:: with SMTP id y41mr4333595uag.10.1584009327849; Thu, 12 Mar 2020 03:35:27 -0700 (PDT) MIME-Version: 1.0 References: <20200224094158.28761-1-brgl@bgdev.pl> <20200224094158.28761-3-brgl@bgdev.pl> In-Reply-To: <20200224094158.28761-3-brgl@bgdev.pl> From: Linus Walleij Date: Thu, 12 Mar 2020 11:35:16 +0100 Message-ID: Subject: Re: [PATCH 2/3] gpiolib: use kref in gpio_desc To: Bartosz Golaszewski 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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? Yours, Linus Walleij