From patchwork Fri May 18 16:59:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 916476 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40nZ9d5WYsz9s33 for ; Sat, 19 May 2018 02:57:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751405AbeERQ5z (ORCPT ); Fri, 18 May 2018 12:57:55 -0400 Received: from mga07.intel.com ([134.134.136.100]:39810 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751184AbeERQ5w (ORCPT ); Fri, 18 May 2018 12:57:52 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 May 2018 09:57:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,415,1520924400"; d="scan'208";a="42389084" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.44]) by orsmga008.jf.intel.com with ESMTP; 18 May 2018 09:57:51 -0700 From: Keith Busch To: Bjorn Helgaas , Linux PCI , Christoph Hellwig Cc: Johannes Thumshirn , Ming Lei , Keith Busch Subject: [PATCH] PCI: Prevent users from disabling devices in use Date: Fri, 18 May 2018 10:59:53 -0600 Message-Id: <20180518165953.30848-1-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This patch returns busy status if a user tried to alter the enabled status of a device owned by a driver. There is no good reason to provide a convenient method to a user for altering the fundamental state of a pci device out from under a driver using it. Signed-off-by: Keith Busch --- drivers/pci/pci-sysfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 366d93af051d..7ff3a3dce641 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -287,6 +287,8 @@ static ssize_t enable_store(struct device *dev, struct device_attribute *attr, /* this can crash the machine when done on the "wrong" device */ if (!capable(CAP_SYS_ADMIN)) return -EPERM; + if (pdev->driver) + return -EBUSY; if (!val) { if (pci_is_enabled(pdev))