Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp495482pxb; Thu, 12 Nov 2020 08:46:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcfwwBVnZAuL2s27A9i1gXkCEqzWDu75Y4fa8kgHV/lkEmDDdNW55T6YWkiL9ii4vS9MTQ X-Received: by 2002:a17:906:854b:: with SMTP id h11mr120640ejy.273.1605199581968; Thu, 12 Nov 2020 08:46:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605199581; cv=none; d=google.com; s=arc-20160816; b=GbjbyU1fi448JDWj+kXB7JptjUw+j9d+Pem1dxT1KaRrOHZbWmShcI/oJwSJf8vqe8 rdsMGKxZWpYxpsDCGxEYTAZv0ucZZRPXipkbqDx57ap/alt8OVoN6fMUfSp1E1V8/9jh 7VnVObQfJfdw9mdtViT48HHEa8cDp+HJEpzQ2HOyc/m3uA+zU0p0FeduEBMM5qfmkeZf oFkfdIyvGcMMd9hvaVpEfRGYdgTqqIgnoE4T5wxtYxSvFChhObbZqOfXNGauLhXjL8B3 AeKutPsaI/7VqJ9VFSgjJXA5na5rng5DhZ0PVFGJlnzEx5d7zhhrfYavSuz4I6OPFBYw iIww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vd26aLv2Qm04BcZ4E7dlGtrKbb7cp/Qy+I+wekalyPA=; b=F0rH56fQFeXj63hu1kbLmqgyjxgA3s+y6zX7G4bwzkGVqZQqChxwo/TggyP7j1itcG IoRnbMMwoAilHKiJz43L4n/+2NByyYyviQ3KHPiRSx9oobykSjx51fhWpiBCI7h4s7Q+ WHF8k9acjtg+lgjn2OO31lZnI5ymV/r2mtIief13SCGUHohRrty90xZrkOTqXWPcUH2u I2iYWhUD27tYnu48FDkIs43nbS/qB5sWJRBfTKz84/gd1XXCGiOGucnx0a4WInz3jhYR jx9a4zYAnf65x1OGVzS51O5FT/dCDIdR6cVgdc4Bw1y73LgrtoQKnF2TJr6oB3yWPFLj eLmA== ARC-Authentication-Results: i=1; mx.google.com; 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 j6si4197882edr.531.2020.11.12.08.45.59; Thu, 12 Nov 2020 08:46:21 -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; 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 S1729184AbgKLQoQ (ORCPT + 99 others); Thu, 12 Nov 2020 11:44:16 -0500 Received: from mx2.suse.de ([195.135.220.15]:50088 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728643AbgKLQoJ (ORCPT ); Thu, 12 Nov 2020 11:44:09 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1D06DAF26; Thu, 12 Nov 2020 16:44:06 +0000 (UTC) From: Nicolas Saenz Julienne To: u.kleine-koenig@pengutronix.de, linux-kernel@vger.kernel.org, Nicolas Saenz Julienne , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com Cc: linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, wahrenst@gmx.net, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, p.zabel@pengutronix.de, linux-gpio@vger.kernel.org, linus.walleij@linaro.org, linux-clk@vger.kernel.org, sboyd@kernel.org, linux-rpi-kernel@lists.infradead.org, bgolaszewski@baylibre.com, andy.shevchenko@gmail.com Subject: [PATCH v4 02/11] firmware: raspberrypi: Introduce devm_rpi_firmware_get() Date: Thu, 12 Nov 2020 17:36:20 +0100 Message-Id: <20201112163630.17177-3-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201112163630.17177-1-nsaenzjulienne@suse.de> References: <20201112163630.17177-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) { + 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