Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp362282rdb; Tue, 23 Jan 2024 01:49:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQ0TiIRn85m74zYFMK6AhbLw/Ko1FxCLZ+UJkg11YALPO8dcnWq6VE95UodzKDvs9YrbJH X-Received: by 2002:a0c:cc0a:0:b0:686:9ea7:b2e with SMTP id r10-20020a0ccc0a000000b006869ea70b2emr531178qvk.34.1706003388122; Tue, 23 Jan 2024 01:49:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706003388; cv=pass; d=google.com; s=arc-20160816; b=ZunR0SaJJixuOVb0xcCRAQg/pbe6FTq4xRwSEXPp6P9wB4BbNv8deIyyiAZiqOlTFT 4BP0nwHwximYlHfMQq6FUcODsxlm7Yxlebbzjoxsi2Jem6XqHedQoPINT+1Lz+Oml/iF 2v7YgWSmEE97vVLWKxRWpy84Nxa0XQ77YzbjkIJe89wBbzFlwbMwT6fCpgIzUp7OGx0R Oze8QmAfp+2WyafIMmiDxB6pEDKjv8QFXlcWFPM4nmng8d4QXQIMixA/PKtSo5lvo6Gr 9SttzBpW/TBCY6yXvh+l0YeA6JPDqfweBxlWd3HGCO+aCTQ8hjiaZvjnXSr6+7KbfX3e pp2A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=n8ldR1APM7FCb8Va/7W7rWsZ/5PXg9NQPlDweLxrFR8=; fh=AY1J9PDScN0xrIvhrMJy8TMRSbPeq4owI1m0lsalYQU=; b=D47BS6tOl6hPGhJEEorB8bsWAHOwQ5qOKnJMjU6V2aflqzULIhBCU18SARLSAPxbND ibw2IFh31YsnVGigYvxKbvviL31ja1guwo6RfGpswXhU2BoDiOjLfACgV+Nn95AM2esI pavXgaMaD7niLUHkrmYLK0TnfqDxE/cPHwSlDNyS/WyV45PAeqyMTJkkLVAql+mpx3/h K8MWzmi83koYp9BXtx9LSESoYLl8oBPu2szaSY8xoT7xRl77O3TDoHvPmMsdN7QreyN2 v+HSblmFOzK3sGed3RfsUj3O+r+/8IRfa7DkRHXKah4ANPnVp+Xy3THvWmgfjfYsU9op uEYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KuXEKh6P; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-35031-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35031-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n11-20020a05620a222b00b00783792339f5si7233210qkh.50.2024.01.23.01.49.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 01:49:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35031-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KuXEKh6P; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-35031-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35031-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BED391C2201C for ; Tue, 23 Jan 2024 09:49:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 633215F858; Tue, 23 Jan 2024 09:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KuXEKh6P" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 099965F86E for ; Tue, 23 Jan 2024 09:45:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706003110; cv=none; b=FWrawKfjBHqDgqINSekdVKiVKQK1rLM0kFeAYx186AAweL0edJRPDzm1lq4eXnYVsm0+2kQFirVkOxXx+tWDjZYjEAQWt0eGF1pI7bGgETl+sVKaMDqvRl0S9vnaIVao6tLpAqvE8SA8c8/Rv4d8Olj/7no7Gil1GMQz7LhK1Zc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706003110; c=relaxed/simple; bh=q2R0g7Hy2U3uiquhdJnwowChrgBPdiPXucNQWzskgyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C94nfq1Cp+eTqfOC2wFlwMt73OpMSp3PnEj0rmlkWWXFQCDVUxffZJmdhBfrdJnvAi3/Wi818Tyqw9Ma+aUl9HLbbIe54XPeqpZ2C0sM265ezjAxQdECwQpMzD3XosV2AryBkMuGqZJc7k3S2IYtNNtMeHhwPFZMA0VeoNZuPr8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KuXEKh6P; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706003108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n8ldR1APM7FCb8Va/7W7rWsZ/5PXg9NQPlDweLxrFR8=; b=KuXEKh6Pzz35ynpJAK06nvAGnEdSMLah4Lc2r2Ig5GM8KNhvsdFSVzMg+Ubk7mXSI+KOT5 1Qd4Th7YLqgZhUGlCcnvl3OWSwKatRWrUbHUvVfyXxvUMvltFCubroPEqgrKDiVPA+Viwr dGTqCDho+YG0IhuQiOlI5l3yWw/h+IU= Received: from mail-vs1-f70.google.com (mail-vs1-f70.google.com [209.85.217.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-46-q4U8t4FvMzS7VZcTLW9rig-1; Tue, 23 Jan 2024 04:45:06 -0500 X-MC-Unique: q4U8t4FvMzS7VZcTLW9rig-1 Received: by mail-vs1-f70.google.com with SMTP id ada2fe7eead31-46a9d50a8b4so216873137.1 for ; Tue, 23 Jan 2024 01:45:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706003105; x=1706607905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n8ldR1APM7FCb8Va/7W7rWsZ/5PXg9NQPlDweLxrFR8=; b=S9FK4Qq1d7uDAYOzjcj6V/bgdyIW4vyilsrKgg8m/J997gD3iec6cYVay2L4O3SaW8 3KFROu5bEQGaX8q1Uo8fPt3RmKAJckfXh6y0fsZV2mTO2R+G1YzzKQuvG05ol5RBP5Ry EcUBsAsZ5pLAh7Z7/k9BFggovYgyHQsmYL5nvievZMIdyEG60FXH9jgotc5upBVKSUz3 qF3D1FuQ84tl0teLTkBfVIvwoo2zh6t+6PefhlHm7lRci6l8j6W8zV/EDn5eJiFI+R6K uaE3JWm3iusFxrszZapqR6h16MSS1858UjNANV2kvlOqJ65qacwS/pALDiqVLqNrT6U5 mkEw== X-Gm-Message-State: AOJu0YxKVRZVBLBusGhU6bsYkXJx1vD+0WFIxArgwUDpSUwXZO/MF/x9 PhOzW4qTekruTr+S0bIaPDc3Ui1ElEI99CTBEciJ1LJoqPRsGv9XrhRBkoWft0eoOvlafa3SFcl ij2fsgJWukz3Pd/Ja96U4LfVHE1gtiM6A+agComsXuUS1qGROt/sa0CWgx4Eu77FM/LMedQ== X-Received: by 2002:a05:6102:5493:b0:469:b7ba:85e2 with SMTP id bk19-20020a056102549300b00469b7ba85e2mr3802818vsb.1.1706003105398; Tue, 23 Jan 2024 01:45:05 -0800 (PST) X-Received: by 2002:a05:6102:5493:b0:469:b7ba:85e2 with SMTP id bk19-20020a056102549300b00469b7ba85e2mr3802807vsb.1.1706003105097; Tue, 23 Jan 2024 01:45:05 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.muc.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id nc5-20020a0562142dc500b00685e2ffcaf5sm2958704qvb.38.2024.01.23.01.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 01:45:04 -0800 (PST) From: Philipp Stanner To: Jonathan Corbet , Hans de Goede , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Bjorn Helgaas , Philipp Stanner , Sam Ravnborg , dakr@redhat.com Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org Subject: [PATCH v2 09/10] PCI: remove legacy pcim_release() Date: Tue, 23 Jan 2024 10:43:06 +0100 Message-ID: <20240123094317.15958-10-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240123094317.15958-1-pstanner@redhat.com> References: <20240123094317.15958-1-pstanner@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Thanks to preceding cleanup steps, pcim_release() is now not needed anymore and can be replaced by pcim_disable_device(), which is the exact counterpart to pcim_enable_device(). This permits removing further parts of the old devres API. Replace pcim_release() with pcim_disable_device(). Remove the now surplus function get_pci_dr(). Signed-off-by: Philipp Stanner --- drivers/pci/devres.c | 49 +++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index 4314d0863282..f368181c6c92 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -463,48 +463,41 @@ int pcim_intx(struct pci_dev *pdev, int enable) return 0; } -static void pcim_release(struct device *gendev, void *res) +static void pcim_disable_device(void *pdev_raw) { - struct pci_dev *dev = to_pci_dev(gendev); - - if (!dev->pinned) - pci_disable_device(dev); -} - -static struct pci_devres *get_pci_dr(struct pci_dev *pdev) -{ - struct pci_devres *dr, *new_dr; - - dr = devres_find(&pdev->dev, pcim_release, NULL, NULL); - if (dr) - return dr; + struct pci_dev *pdev = pdev_raw; - new_dr = devres_alloc(pcim_release, sizeof(*new_dr), GFP_KERNEL); - if (!new_dr) - return NULL; - return devres_get(&pdev->dev, new_dr, NULL, NULL); + if (!pdev->pinned) + pci_disable_device(pdev); } /** * pcim_enable_device - Managed pci_enable_device() * @pdev: PCI device to be initialized * - * Managed pci_enable_device(). + * Returns: 0 on success, negative error code on failure. + * + * Managed pci_enable_device(). Device will automatically be disabled on + * driver detach. */ int pcim_enable_device(struct pci_dev *pdev) { - struct pci_devres *dr; - int rc; + int ret; - dr = get_pci_dr(pdev); - if (unlikely(!dr)) - return -ENOMEM; + ret = devm_add_action(&pdev->dev, pcim_disable_device, pdev); + if (ret != 0) + return ret; - rc = pci_enable_device(pdev); - if (!rc) - pdev->is_managed = 1; + /* + * We prefer removing the action in case of an error over + * devm_add_action_or_reset() because the later could theoretically be + * disturbed by users having pinned the device too soon. + */ + ret = pci_enable_device(pdev); + if (ret != 0) + devm_remove_action(&pdev->dev, pcim_disable_device, pdev); - return rc; + return ret; } EXPORT_SYMBOL(pcim_enable_device); -- 2.43.0