From patchwork Wed Jan 10 16:16:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10155531 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 9417260231 for ; Wed, 10 Jan 2018 16:16:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EE8628500 for ; Wed, 10 Jan 2018 16:16:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70BF328524; Wed, 10 Jan 2018 16:16:43 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 2C3F428500 for ; Wed, 10 Jan 2018 16:16:43 +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=hPa39uQG4od6TrwD+3e0jCF0FMznbKAQ570Eedp1EDw=; b=Jh7 2VnJowZicmNYRTUd4sDZxBu/1JYGVy3Hrm2LmYmqzEp12ztZzk+0uY4InP4PmEwo66eC10VNlBTaC 0LcCpQyRnc4/ttgbRUfuHggAGOxFh1bab2U4+G/lP/PNrMTxaYCn5zdKywLGh8NEGB3qY/BiBeipv AodRt+DF8QDBqR9qUvOwY2JV6FA1nqoIHLr3XJtYKStRY3mIQaQKt+4fc+czUmQXH/lOFlrOyRsYO nmg9xC0r0YitaXTYyRILbs5sGxIhcqgRl33ps2esjeZYnu7L3t5JfcSjnzWn6wvg/5b3a+pa7QH39 FXiRVT1E8uZTwLbMxo7fiVKOXO/DPzw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eZJ3R-0007Qd-Tj; Wed, 10 Jan 2018 16:16:41 +0000 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZJ3N-0007M0-P0 for linux-arm-kernel@lists.infradead.org; Wed, 10 Jan 2018 16:16:39 +0000 Received: by mail-pg0-x243.google.com with SMTP id m17so8818124pgd.8 for ; Wed, 10 Jan 2018 08:16:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=e/G1X0/fwMu7eFBG37H4hkV1sCaXeIpvTXZxGlDxl4A=; b=ZV9azGnEH0bXkdNJjX4yTf1o8NCwBLz8QAOM5JJv3O3PIMahJ9iBOErrV2LyLaf6l+ yTXakv+ncS/2p5FpVz4YF0wgyNA1Q9q1dVNNB9fLC6yQxFOfm6V9nJIMqNYq2I/JIbN/ Grx81dA3niV3YiAI8X3C/JdwuI3SossF8ZxKdWCpKmz6PRRq/+LLJmP3IY/+OolukqUh /Sw5C43VPR29rBrw1VwD7OOMSbCLNBWFjYy4YTWMypwxd1ovCKjgjAluqXYyxvEVjFlb VTGPRi7oRxGbSIQSGg5oCaq7sBW62bEA0pA/Al153V7eM5zt+QvRpLlWAKW3HTlK4Go9 1/Sg== 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=e/G1X0/fwMu7eFBG37H4hkV1sCaXeIpvTXZxGlDxl4A=; b=bjNeVzSlA3jDhwYiwnjRNojhLobX16V7Rn/7kFsufF+jwE0wpxP7NCt2gXeLmiUEfD ZgcuzIlQ0CjZyxDbQ/A8FYgS8ET4S/jZmQWRiuz76QPECZp1ZOtIQFQwkuCXFEX+3/9y v8f5G03xumvsFfvgKQR3pHwD2UIeVS+NK/hdcd376NPkogdtTzFoghteIYMWXHjKjmG3 +z3qhIXrV18q8FLsl7fZw9ychRgycBQm6vtIvTrxFfghVLnNnLgRF+7nzNrLNPLneKFP voNxt1XsnPQps5KAMwS2SMB3CgMi0/sY/rJo0N+oP6+9jupoiVZ0yC/4lXlr3+Vidpml OkYQ== X-Gm-Message-State: AKGB3mJRDNG9svLB86Tfv/2xvkIN3bI2kRpWXWO/FiWxDL0RN4QHlW8T 5WJxyHM5oNrVd8Va4SPm1V4= X-Google-Smtp-Source: ACJfBotQVyWeOC3Iv2UUWqAsD+/FVxWn8jmslweceakbAAiCHpXgaEMhmx0pA0473rOH+TlUaHSShw== X-Received: by 10.98.236.93 with SMTP id k90mr7495851pfh.35.1515600986251; Wed, 10 Jan 2018 08:16:26 -0800 (PST) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id u21sm1382254pfl.114.2018.01.10.08.16.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Jan 2018 08:16:25 -0800 (PST) From: Andrey Smirnov To: Shawn Guo Subject: [PATCH 1/2] soc: imx: gpcv2: Do not pass static memory as platform data Date: Wed, 10 Jan 2018 08:16:07 -0800 Message-Id: <20180110161608.13015-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-20180110_081637_825196_2024B484 X-CRM114-Status: GOOD ( 15.65 ) 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 pass kzalloc'ed chunk of memory 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 --- This patch is a follow up to fix one of the bugs discussed in lkml.kernel.org/r/3f836677c6e98aaf01bc1ac8c3410083@agner.ch drivers/soc/imx/gpcv2.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c index afc7ecc3c187..001b64afa5c1 100644 --- a/drivers/soc/imx/gpcv2.c +++ b/drivers/soc/imx/gpcv2.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #define GPC_LPCR_A7_BSC 0x000 @@ -155,7 +156,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,7 +322,14 @@ static int imx_gpcv2_probe(struct platform_device *pdev) continue; } - domain = &imx7_pgc_domains[domain_index]; + domain = kzalloc(sizeof(*domain), GFP_KERNEL); + if (!domain) { + of_node_put(np); + return -ENOMEM; + } + memcpy(domain, &imx7_pgc_domains[domain_index], + sizeof(*domain)); + 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; @@ -330,6 +338,7 @@ static int imx_gpcv2_probe(struct platform_device *pdev) domain_index); if (!pd_pdev) { dev_err(dev, "Failed to allocate platform device\n"); + kfree(domain); of_node_put(np); return -ENOMEM; }