From patchwork Fri Nov 1 19:34:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Cameron X-Patchwork-Id: 3127271 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5CA3C9F432 for ; Fri, 1 Nov 2013 19:35:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7E855204AF for ; Fri, 1 Nov 2013 19:35:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 679E520414 for ; Fri, 1 Nov 2013 19:34:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751612Ab3KATe6 (ORCPT ); Fri, 1 Nov 2013 15:34:58 -0400 Received: from g4t0017.houston.hp.com ([15.201.24.20]:8682 "EHLO g4t0017.houston.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751086Ab3KATe5 (ORCPT ); Fri, 1 Nov 2013 15:34:57 -0400 Received: from g9t2301.houston.hp.com (g9t2301.houston.hp.com [16.216.185.78]) by g4t0017.houston.hp.com (Postfix) with ESMTP id E888D3800B; Fri, 1 Nov 2013 19:34:56 +0000 (UTC) Received: from beardog.cce.hp.com (beardog.cce.hp.com [16.84.84.24]) by g9t2301.houston.hp.com (Postfix) with ESMTP id D708E5C; Fri, 1 Nov 2013 19:34:55 +0000 (UTC) Received: from beardog.cce.hp.com (beardog.cce.hp.com [127.0.0.1]) by beardog.cce.hp.com (8.13.8/8.13.8) with ESMTP id rA1JYtTA018709; Fri, 1 Nov 2013 14:34:55 -0500 Subject: [PATCH] PCI: warn on driver probe return value greater than zero To: bhelgaas@google.com From: "Stephen M. Cameron" Cc: axboe@kernel.dk, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, stephenmcameron@gmail.com, thenzl@redhat.com, akpm@linux-foundation.org Date: Fri, 01 Nov 2013 14:34:55 -0500 Message-ID: <20131101193455.18686.92302.stgit@beardog.cce.hp.com> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, 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: Stephen M. Cameron Ages ago, drivers could return values greater than zero from their probe function and this would be regarded as success. Commit f3ec4f87d607f40497 "PCI: change device runtime PM settings for probe and remove" slightly altered this in 2010, and commit 967577b062417b4e4b8e27b "PCI/PM: Keep runtime PM enabled for unbound PCI devices" in late 2012 altered it more signficantly, setting pci_dev->driver to NULL if the driver's probe function returned a value greater than zero, which would for example prevent the driver's remove function from being called on rmmod. Neither of those changes would necessarily make the driver fail in an obvious way though, and so at least a couple drivers (cciss, hpsa) fell into this hole since they were returning 1, and this situation went unnoticed for quite some time. If a driver's probe function returns a value greater than zero, issue a warning, but otherwise treat this as success. Signed-off-by: Stephen M. Cameron --- drivers/pci/pci-driver.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 98f7b9b..7fbe343 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -264,11 +264,19 @@ static long local_pci_probe(void *_ddi) pm_runtime_get_sync(dev); pci_dev->driver = pci_drv; rc = pci_drv->probe(pci_dev, ddi->id); - if (rc) { + if (!rc) + return rc; + if (rc < 0) { pci_dev->driver = NULL; pm_runtime_put_sync(dev); + return rc; } - return rc; + /* + * Probe function should return < 0 for failure, 0 for success + * Treat values > 0 as success, but warn. + */ + dev_warn(dev, "Driver probe function unexpectedly returned %d\n", rc); + return 0; } static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,