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: 549218 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id C7063140316 for ; Fri, 27 Nov 2015 06:02:27 +1100 (AEDT) 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-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -1.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 AWL AWL: Adjusted score from AWL reputation of From: address 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 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) {