From patchwork Tue Apr 10 18:32:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10333663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 28EE16053C for ; Tue, 10 Apr 2018 18:43:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 178CE27FA3 for ; Tue, 10 Apr 2018 18:43:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B63A27FAE; Tue, 10 Apr 2018 18:43:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8C52A27FA3 for ; Tue, 10 Apr 2018 18:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=xXpR8y2wsmBTzxGbs0FBV3N++LmSNr+Cglz7jwJu4IQ=; b=sPY ejmzH0FYoCGNggRbsVpVmq0tSJ2DslUgEL86ieS3nFMZrEQUgmTDLh13r/sjySpBN0Ml7V4d0zQme t5ap8YzJiiDCgAJZ/owLql2FwO8QAHMgtGxF5JFqV82ewr8iJ3SVLkktrMyiwM6wDac/LuK4tJPXt lSHQLNQGn7FVrDbGfbE+0Sl5adZGsLGWT3F+OsjTq9HBuX5kI2UPCqAYYHDYjiVqXpMupY6S4KEOX kq/MF1ZvpxKCl8hFrE7APnqEdtEAtz8urYxkROykcnbpvqrSp2lgCO0WJscjIk8HeL3DmQ3Blsnhf TwH8PP9H9VDL9nxX4FAk8cgl0vzWloQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5yEe-0002VS-7t; Tue, 10 Apr 2018 18:43:16 +0000 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5y6e-0001v4-TL for linux-arm-kernel@lists.infradead.org; Tue, 10 Apr 2018 18:35:36 +0000 Received: by mail-pl0-x244.google.com with SMTP id bj1-v6so8061786plb.8 for ; Tue, 10 Apr 2018 11:34:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=UwU7LXYM43Lx4sj8ee1agLdDAUih23VobPVAj+DPZww=; b=amS7auizBIuxbtrxR5CxLJ1+d8M0QJsc1V3aLNwu1LOACAlcG8MMwzC4Gjev+VDjM4 rMKyvYpTwoFo1FVxuzCIyABEZ9hrVbsoBDgdUewfkVCRyD2br9dD5wTlP+Dtdm2OEhbS unmImvx86UvhZcWYGKAEfgn3uXjXV8A4MJVgbmbhtW5S783r5rmP/E4MyiHew1XPDvy6 HxNeo8dAM1NGF18dPWxCacsDltSPSoaV7zHw/bDxucAYz/FpBkFUgmWs9Pcshv+jKdUH 4V0Su4xPosrNqXfYoVhQ+0x/vtjHzzGDObED3Ky872I87wt76BNMZnG9wQJF1+L8QkFL J+9A== 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; bh=UwU7LXYM43Lx4sj8ee1agLdDAUih23VobPVAj+DPZww=; b=exZWYLhSEEGk9o9HcLZOehHXWRo4joiqEqdScWk7+vc37/ksprBQ3mVlZDW4PKI5sy 4QftZqinlx+BYkDTkHEXlO9S4GnGNdLwJX0HyzfXlABw0c8Q+oYtPwjOaMbrtn0YCNza i5HB6g1TElL2Jzbc6DCwD59icPkbUlEYRhWvRFQEotp+wD818NmtxrB0wQHLuMsxCYCW iFO6zwkZQfzjdXkSApenN5hfjyUkCcMsxdOdIv/xt9l0mWbHj/VhyMi8DGA7QvNmTS+5 DfDcc9AF0R7VBCdaXjHv4zW6qIfgRhkXUK4hfznuV1TonwHFGOdGDQwTjcDgPwQNfuCW 4SYA== X-Gm-Message-State: ALQs6tAC+DDkjXM702pJu2Qt38KHaBuTbAtLKUts67uOEqaPpEDuGFC0 bwbbI9vuiwkUd0AoExIlyZM= X-Google-Smtp-Source: AIpwx489lbNxzRLKUQqYqVQ4L2205lXAB6ghB9yWXwYmLeondq/i9oFlpKWdEVvMEnMjuTM6FPz6Mw== X-Received: by 2002:a17:902:a701:: with SMTP id w1-v6mr1534112plq.109.1523385289081; Tue, 10 Apr 2018 11:34:49 -0700 (PDT) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id w12sm4810130pgv.26.2018.04.10.11.34.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Apr 2018 11:34:48 -0700 (PDT) From: Andrey Smirnov To: Shawn Guo Subject: [PATCH v3 1/2] soc: imx: gpcv2: Do not pass static memory as platform data Date: Tue, 10 Apr 2018 11:32:09 -0700 Message-Id: <20180410183210.28052-1-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.14.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180410_113501_025702_36379E17 X-CRM114-Status: GOOD ( 17.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrey Smirnov , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Stefan Agner , Lucas Stach MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Platform device core assumes the ownership of dev.platform_data as well as that it is dynamically allocated and it will try to kfree it as a part of platform_device_release(). Change the code to use platform_device_add_data() n instead of a pointer to a static memory to avoid causing a BUG() when calling platform_device_put(). The problem can be reproduced by artificially enabling the error path of platform_device_add() call (around line 357). Note that this change also allows us to constify imx7_pgc_domains, since we no longer need to be able to modify it. Cc: Shawn Guo Cc: Stefan Agner Cc: Lucas Stach Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Andrey Smirnov --- Changes since [v2]: - Patch reworked to use platform_device_add_data() as per request from Shawn Changes since [v1]: - Replaced devm_kzalloc() with devm_kmalloc() as per suggestion from Stefan [v1] lkml.kernel.org/r/20180110161608.13015-1-andrew.smirnov@gmail.com [v2] lkml.kernel.org/r/20180122150748.1742-1-andrew.smirnov@gmail.com drivers/soc/imx/gpcv2.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c index afc7ecc3c187..f4e3bd40c72e 100644 --- a/drivers/soc/imx/gpcv2.c +++ b/drivers/soc/imx/gpcv2.c @@ -155,7 +155,7 @@ static int imx7_gpc_pu_pgc_sw_pdn_req(struct generic_pm_domain *genpd) return imx7_gpc_pu_pgc_sw_pxx_req(genpd, false); } -static struct imx7_pgc_domain imx7_pgc_domains[] = { +static const struct imx7_pgc_domain imx7_pgc_domains[] = { [IMX7_POWER_DOMAIN_MIPI_PHY] = { .genpd = { .name = "mipi-phy", @@ -321,11 +321,6 @@ static int imx_gpcv2_probe(struct platform_device *pdev) continue; } - domain = &imx7_pgc_domains[domain_index]; - domain->regmap = regmap; - domain->genpd.power_on = imx7_gpc_pu_pgc_sw_pup_req; - domain->genpd.power_off = imx7_gpc_pu_pgc_sw_pdn_req; - pd_pdev = platform_device_alloc("imx7-pgc-domain", domain_index); if (!pd_pdev) { @@ -334,7 +329,20 @@ static int imx_gpcv2_probe(struct platform_device *pdev) return -ENOMEM; } - pd_pdev->dev.platform_data = domain; + ret = platform_device_add_data(pd_pdev, + &imx7_pgc_domains[domain_index], + sizeof(imx7_pgc_domains[domain_index])); + if (ret) { + platform_device_put(pd_pdev); + of_node_put(np); + return ret; + } + + domain = pd_pdev->dev.platform_data; + domain->regmap = regmap; + domain->genpd.power_on = imx7_gpc_pu_pgc_sw_pup_req; + domain->genpd.power_off = imx7_gpc_pu_pgc_sw_pdn_req; + pd_pdev->dev.parent = dev; pd_pdev->dev.of_node = np;