From patchwork Tue Apr 10 18:32:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10333665 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 2830F60365 for ; Tue, 10 Apr 2018 18:44:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16CC027FA3 for ; Tue, 10 Apr 2018 18:44:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B9BD27FB3; Tue, 10 Apr 2018 18:44:09 +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 A1A1D27FA3 for ; Tue, 10 Apr 2018 18:44:07 +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=0sqMqoqDXlQUe9ccupeF8cMn3GHKissMYUpbCGMOTkQ=; b=pgc+3ixiNUtxbiu5B5Rh2mkXXo G7X+ofwKPedEzLg2bFrdluDBp5ZBruYVtML2mrrEyOHFAvmHA7lzkPaHoLLeYleNcIz2SfVF5viws dY90YkuVJ/jEI/HaY2WTYG0zLeP5oSfr0uv3w9QBNqW6ov6PViETgFhnRhnZ3PZ8mj1Yf/ot7m5fs ZNfZMtxRGq9spUPbXTrVv2WC+OPwfsRpkxSEQXYAWaexnFiRswb84NgQP0eOwz/Bd6NcDXzrWzK6O ufUX5FAan04EDLTVqodTQqCSqXOnWfrfRgHWgrJSr5VVJDyv4+5qBdKRmZIst+fZ9p3cx4v8ijVCV AMfbl5JA==; 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 1f5yFJ-0002uL-4X; Tue, 10 Apr 2018 18:43:57 +0000 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5y6f-0001z8-Uq for linux-arm-kernel@lists.infradead.org; Tue, 10 Apr 2018 18:35:37 +0000 Received: by mail-pl0-x241.google.com with SMTP id bj1-v6so8061828plb.8 for ; Tue, 10 Apr 2018 11:34:51 -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:in-reply-to:references; bh=M5whOfFuNDnZdGoTOCjvWtUqTxW5+ohsZIIQFJXTwWU=; b=vYIDptJj7hsuPDczFvpnDElQRqjTo0ZnBR9S8B+JvpkB0IkSFRezbHFoUpZ5qPEUV6 JF/sEmnYzXOjJ2DbpA6qZrrOJwN3/RBzD5ogpx00iRV3QS6mmcUqtRdQsnltZjZmN3tF lwQxQ8fMzbM5DK8uAWg5t4nQ9uqAMURBjes7TTFUDUpWY472p26NtmXya9nGXeQsRIsn 45YSyfOC2Q4P2ZX70rMrTJ0HnXc6oTax0rdJe2UphyxlUlU8cUeOzcVdl8WWpYE7ZV2i ZkdtyE613l05vU8Wk9z9HIulpoEDKLUUYHPbgggG293Fxp6J8l3140rY/cgSM79fSzYE /1LQ== 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=M5whOfFuNDnZdGoTOCjvWtUqTxW5+ohsZIIQFJXTwWU=; b=QJQCsVAA4Z1e7cDfk1dAbInVuTO+oxu7hTSX9Gu5dyQeWDgMRAKhFbw3ffkOpZxZ80 DQzwEW9Ii2iNKXG7h+5Sc0co8trqrXa7h0Nn+cDUlmHE9hAudFy3SGcj55OV+5/Bvbtu hDsgSTk7gtINgLB0cExnM12tUppiTQl7XrPrMezQ5SAjvYfq2zK8GBQwimxSe5RoZCNp XQLIeqUrJD/Vgcr9Y9lxH5TUMVo2ncb3nSd3nRU3fZfy8sZsIbt5ygT5f8yr1jaFpOgf DPGB4PJSFAuI2zYSzBAdIYMh1XBhXRadD38jtR9/J57tOuzewT6C7Wr1ppB3p3zYazu5 pdAA== X-Gm-Message-State: ALQs6tDVmHGU9w9AeKg3pKfzle4wKZfptlEK6FdsfAFr45NXmLp8G6ns AhzwXpaBKflfNeO7CWTt9ks= X-Google-Smtp-Source: AIpwx48RlA73ghD0ytL+uqLq+7pwIB1dU8/l3iYPDBtv1u3fWGuwDly4OFkR9yj9/TEd+oWHjktt3w== X-Received: by 2002:a17:902:4003:: with SMTP id b3-v6mr1603140pld.15.1523385290759; Tue, 10 Apr 2018 11:34:50 -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.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Apr 2018 11:34:49 -0700 (PDT) From: Andrey Smirnov To: Shawn Guo Subject: [PATCH v3 2/2] soc: imx: gpc: Do not pass static memory as platform data Date: Tue, 10 Apr 2018 11:32:10 -0700 Message-Id: <20180410183210.28052-2-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180410183210.28052-1-andrew.smirnov@gmail.com> References: <20180410183210.28052-1-andrew.smirnov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180410_113502_081014_67DBE1E0 X-CRM114-Status: GOOD ( 16.60 ) 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() 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 [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-2-andrew.smirnov@gmail.com [v2] lkml.kernel.org/r/20180122150748.1742-2-andrew.smirnov@gmail.com drivers/soc/imx/gpc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/soc/imx/gpc.c b/drivers/soc/imx/gpc.c index c4d35f32af8d..32f0748fd067 100644 --- a/drivers/soc/imx/gpc.c +++ b/drivers/soc/imx/gpc.c @@ -443,17 +443,25 @@ 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->regmap = regmap; - domain->ipg_rate_mhz = ipg_rate_mhz; - pd_pdev = platform_device_alloc("imx-pgc-power-domain", domain_index); if (!pd_pdev) { of_node_put(np); return -ENOMEM; } - pd_pdev->dev.platform_data = domain; + + ret = platform_device_add_data(pd_pdev, + &imx_gpc_domains[domain_index], + sizeof(imx_gpc_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->ipg_rate_mhz = ipg_rate_mhz; + pd_pdev->dev.parent = &pdev->dev; pd_pdev->dev.of_node = np;