From patchwork Wed Jan 10 16:16:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10155535 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 9002560231 for ; Wed, 10 Jan 2018 16:16:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8149F28522 for ; Wed, 10 Jan 2018 16:16:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 755F328534; Wed, 10 Jan 2018 16:16:55 +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=ham 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 25D6328522 for ; Wed, 10 Jan 2018 16:16:55 +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:References: In-Reply-To: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:List-Owner; bh=vyIkMIJh1poxixDVRUjjIVYlCnTpHjPZOuKwHMpbqpg=; b=OtAlimnOeSWoqPI3cWtORWOb+h 9mvVNTttNrbiPt0UNzIXewEhrEnahUqWQipQuUOquNOmyDIXs4rpL7VKUhbiYkPAERiVuzxYGjzsW lFBTcbxxOTKCNkjaGKsQUWrURhu+iSkrNsNfHLKfe5ppE/mIuwORy964EZxN8HXNCiIkmkomnLAYD IrUoRypFnej7lBtxNqywwngeVy7e6Je5JmkRonwGtv7Wjx5PiYL2JRMbCBDaI8hez8hfDi1jpX4DM /+NeyDGmVqqmNM74elMHI87lEVT4bxg7xKSbzHPzQVzT85rLhMAK25hQofoZJKQxHVqzoB+bwZ+c7 mnVjzPeA==; 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 1eZJ3d-0007bL-1n; Wed, 10 Jan 2018 16:16:53 +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-0007MK-Mr 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 j4so11181068pgp.1 for ; Wed, 10 Jan 2018 08:16: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:in-reply-to:references; bh=MkIAMYdzjb2y9/Z1ogV3A4Gseo80YYzCelFTJndNtTc=; b=g6oM31JGLXUDMdWMRITy6PSqyOb/xV/WlRf5b9IaBpmGiYoX0VFHPkiXy96YF+JrZW 6RwVRn2TCe79N4l2JWzOjC5tlmqS3ECgsqu0q2lxmH4CHXokxu9uN788Kf6ybmVn2gmI jeEFznnUnAJmHU57LV1I4SyVBS1tDc3oR7sXdxLBta4snHyNXnMRF5UkLPsae2NXPYy9 jivGJxQ1hfmzHW7nGCUmwujBs8K5QeuvUZIB9FuYhFM5EGGvZv0DlsCM1lXQTsySkSf7 40RADqFJfSFE4zE5s4Bi5nUzqdGuFKmuLg3cmfZtGMLzDL7IAZk2bwVt1ndP3x5ggqVN 74lQ== 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=MkIAMYdzjb2y9/Z1ogV3A4Gseo80YYzCelFTJndNtTc=; b=HBcS8662mXGYoVP7OxHpx7AtVZpgQPAW+bKfABdBGkZFPFZk4ENLz4gdUrjpDFXjQe YeRZ+/7EwbmHFvEkQh10P7OHFgdzNnPC2vxdLvv2N33Mog+7gPD7RWGIjvJKp9On4RCS 3VQY9FF9ITEq/ppDWMC82GC0C1nDh3yZNBcpKMojSafBY8DDLx6gtnkIVraVClYWtqYF 5G2HgZFc3me91fdf9K1a+KQhDik243TfKdQSo2HzgrVyY5LhtbXuSskGWhDi5HOagRBw Cg6oVWETKBiZeO0WHvBLm0yJqc8XTPo8xt5EQUq8e5/t5VQkTvEHy88XQGsXMSwMDfnh yEpQ== X-Gm-Message-State: AKGB3mJyLNmFQ/yXXbArC0myDCKypSiwT3YGvzivisYpg/jOmmhZ3pOX 2OtVt+cFQoEwOzVyuQBXlh8= X-Google-Smtp-Source: ACJfBoseolN0kN2pTsi1H8uF+bLlisGQMrhQFR3QaN/MR4gTkjvuctUwPXqyRI0wXNVC8cYIYhJ0Hw== X-Received: by 10.98.156.29 with SMTP id f29mr7386268pfe.109.1515600987467; Wed, 10 Jan 2018 08:16: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 u21sm1382254pfl.114.2018.01.10.08.16.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Jan 2018 08:16:26 -0800 (PST) From: Andrey Smirnov To: Shawn Guo Subject: [PATCH 2/2] soc: imx: gpc: Do not pass static memory as platform data Date: Wed, 10 Jan 2018 08:16:08 -0800 Message-Id: <20180110161608.13015-2-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180110161608.13015-1-andrew.smirnov@gmail.com> References: <20180110161608.13015-1-andrew.smirnov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180110_081637_762712_52DC46B9 X-CRM114-Status: GOOD ( 13.72 ) 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 452). 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/gpc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/soc/imx/gpc.c b/drivers/soc/imx/gpc.c index 47e7aa963dbb..ec8b79abebac 100644 --- a/drivers/soc/imx/gpc.c +++ b/drivers/soc/imx/gpc.c @@ -18,6 +18,7 @@ #include #include #include +#include #define GPC_CNTR 0x000 @@ -428,13 +429,19 @@ static int imx_gpc_probe(struct platform_device *pdev) if (domain_index >= of_id_data->num_domains) continue; - domain = &imx_gpc_domains[domain_index]; + domain = kzalloc(sizeof(*domain), GFP_KERNEL); + if (!domain) { + of_node_put(np); + return -ENOMEM; + } + memcpy(domain, &imx_gpc_domains[domain_index], sizeof(*domain)); domain->regmap = regmap; domain->ipg_rate_mhz = ipg_rate_mhz; pd_pdev = platform_device_alloc("imx-pgc-power-domain", domain_index); if (!pd_pdev) { + kfree(domain); of_node_put(np); return -ENOMEM; }