Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp525837pxb; Thu, 12 Nov 2020 09:27:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUcG8QqZ2UwnYdO+W9Yjqc4hjJQSu/+qE2W/icmQUVJtT42fsiW4qB5IKnoFYig3GxbVTf X-Received: by 2002:a50:f0d4:: with SMTP id a20mr856778edm.303.1605202068471; Thu, 12 Nov 2020 09:27:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605202068; cv=none; d=google.com; s=arc-20160816; b=EQNKgGfvWqpw0J1MjyADtGck9Qa2X8lphITw2Ibx2TDi/jHfXwxMgp5pL26jx+Jsqu Xup6XlEktlxOJolF4dFDMtP2pJZOKgUr3gIj+VUbi6AAaYupf8sOB7fJ14sf85Srlbdv sGFWKnF/fjpuv3ImmQtIExNKHbiRvuMLk3kI1Uf5YTy296ROyfHcA/5KuuqzEljnCqzc UkWw7ykQBJxMfMp9/FZOlYTCoDa+AStaLxCYZjkW68vuRLHAvP9qvSSE3QzXPd6N1zfO DWa3dVOGx7mGTo/czcA2NbQOYqS8foOjkP8pm6i5NayKJLW5WveEb/b8NLSePohkosLZ gVwg== 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=EYH3xwiXEDAnNYFH6sRlnj0nrx9OC5GkHU2BEsYeg8c=; b=aVJtp/eFselvAEVelBlElwJ2DTntEXFo5zper1RRuGyDFZM9vF+1oSmWbyrpgM6lOD u49cMgEYLo+DC7S6JYUPVMQmOJlqMaAyJwsNbQhzrWIE4fBaY73d+7pgc4UR8Zh+tuXf ck/Re9/oXAOubSNX0EI4vkfWmuspAVz/O9ROedJoXv0qbk70DZXpVSNH4htjnHATToc+ 1oYR8a9BjK4Ei7nVf9r7SvTBbWeh+MeEoe/ay1Tm5BjTx4VHXFNaWacHAaVUP1qYySHw GjBEHVqHMBA8uZ8EPh4YApJlW8Rm13mUr0PHW9QZw8+VLpRRACb29nEQy//FvLee4s6x DCLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=V1er74VJ; 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 q3si4412389edv.85.2020.11.12.09.27.24; Thu, 12 Nov 2020 09:27:48 -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=V1er74VJ; 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 S1726041AbgKLRZ7 (ORCPT + 99 others); Thu, 12 Nov 2020 12:25:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgKLRZ7 (ORCPT ); Thu, 12 Nov 2020 12:25:59 -0500 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EEAFC0617A7 for ; Thu, 12 Nov 2020 09:25:58 -0800 (PST) Received: by mail-ed1-x543.google.com with SMTP id q3so7216637edr.12 for ; Thu, 12 Nov 2020 09:25:58 -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=EYH3xwiXEDAnNYFH6sRlnj0nrx9OC5GkHU2BEsYeg8c=; b=V1er74VJGkYMqey/iyOXhUJFrbfBMej3NDgDK/+Dsn878FmHqTP2crY3RgRv+amk6x qmjtEZmsJbcY0UAfQUB4Uy/Au7ucKUx4UikT7GphdZINd4kjRqdu7vhLTTTpV1YG4zaU 7eSTqs1Ajd5b1s8r6edLBGVp0ADsMSfZVuRn4RIbtxiHxKc5NzogmuBfiG1TJ59nrTi8 jDtqKDS+c/qmN9QYU5oKIdKjsCTqT85+uPsYArzF81ZO2o053KEPLRhdaNUI7gbS37YR ZYP6gYur4aoMH+k6trf/kSpCgk7T8XZUUHJ5JjANSOs0Y1Wmvue8yKT61v8pLlOtGbuv QViA== 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=EYH3xwiXEDAnNYFH6sRlnj0nrx9OC5GkHU2BEsYeg8c=; b=LbElT0vAlPKI/fH/KssAWXtHQjVgQ/91vTtlTaR0PZqcSRIHv6YdjB2iRUE4icv3Zx LLdZOrVxxlbzxeC0wfxN+iBK6NBM0x55CZUHZrDxrqC5UvSrm3szj7Kd2CG6svzHW6v2 KYAInTyH4dr8sQtFRjGZsaXLxKe98G1PqOt5LfLm2n3vWYiXv6onqRUMnM/tMj3r1iKj IvgpILG+AKys1perEK+RQUhvgrTrhypDEiKizkiK5CF9UwP3aFvCE1I0b38PFjAc7ZhP M7+AdvZK1vhieK1LNTuD2IgW79PEZIN0pAjNCEBqywk93HyDulz8A81WY7IJifYiYeKu C5Dw== X-Gm-Message-State: AOAM530dTEDLO32DBGcZCfbKwZuHUCnu3IGQefUbGzsIK/BTIfg9VJ/f cIO1Q8E0tYstH17AypLaP1LgIa+c69912XnEFgly4A== X-Received: by 2002:aa7:d54b:: with SMTP id u11mr878250edr.341.1605201957042; Thu, 12 Nov 2020 09:25:57 -0800 (PST) MIME-Version: 1.0 References: <20201112163630.17177-1-nsaenzjulienne@suse.de> <20201112163630.17177-3-nsaenzjulienne@suse.de> In-Reply-To: <20201112163630.17177-3-nsaenzjulienne@suse.de> From: Bartosz Golaszewski Date: Thu, 12 Nov 2020 18:25:46 +0100 Message-ID: Subject: Re: [PATCH v4 02/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 12, 2020 at 5:44 PM Nicolas Saenz Julienne wrote: > > Itroduce devm_rpi_firmware_get(), it'll simplify the firmware handling > for most consumers. > > Suggested-by: Bartosz Golaszewski > Signed-off-by: Nicolas Saenz Julienne > --- > > Changes since v2: > - Introduce devm_rpi_firmware_get() > > drivers/firmware/raspberrypi.c | 31 +++++++++++++++++++++- > include/soc/bcm2835/raspberrypi-firmware.h | 8 ++++++ > 2 files changed, 38 insertions(+), 1 deletion(-) > > diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c > index 438e17074a97..4ab2dfdc82ad 100644 > --- a/drivers/firmware/raspberrypi.c > +++ b/drivers/firmware/raspberrypi.c > @@ -237,10 +237,17 @@ static void rpi_firmware_delete(struct kref *kref) > kfree(fw); > } > > -void rpi_firmware_put(struct rpi_firmware *fw) > +static void __rpi_firmware_put(void *data) > { The '__' prefix is very vague and usually used for unlocked variants of functions. The casting to void * in rpi_firmware_put() is also unneeded. I would much prefer that the devres release callback be called devm_rpi_firmware_put() and that it call rpi_firmware_put() which would then call kref_put(). Bartosz > + struct rpi_firmware *fw = data; > + > kref_put(&fw->consumers, rpi_firmware_delete); > } > + > +void rpi_firmware_put(struct rpi_firmware *fw) > +{ > + __rpi_firmware_put(fw); > +} > EXPORT_SYMBOL_GPL(rpi_firmware_put); > > static int rpi_firmware_probe(struct platform_device *pdev) > @@ -326,6 +333,28 @@ struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node) > } > EXPORT_SYMBOL_GPL(rpi_firmware_get); > > +/** > + * 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 rpi_firmware *fw; > + > + fw = rpi_firmware_get(firmware_node); > + if (!fw) > + return NULL; > + > + if (devm_add_action_or_reset(dev, __rpi_firmware_put, fw)) > + return NULL; > + > + return fw; > +} > +EXPORT_SYMBOL_GPL(devm_rpi_firmware_get); > + > static const struct of_device_id rpi_firmware_of_match[] = { > { .compatible = "raspberrypi,bcm2835-firmware", }, > {}, > diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h > index fdfef7fe40df..73ad784fca96 100644 > --- a/include/soc/bcm2835/raspberrypi-firmware.h > +++ b/include/soc/bcm2835/raspberrypi-firmware.h > @@ -142,6 +142,8 @@ int rpi_firmware_property_list(struct rpi_firmware *fw, > void *data, size_t tag_size); > void rpi_firmware_put(struct rpi_firmware *fw); > struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node); > +struct rpi_firmware *devm_rpi_firmware_get(struct device *dev, > + struct device_node *firmware_node); > #else > static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag, > void *data, size_t len) > @@ -160,6 +162,12 @@ static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware > { > return NULL; > } > + > +static inline struct rpi_firmware *devm_rpi_firmware_get(struct device *dev, > + struct device_node *firmware_node) > +{ > + return NULL; > +} > #endif > > #endif /* __SOC_RASPBERRY_FIRMWARE_H__ */ > -- > 2.29.2 >