From patchwork Mon Jan 22 15:07:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10178717 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 475D360353 for ; Mon, 22 Jan 2018 15:08:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B12126E5D for ; Mon, 22 Jan 2018 15:08:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FD0327F9F; Mon, 22 Jan 2018 15:08:47 +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 AF45F26E5D for ; Mon, 22 Jan 2018 15:08:46 +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=94KISCELsQZYKdJucUKDdntxOMaZLFfs5brIVIoaFjE=; b=Jsn GODSGpDLYw7uFTQRPVi9JtW1EEV/pWWcO45DRHcR6ZILTVoTD1Z+Av5z41yTtDLoNfM0sD6fqtoPW CQK7lyIIcJR710yGxOIgIIxqxnZVno3PuF0etOQ3M4NaF5QtOSMcfm8v5f0Pf0EthQGPloHyjG7fe dAboovQu5LHuLv9qalIOsrVMH1Ag8rA1ZrU8YrupBBl6iYEuj+tB/OMcTYNOkmNqgkKZC3wE+sAdq 4D/FHdscVh5o29zPqOCEUd1eyo+4teaaNaO5sLhpDC4+yat4oU99REPQBJAIjfRSGsuwvkBc2SdGh 1GznvpGt83Z9cGAASf9b7vUbKv/ac/w==; 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 1eddiE-00051H-ND; Mon, 22 Jan 2018 15:08:42 +0000 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eddiB-0004vL-Af for linux-arm-kernel@lists.infradead.org; Mon, 22 Jan 2018 15:08:40 +0000 Received: by mail-pg0-x241.google.com with SMTP id q67so7291019pga.9 for ; Mon, 22 Jan 2018 07:08:28 -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=dJObjZ+VgmSM7Rt6rjBXj0pA2ou7te07HIo+5e/dvhg=; b=EbvXofIn5+Jj3MIilCQkjHeRHk+x03imtX0Yr6a37qnKjz0mo5oAH9G+Ghz7wDrxry afqEl+JMU6PHKPJ/omZfVq2/wtpVnuzwwnrKgT3RJSBqo+foAjBFnGK/b8BdkGtLmccM VbbLDpsY11ZfbDYWVNjYZwyXLO9yfdqIMBP0HctJCnKhyaio/1jqoF2wcEGFILT/Rmjf V23/+cc+QHo23dGMGQXDQYPYYpHDsvBBEDvg6WmziLe9T4Dgw1LCyJIct/7aPQt/ZIIE o8sySuHA22slex1d6+xjE97LMqWtXGttPAGw4nKzSRdwAB2t+WM3LWApgvOFxV+P0zgm 8niQ== 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=dJObjZ+VgmSM7Rt6rjBXj0pA2ou7te07HIo+5e/dvhg=; b=r0vcGFSQIWl2vJLEfRLoanPqqmQfOK3TPgNw7Mlbn9JGUxc2zGeZdsa1RWmtd7smu/ t4lv7cBkRWQdXcJp4cAEPeVX3YDL0d2Bnkys1M5nrORWWL30wCtCAT9yx3TTwKyV4s5R 0LqyMjvyDoe6PsJb7JJUb16G5vKMx14tqNrLxgBZSiad9vqv4ByhtDL9zeOzpn4uCOJ9 1W4YYi50NrnGgcg3QkAoBgGFjp23cQ0qKZbrnG+P7m1pE9od+lBudirPjT4PmQ+JEY6K yb3UqOMG7DG/CrehqzDg6Mja3ka2ZxshDkeKFeIokGbbJP8NpafL1i5w4SsJrFAm2W6n 3YsA== X-Gm-Message-State: AKwxytfvBDNHTNamlHGaeDTgItMvL3DCytjSUowPqhpoPLOK3KmO4Kv8 eyf5xQQ/LNP0x2gKzTL1L5+TkiOm X-Google-Smtp-Source: AH8x22772RjW02NJvH3syt1f5nsHBLHrgG/PIAf0+WaiD21oJ+2IYZv1TRBBUQ/SemUidWJhObwLKg== X-Received: by 10.99.124.24 with SMTP id x24mr7391106pgc.351.1516633707567; Mon, 22 Jan 2018 07:08:27 -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 14sm1037604pfn.125.2018.01.22.07.08.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Jan 2018 07:08:26 -0800 (PST) From: Andrey Smirnov To: Shawn Guo Subject: [PATCH v2 1/2] soc: imx: gpcv2: Do not pass static memory as platform data Date: Mon, 22 Jan 2018 07:07:47 -0800 Message-Id: <20180122150748.1742-1-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.14.3 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 --- Changes since [v1]: - Replaced devm_kzalloc() with devm_kmalloc() as per suggestion from Stefan [1] lkml.kernel.org/r/20180110161608.13015-1-andrew.smirnov@gmail.com 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..9947598ec4b5 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 = kmalloc(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; }