Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp357350pxb; Thu, 5 Nov 2020 01:47:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7npQ4a77abu6rc7V2hXPREaIf6BtLmHOEmxWlBA7kgzDGT+pFtwQiY7JaW5B8pjbHtXb5 X-Received: by 2002:a17:906:66d2:: with SMTP id k18mr1382928ejp.113.1604569621812; Thu, 05 Nov 2020 01:47:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604569621; cv=none; d=google.com; s=arc-20160816; b=yitqWwc78cCGCrs+RS6L0ipx3EmDthyYzuxM8jdtNGCPjSsO3b4D6OBRTNqjWMjrvT VcA4H2no7FgwqxCk5pEzidRp+mQs2GGDVRcA7E0WYV6x5ud2XSYmoEmP9LHM8a49ob8U tq/CUeuMIOavqhjtUsdGNVLh/NFB/peiu4K8YCtkxlc2fddXdna8MiHDvgOzgvYYP/n7 YRP5dwIbM6p6g304FWZt48HIt+PuNMYXnxS9twD9p+PlGsVynBhiv0G2j4XYkSg+OYZX 5/W0zGSNFmQJ7gVam7OcKcDRU1xPxSSz7OqeAhoWSWY3ddzHQegjRUhG6J+oAM5z5wS6 wQAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=DeOBs8//T4JC8W2v/41RF/aONDtKGyNLXtxBMCRNHss=; b=S2necvdiSmPCX5WBmaTmK6xLJLHt5nmrtktPGOo8NDh9DPY64W8slJ+CTMUJ5k9XA/ sifiH+J+BsyT2diwTJH6yDJuKMb3LsR/EbCYI1GFzWzh3pNSLXDzGyIzq5zhg6cZlw8J tf6f4xRpujobl7plcCLZ7tmgTuzS9aUMdYv7q8cDxBxPEbh+rp0VdFVloVNIgEY0n59k sfHVIBzns0lfCZHIin5kaKW7+5qqzBirBJgVOxF01JidADspabPetDK4R7xVf0RRAUN/ hOOWjldeAvI+A0uudnZPqa6Q7GHWQI7esuGinSuMCHKWhSAoFTO55f0vHKuAMeTmW5zx jTSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=CyY1MxxZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w1si702060edf.49.2020.11.05.01.46.39; Thu, 05 Nov 2020 01:47:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=CyY1MxxZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728553AbgKEJnI (ORCPT + 99 others); Thu, 5 Nov 2020 04:43:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726762AbgKEJnC (ORCPT ); Thu, 5 Nov 2020 04:43:02 -0500 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B7FFC0613D4 for ; Thu, 5 Nov 2020 01:43:02 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id k9so830722edo.5 for ; Thu, 05 Nov 2020 01:43:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DeOBs8//T4JC8W2v/41RF/aONDtKGyNLXtxBMCRNHss=; b=CyY1MxxZtzoUExDGbmpfCTNbv0CVGls7p0kDIFJHKIwdCk8Bd4QEzlmsBdJkefe5kF bDVViaItqLXwHDLbA+q9Fr5dnVgW/1XDyTeTaEGjy3Dr6pOaBaYVENiOk6ilsVbG0/HL xeFbvtqJO3blOzIuCgaSSkafRYQolKoH227e+GB3iGCLhm5zzOLXRXW5GdbDuLploRFF FqXsj+CadpLYKdBoFr13XOn5hQRujYHvQqPzQkdCdrmCwaKQKlw9Ba8ZQB5ctigIBhSw tB7ZNrEGerTHA3/IxDKAXDu6f3oUcxTz8A/mJaAdvwYjPMhFzhGJbODSNOIOvro3aJbF ipug== 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=DeOBs8//T4JC8W2v/41RF/aONDtKGyNLXtxBMCRNHss=; b=OjVGWTwTp8OJHIuMjL1o9xedfDYpmuxl6VL7uuOFSb2OlumcEBxGhSUNGjqnUQPzAN VOSX7f4AoR8NdjhfXYBOGivm0XgqjBCZnBvckP5/3QlifeQ0Swpd9gdc7Q540OokRHgi szix//FfDxtD1vAt/Vpa6AdaI6F7eVuccE6iXULJeRtw2K8RNI650A+MXgqzcP5M42D1 gRYBcrRZmcUfR5btcmJip24kkNKQ46v7pKR1cw4sbIzmgiowSivEyjnwDiAXEtj9CTrN ks+cyLoPQ3hpxThBabYJt5/pEHfq+o1Dm+7CMzq3SSytHkp+tQWgv3rA3RRjj8LR/EKZ aivQ== X-Gm-Message-State: AOAM531VYIx7U7LW88G2oKTjcBg2HlMt//PHIdaRSjPnw72FNTh+8yf/ 6nzLhjqguk4/kfliNCA+uN/TpvQL38Oa6hQqySAUbQ== X-Received: by 2002:a50:e442:: with SMTP id e2mr1738064edm.186.1604569380861; Thu, 05 Nov 2020 01:43:00 -0800 (PST) MIME-Version: 1.0 References: <20201104103938.1286-1-nsaenzjulienne@suse.de> <20201104103938.1286-2-nsaenzjulienne@suse.de> <47eaba0bc71c6e23bff87b8a01cebf0c6d12efd0.camel@suse.de> In-Reply-To: <47eaba0bc71c6e23bff87b8a01cebf0c6d12efd0.camel@suse.de> From: Bartosz Golaszewski Date: Thu, 5 Nov 2020 10:42:50 +0100 Message-ID: Subject: Re: [PATCH v3 01/11] firmware: raspberrypi: Introduce devm_rpi_firmware_get() To: Nicolas Saenz Julienne Cc: =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= , LKML , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, linux-pwm@vger.kernel.org, arm-soc , linux-devicetree , wahrenst@gmx.net, Linux Input , Dmitry Torokhov , Greg KH , devel@driverdev.osuosl.org, Philipp Zabel , linux-gpio , Linus Walleij , linux-clk , Stephen Boyd , linux-rpi-kernel@lists.infradead.org, Andy Shevchenko Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 5, 2020 at 10:28 AM Nicolas Saenz Julienne wrote: > > Hi Bartosz, thanks for the review. > > On Thu, 2020-11-05 at 10:13 +0100, Bartosz Golaszewski wrote: > > > +/** > > > + * devm_rpi_firmware_get - Get pointer to rpi_firmware structure. > > > + * @firmware_node: Pointer to the firmware Device Tree node. > > > + * > > > + * Returns NULL is the firmware device is not ready. > > > + */ > > > +struct rpi_firmware *devm_rpi_firmware_get(struct device *dev, > > > + struct device_node *firmware_node) > > > +{ > > > + struct platform_device *pdev = of_find_device_by_node(firmware_node); > > > + struct rpi_firmware *fw; > > > + > > > + if (!pdev) > > > + return NULL; > > > + > > > + fw = platform_get_drvdata(pdev); > > > + if (!fw) > > > + return NULL; > > > + > > > + if (!refcount_inc_not_zero(&fw->consumers)) > > > + return NULL; > > > + > > > + if (devm_add_action_or_reset(dev, rpi_firmware_put, fw)) > > > + return NULL; > > > + > > > + return fw; > > > +} > > > +EXPORT_SYMBOL_GPL(devm_rpi_firmware_get); > > > > Usually I'd expect the devres variant to simply call > > rpi_firmware_get() and then schedule a release callback which would > > call whatever function is the release counterpart for it currently. > > Devres actions are for drivers which want to schedule some more > > unusual tasks at driver detach. Any reason for designing it this way? > > Yes, see patch #8 where I get rid of rpi_firmware_get() altogether after > converting all users to devres. Since there is no use for the vanilla version > of the function anymore, I figured it'd be better to merge everything into > devm_rpi_firmware_get(). That said it's not something I have strong feelings > about. > I see. So the previous version didn't really have any reference counting and it leaked the reference returned by of_find_device_by_node(), got it. Could you just clarify for me the logic behind the wait_queue in rpi_firmware_remove()? If the firmware driver gets detached and remove() stops on the wait_queue - it will be stuck until the last user releases the firmware. I'm not sure this is correct. I'd prefer to see a kref with a release callback and remove would simply decrease the kref and return. Each user would do the same and then after the last user is detached the firmware would be destroyed. Don't we really have some centralized firmware subsystem that would handle this? Bartosz