From patchwork Thu Nov 26 19:01:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 7708751 Return-Path: X-Original-To: patchwork-tpmdd-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BE6C19F1D3 for ; Thu, 26 Nov 2015 19:02:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DB6F720654 for ; Thu, 26 Nov 2015 19:02:23 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CE8B220652 for ; Thu, 26 Nov 2015 19:02:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1a21oD-0003FB-MB; Thu, 26 Nov 2015 19:02:21 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1a21oC-0003Eq-0h for tpmdd-devel@lists.sourceforge.net; Thu, 26 Nov 2015 19:02:20 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of ts.fujitsu.com designates 80.70.172.51 as permitted sender) client-ip=80.70.172.51; envelope-from=martin.wilck@ts.fujitsu.com; helo=dgate20.ts.fujitsu.com; Received: from dgate20.ts.fujitsu.com ([80.70.172.51]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1a21oA-00028x-IW for tpmdd-devel@lists.sourceforge.net; Thu, 26 Nov 2015 19:02:19 +0000 X-SBRSScore: None Received: from unknown (HELO abgdgate60u.abg.fsc.net) ([172.25.138.90]) by dgate20u.abg.fsc.net with ESMTP; 26 Nov 2015 20:02:11 +0100 Received: from unknown (HELO pdbcooper.pdb.fsc.net) ([172.25.111.126]) by abgdgate60u.abg.fsc.net with ESMTP; 26 Nov 2015 20:02:12 +0100 Received: from pdbcooper.pdb.fsc.net (localhost [127.0.0.1]) by pdbcooper.pdb.fsc.net (8.14.9/8.14.8) with ESMTP id tAQJ25GH023277; Thu, 26 Nov 2015 20:02:05 +0100 From: martin.wilck@ts.fujitsu.com To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Date: Thu, 26 Nov 2015 20:01:34 +0100 Message-Id: <1448564494-23218-1-git-send-email-martin.wilck@ts.fujitsu.com> X-Mailer: git-send-email 2.1.0 X-Spam-Score: -2.5 (--) X-Headers-End: 1a21oA-00028x-IW Cc: Martin Wilck , tpmdd-devel@lists.sourceforge.net, u.kleine-koenig@pengutronix.de Subject: [tpmdd-devel] [PATCH] base/platform: fix panic when probe function is NULL X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, HK_RANDOM_ENVFROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Wilck Since b8b2c7d845d5, platform_drv_probe() is called for all platform devices. If drv->probe is NULL, and dev_pm_domain_attach() fails, platform_drv_probe() will return the error code from dev_pm_domain_attach(). This causes real_probe() to enter the "probe_failed" path and set dev->driver to NULL. Before b8b2c7d845d5, real_probe() would assume success if both dev->bus->probe and drv->probe are missing. This may cause a panic later. For example, inserting the tpm_tis driver with parameter "force=1" (i.e. registering tpm_tis as a platform driver) will panic in tpmm_chip_alloc() because dev->driver is NULL: chip->cdev.owner = chip->pdev->driver->owner; This patch fixes this by returning success in platform_drv_probe() if "just" dev_pm_domain_attach() had failed. This restores the semantics of platform_device_register_XXX() if the associated platform driver has no "probe" function. Fixes: b8b2c7d845d5 ("base/platform: assert that dev_pm_domain callbacks are called unconditionally") Signed-off-by: Martin Wilck Acked-by: Jarkko Sakkinen --- drivers/base/platform.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 1dd6d3b..c994e76 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -513,10 +513,14 @@ static int platform_drv_probe(struct device *_dev) return ret; ret = dev_pm_domain_attach(_dev, true); - if (ret != -EPROBE_DEFER && drv->probe) { - ret = drv->probe(dev); - if (ret) - dev_pm_domain_detach(_dev, true); + if (ret != -EPROBE_DEFER) { + if (drv->probe) { + ret = drv->probe(dev); + if (ret) + dev_pm_domain_detach(_dev, true); + } else + /* don't fail if just dev_pm_domain_attach failed */ + ret = 0; } if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {