From patchwork Mon Jan 22 15:07:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10178721 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 584B460353 for ; Mon, 22 Jan 2018 15:08:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D2B826E5D for ; Mon, 22 Jan 2018 15:08:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3192B27F9F; Mon, 22 Jan 2018 15:08:57 +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 C8E1C26E5D for ; Mon, 22 Jan 2018 15:08:56 +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=DHdjRshHIHmtqy5kdAwXvIpDWu2OqIEY/8Xw2D7Gyog=; b=R9IZfueomcf/M31r8kQkL5uhB3 28j/ckT6GIDzW1Iz/bxhLjH8rq6FXyr4gXwBZZ4LBmSJxyobYy44RqfQ8jP9THkoNFzQHWTUQfI7Y D8ZT0iza514GszrHS0xin+9ER9NaskZqS1YQ789oMoIjd+kGH5x8defAmrFgf2S0+0YzP56MhnyXp o8+Yn6En/EYyj7l1KZoPpdWtyWJwRTG4Jmb/zHs6qQh7qf4iwAH4N4M8PeGR67hRN9JS0kVFkFLjN RcpGepVwYOWRcFTFbHGKdrtbNRUHM+sXmsLGvytiNMI26ZLNqfqRMLcRNqMOX9IOp8RVqcIsuPGwG A5X4Kd9g==; 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 1eddiP-0005Cx-AI; Mon, 22 Jan 2018 15:08:53 +0000 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eddiB-0004vR-KA for linux-arm-kernel@lists.infradead.org; Mon, 22 Jan 2018 15:08:41 +0000 Received: by mail-pg0-x242.google.com with SMTP id s9so7281009pgq.13 for ; Mon, 22 Jan 2018 07:08:29 -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=jXZPPHn48+bXdxFF4T4zfYCFnnH/gFgNhuLrL0mExuw=; b=Cz7ZUtkheQiZAx4eApSJta3YGgrKA17XFtW5jQ/yiAZkmXO8pQPpibfff7MagHAcUr 3E4aLyruiE97yjPgAj8Uj/pS6WDzlA0U2YvmDG16dyE8bmQFdEiry0m9PwtOy/n3ip4d raBwJF9ON37cgdkPdYu8Y+ssIkHZt9Z4B+mhfl46pcqC0TQnGYYqvWP0M8oAA736dZJ0 jMCXGEgfWBmtoW6qCjA0xmKcwZC81rE/KwkmuRxbN9bAtLfjr9vTpoh7BhGe0MvzFJcK sMTVg3jftKOZGOoo2DjvCU0Zobq9JhVi4d+GAeKU/cq/nVBwhocLZCO3dccJxrDhWwtJ JsKw== 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=jXZPPHn48+bXdxFF4T4zfYCFnnH/gFgNhuLrL0mExuw=; b=U7p3/+ORboUx+qMxK9nUlLSIHDI6Bg/dIra0SoC50VsZGfWYj8pwO94GGbU6fIKcSA DR5DxEAYeOPxMd8ypv+kJSPB1Hx19Te4c2SgwIossPHp1B+MjwqKBWOLvgWYPxGSFe1W iPSLRF/wWwYOSzOkfpPs4niFdgy/iX//gAjpknr7XfQ1Mfv7ufccLJky0HTiJbf5C4v1 lVuIed6wxhZKoF8qZXoG7mH6OH0fBMflWOqhBNe5uYqJbITq4HNBz5mrAIz4aZeXzfsa HkheE1S2azLpmZcQ9D0OnJnSvf6MKDC9cvSV1hF6O4vtjLK5fbWEtbSVFjnfNlm3B9s7 46Nw== X-Gm-Message-State: AKwxyteMlFCczemlo5AWGpd3YByoLYUBcYkKEu4SeIywqFDbNEuELF7+ ftbONqIQonVd33BckGisXPIvPhyg X-Google-Smtp-Source: AH8x2260jGk9ia6KSQ7d8O51o380gh+NxW9xUViAFl3XmABbnII56BEsDzeCXxrRNOixYjI4vSNHGQ== X-Received: by 10.101.71.202 with SMTP id f10mr7634925pgs.208.1516633708835; Mon, 22 Jan 2018 07:08:28 -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.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Jan 2018 07:08:28 -0800 (PST) From: Andrey Smirnov To: Shawn Guo Subject: [PATCH v2 2/2] soc: imx: gpc: Do not pass static memory as platform data Date: Mon, 22 Jan 2018 07:07:48 -0800 Message-Id: <20180122150748.1742-2-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180122150748.1742-1-andrew.smirnov@gmail.com> References: <20180122150748.1742-1-andrew.smirnov@gmail.com> 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 --- Changes since [v1]: - Replaced devm_kzalloc() with devm_kmalloc() as per suggestion from Stefan [1] lkml.kernel.org/r/20180110161608.13015-2-andrew.smirnov@gmail.com 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..769aae647fed 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 = kmalloc(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; }