From patchwork Fri Feb 17 14:31:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 94160 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp194429qgi; Fri, 17 Feb 2017 06:31:46 -0800 (PST) X-Received: by 10.99.45.133 with SMTP id t127mr10517800pgt.224.1487341906651; Fri, 17 Feb 2017 06:31:46 -0800 (PST) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id n12si10424013pfa.269.2017.02.17.06.31.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Feb 2017 06:31:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 40E656ED2F; Fri, 17 Feb 2017 14:31:45 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com [IPv6:2a00:1450:400c:c09::22d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7986B6ED2E for ; Fri, 17 Feb 2017 14:31:42 +0000 (UTC) Received: by mail-wm0-x22d.google.com with SMTP id v186so16756180wmd.0 for ; Fri, 17 Feb 2017 06:31:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y4c2QMwLv9QYQ+nOQayN0UR0rs57hfiqsDEeDEmYjGQ=; b=A4i2ElTTS9o5e9dooIy10AFuYRgCHGsNv0BZzLbsgPQohUwQWnMSBLIC5zTqW//tzT 0VQm29MxSo0Ma8x6MxVYqB27kBimCpgdm3xa9nKzjlot3p1ibWv1pC2tvLMg+VfzFAk7 d7NB5q1Fo30pQjBckbG6gjPgUpuG1Gm3wfWc8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=y4c2QMwLv9QYQ+nOQayN0UR0rs57hfiqsDEeDEmYjGQ=; b=s+42LEKD7x9Law/RmhwJX4KY+rGysqR7wOF0nPBk2fZKAPPMQOI5PpVfwtudhG71SN dDz2wLMMwWW4bE52WsbUFbs6syGolo0qdMYL/TIih+1TCmGXCxcRZyp5zOLBH6DOi9L8 4N2Sehchs+oaQxjL/h2pH48k3pkSRQwH477vT2EzJlp5W0MZhI+VMgT0TaaNyt+YefnD KuyvXBVXjfi0C/GBsrI16Yfuawu8Z10GVYA7ZcM5tPzC1PvLMdJvYds0IcixH+Eq1pXh 300AO3ZlSnUyZ9x2pKmdf4dvv2FHpEJcuOAZbQibLx47KLaaueu+MnFKCcL8Rn6bzWRa UKLQ== X-Gm-Message-State: AMke39kTnQmNKmuidFa4oeajYrt3H0cv5e6sF0Gp0eJZ7gttd3oU85tqtY+WWvoWu2dZSile X-Received: by 10.28.146.12 with SMTP id u12mr2319427wmd.113.1487341901079; Fri, 17 Feb 2017 06:31:41 -0800 (PST) Received: from lmenx321.st.com. ([80.215.97.44]) by smtp.gmail.com with ESMTPSA id g81sm1904593wmf.16.2017.02.17.06.31.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Feb 2017 06:31:40 -0800 (PST) From: Benjamin Gaignard To: robh+dt@kernel.org, frowand.list@gmail.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, vincent.abriou@st.com, dri-devel@lists.freedesktop.org Subject: [PATCH v1 1/2] of: add devm_ functions for populate and depopulate Date: Fri, 17 Feb 2017 15:31:25 +0100 Message-Id: <1487341886-13829-2-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1487341886-13829-1-git-send-email-benjamin.gaignard@linaro.org> References: <1487341886-13829-1-git-send-email-benjamin.gaignard@linaro.org> Cc: linaro-kernel@lists.linaro.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Lost of calls to of_platform_populate() are not unbalanced by a call to of_platform_depopulate(). This create issues while drivers are bind/unbind. In way to solve those issues is to add devm_of_platform_populate() which will call of_platform_depopulate() when the device is unbound from the bus. Signed-off-by: Benjamin Gaignard --- drivers/of/platform.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_platform.h | 20 ++++++++++++ 2 files changed, 97 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index b8064bc..3dbebf7 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -571,6 +571,83 @@ void of_platform_depopulate(struct device *parent) } EXPORT_SYMBOL_GPL(of_platform_depopulate); +static void devm_of_platform_populate_release(struct device *dev, void *res) +{ + of_platform_depopulate(*(struct device **)res); +} + +/** + * devm_of_platform_populate() - Populate platform_devices from device tree data + * @dev: device that requested to populate from device tree data + * @root: parent of the first level to probe or NULL for the root of the tree + * @matches: match table, NULL to use the default + * @lookup: auxdata table for matching id and platform_data with device nodes + * @parent: parent to hook devices from, NULL for toplevel + * + * Similar to of_platform_populate(), but will automatically call + * of_platform_depopulate() when the device is unbound from the bus. + * + * Returns 0 on success, < 0 on failure. + */ +int devm_of_platform_populate(struct device *dev, + struct device_node *root, + const struct of_device_id *matches, + const struct of_dev_auxdata *lookup, + struct device *parent) +{ + struct device **ptr; + int ret; + + ptr = devres_alloc(devm_of_platform_populate_release, + sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = of_platform_populate(root, matches, lookup, parent); + if (ret) { + devres_free(ptr); + } else { + *ptr = parent; + devres_add(dev, ptr); + } + + return ret; +} +EXPORT_SYMBOL_GPL(devm_of_platform_populate); + +static int devm_of_platform_match(struct device *dev, void *res, void *data) +{ + struct device **ptr = res; + + if (!ptr) { + WARN_ON(!ptr); + return 0; + } + + return *ptr == data; +} + +/** + * devm_of_platform_depopulate() - Remove devices populated from device tree + * @dev: device that requested to populate from device tree data + * @parent: device which children will be removed + * + * Complementary to devm_of_platform_populate(), this function removes children + * of the given device (and, recurrently, their children) that have been + * created from their respective device tree nodes (and only those, + * leaving others - eg. manually created - unharmed). + */ +void devm_of_platform_depopulate(struct device *dev, struct device *parent) +{ + int ret; + + ret = devres_release(dev, devm_of_platform_populate_release, + devm_of_platform_match, parent); + + WARN_ON(ret); +} +EXPORT_SYMBOL_GPL(devm_of_platform_depopulate); + #ifdef CONFIG_OF_DYNAMIC static int of_platform_notify(struct notifier_block *nb, unsigned long action, void *arg) diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index 956a100..282fae3 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -76,6 +76,14 @@ extern int of_platform_default_populate(struct device_node *root, const struct of_dev_auxdata *lookup, struct device *parent); extern void of_platform_depopulate(struct device *parent); + +extern int devm_of_platform_populate(struct device *dev, + struct device_node *root, + const struct of_device_id *matches, + const struct of_dev_auxdata *lookup, + struct device *parent); +extern void devm_of_platform_depopulate(struct device *dev, + struct device *parent); #else static inline int of_platform_populate(struct device_node *root, const struct of_device_id *matches, @@ -91,6 +99,18 @@ static inline int of_platform_default_populate(struct device_node *root, return -ENODEV; } static inline void of_platform_depopulate(struct device *parent) { } + +static inline int devm_of_platform_populate(struct device *dev, + struct device_node *root, + const struct of_device_id *matches, + const struct of_dev_auxdata *lookup, + struct device *parent) +{ + return -ENODEV; +} + +static inline void devm_of_platform_depopulate(struct device *dev, + struct device *parent) { } #endif #if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS) From patchwork Fri Feb 17 14:31:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 94161 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp194447qgi; Fri, 17 Feb 2017 06:31:49 -0800 (PST) X-Received: by 10.98.19.12 with SMTP id b12mr9617817pfj.150.1487341909500; Fri, 17 Feb 2017 06:31:49 -0800 (PST) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id i9si4284322pli.318.2017.02.17.06.31.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Feb 2017 06:31:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 668F16ED34; Fri, 17 Feb 2017 14:31:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x230.google.com (mail-wm0-x230.google.com [IPv6:2a00:1450:400c:c09::230]) by gabe.freedesktop.org (Postfix) with ESMTPS id 65CB66ED2F for ; Fri, 17 Feb 2017 14:31:44 +0000 (UTC) Received: by mail-wm0-x230.google.com with SMTP id c85so16703102wmi.1 for ; Fri, 17 Feb 2017 06:31:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=R+Itmz2Nm8ixdYR9egrVmFJ+UiPBlSRdVGIpGdIEO5U=; b=FssSesNzluIOpYoge2/aScci4raqL7wqNsPkVOMsBk3481Y8JXVWNdH5wBLHCQP2yJ WTotxn/Wk4J2OADjslTClYWxBBaqCjLpjfUo0Nh9QYgJiG5KXmPdaJbQmVVVOjXtCbYI 6B+6IXhP4F5X1qwBW2c46lSFcqnYOV88xWIyw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=R+Itmz2Nm8ixdYR9egrVmFJ+UiPBlSRdVGIpGdIEO5U=; b=gNN8PRmdEEP5IJl8f9K/nP+JxPEVSZSmrw+i+J6xIL4Yfh2rKM/QTMNM5HCh+1TvVY TjDfJDUmajIW2YVGuj8O8AwSJ2b52X2a5qW8HFQ2/ag66OklWxi3XnA84EIOpySR2+lu oqpg9yt7prKpDlCwavb8KeEixc1F/czDGJjUew180QlG7y3vqKD0IdE+I50/HpvPbyB0 anicDS1ZvX6szpwrMyBirTIaOtbK8qh1HMg/xRhCsbq4g3IhbaNhgMdEcjjEyjr32FF1 eVdS2tsjOarlI6L2CyjgtuYL91JxUreXO8rDgvR2Tpiyj/roMQ47LJQx53i5fqBFYT/Y bnVQ== X-Gm-Message-State: AMke39ntwWfvycCZSTbFLBgIyrYe4FVNgOJ/Vxy/qK1ot07rxq3nYVFPgVWFCMJiGvtNs6s0 X-Received: by 10.28.128.131 with SMTP id b125mr4048638wmd.7.1487341903078; Fri, 17 Feb 2017 06:31:43 -0800 (PST) Received: from lmenx321.st.com. ([80.215.97.44]) by smtp.gmail.com with ESMTPSA id g81sm1904593wmf.16.2017.02.17.06.31.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Feb 2017 06:31:42 -0800 (PST) From: Benjamin Gaignard To: robh+dt@kernel.org, frowand.list@gmail.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, vincent.abriou@st.com, dri-devel@lists.freedesktop.org Subject: [PATCH v1 2/2] drm: sti: make driver use devm_of_platform_populate() Date: Fri, 17 Feb 2017 15:31:26 +0100 Message-Id: <1487341886-13829-3-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1487341886-13829-1-git-send-email-benjamin.gaignard@linaro.org> References: <1487341886-13829-1-git-send-email-benjamin.gaignard@linaro.org> Cc: linaro-kernel@lists.linaro.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This make sure that of_platform_depopulate() is called if an error occur in probe after populating the date from the device tree. Signed-off-by: Benjamin Gaignard --- drivers/gpu/drm/sti/sti_drv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/sti/sti_drv.c b/drivers/gpu/drm/sti/sti_drv.c index ff71e25..01ef9a4 100644 --- a/drivers/gpu/drm/sti/sti_drv.c +++ b/drivers/gpu/drm/sti/sti_drv.c @@ -438,7 +438,7 @@ static int sti_platform_probe(struct platform_device *pdev) dma_set_coherent_mask(dev, DMA_BIT_MASK(32)); - of_platform_populate(node, NULL, NULL, dev); + devm_of_platform_populate(dev, node, NULL, NULL, dev); child_np = of_get_next_available_child(node, NULL); @@ -454,7 +454,6 @@ static int sti_platform_probe(struct platform_device *pdev) static int sti_platform_remove(struct platform_device *pdev) { component_master_del(&pdev->dev, &sti_ops); - of_platform_depopulate(&pdev->dev); return 0; }