Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1825098lqz; Mon, 1 Apr 2024 20:30:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/3xjZQEjcRG8nIukp3YS/No0nw5OkOg7npix9tE5GIWf/i7APmwv6LZ7aLawHGP2WEv4BTHhC9Du26vwyJvQp1P3NktTS9SX9YIYgjA== X-Google-Smtp-Source: AGHT+IHwa1M6GIsd2fkBKhPMggfVkNhDOP356LOYVUX/xSf0LiV/ih1l5OYoUptMPz+cgJpPVPQ1 X-Received: by 2002:a05:6808:1903:b0:3c3:d89c:2999 with SMTP id bf3-20020a056808190300b003c3d89c2999mr12946402oib.40.1712028633060; Mon, 01 Apr 2024 20:30:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712028633; cv=pass; d=google.com; s=arc-20160816; b=hJwemJlpCmoH55jDPUxkIgHN8yhpJ8lvkQTYbLREAZYd3YBDPpWifEODuzv53sUxPt WD3N2sr4uL5r5k9CzTlov3DtqenjfAyL5m10+wNhdC3ZfKWO30EMWVeDxkn0ptzlZO7m vuXWTNhw+XRTkMm3qNenlZBGeyH1H/ehRrONetyizfi+zG0zsByXiw/eyfR0LYnhRH/p z3dZ0FkGtrfoSi7s34y+rpVJjswJ1eq2viIyQdH9ncZTRpvyRX7vMR9WvysJbGb6iKKv PQbWwu/51bU+7G71miap1uzS9eBKOK946b3d+bRXwZiaXM8brKIWVn1VEoFE+zkr92W0 mhoQ== 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; bh=8y72Zl2Z0VujFyKPDErJBbz/O5DmiOX6CS6dGHikckw=; fh=lW6MHi1ma+bdiE1he+iHyx9lPKntUb1s0946rN3rfJM=; b=iQh2U66VUxX4GAu6ci6JLHmjoOi7q7C8KNGctcxud9146YrmMa2OSg2UBH/i4FvLM0 OWPcbhARZMxkK8STJB0hWrcGEaS58HfB9W6NAN3Q7c2oS0cDtJxBg2Gn5ixp/RVlUb5s rQnNm4XU3TxLrDcTVjWDEZWqwaLFuuKNuspxMecvs+d1unNcaxByOGL/rLbqNemqTuiU RtAuoI6eNa9yqrT36Y3gk7zXkQaMbSsNRX/eC6/pat2OzyMLaT3LB5RP6qlOGLkmpBK4 qsqlhPZMY0+1kKXS8250Mz85Yu+6beOQEea+ErlVmDhha+OHHwyNr3LykXuKn1e7g/AH eZEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-127338-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ln9-20020a056a003cc900b006e0945e03fasi10588254pfb.162.2024.04.01.20.30.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 20:30:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127338-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-127338-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 61BBEB242AC for ; Tue, 2 Apr 2024 03:30:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E4BF1755A; Tue, 2 Apr 2024 03:29:55 +0000 (UTC) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (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 41436156C2; Tue, 2 Apr 2024 03:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712028594; cv=none; b=SAZSjSulzOju0ATer/E28NpW1Pgd3abGgp3l+fqGtQRhWHFFMPOkNI7rvvlfU2WHZ04xmyGRezSWEFqC5dxgRtgFUtrq35EVIoe/m/z78NzTNC8muVTEBSgGGKgU3kMaeJ+R2u5WMrIelz7fONlnED+RZqhLUexlV6BTN5/m4Mk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712028594; c=relaxed/simple; bh=8bcsrA2Lq0ga4FH436fKGxyE6fNRzCVVCCyK4htyjZY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EIZhrzxOqx4KEt59hBKVKDENkZKT/9HKnHN/ANV1vV3VR9A2/9949LVIgc2dKyZP7pCRrn+A/XQZ/On2RA1vCp/GBLao6OvYFpCifJyRq4VfMnfE/bzU7KF5dTEy7v3QL20dLfnxy5mlw0AUkRB7CTR6QCYNgmNWZ3+7pCstgn8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4V7tbX0bLWz1R9bF; Tue, 2 Apr 2024 11:27:04 +0800 (CST) Received: from kwepemm600005.china.huawei.com (unknown [7.193.23.191]) by mail.maildlp.com (Postfix) with ESMTPS id F34661A0172; Tue, 2 Apr 2024 11:29:48 +0800 (CST) Received: from huawei.com (10.50.165.33) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Tue, 2 Apr 2024 11:29:48 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v4 1/4] hisi_acc_vfio_pci: extract public functions for container_of Date: Tue, 2 Apr 2024 11:24:29 +0800 Message-ID: <20240402032432.41004-2-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20240402032432.41004-1-liulongfang@huawei.com> References: <20240402032432.41004-1-liulongfang@huawei.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 Content-Type: text/plain X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600005.china.huawei.com (7.193.23.191) In the current driver, vdev is obtained from struct hisi_acc_vf_core_device through the container_of function. This method is used in many places in the driver. In order to reduce this repetitive operation, It was extracted into a public function. Signed-off-by: Longfang Liu --- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c index 9a3e97108ace..45351be8e270 100644 --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c @@ -630,6 +630,12 @@ static void hisi_acc_vf_disable_fds(struct hisi_acc_vf_core_device *hisi_acc_vde } } +static struct hisi_acc_vf_core_device *hisi_acc_get_vf_dev(struct vfio_device *vdev) +{ + return container_of(vdev, struct hisi_acc_vf_core_device, + core_device.vdev); +} + static void hisi_acc_vf_reset(struct hisi_acc_vf_core_device *hisi_acc_vdev) { hisi_acc_vdev->vf_qm_state = QM_NOT_READY; @@ -1033,8 +1039,7 @@ static struct file * hisi_acc_vfio_pci_set_device_state(struct vfio_device *vdev, enum vfio_device_mig_state new_state) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); enum vfio_device_mig_state next_state; struct file *res = NULL; int ret; @@ -1075,8 +1080,7 @@ static int hisi_acc_vfio_pci_get_device_state(struct vfio_device *vdev, enum vfio_device_mig_state *curr_state) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(vdev); mutex_lock(&hisi_acc_vdev->state_mutex); *curr_state = hisi_acc_vdev->mig_state; @@ -1280,8 +1284,7 @@ static long hisi_acc_vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev); struct vfio_pci_core_device *vdev = &hisi_acc_vdev->core_device; int ret; @@ -1304,8 +1307,7 @@ static int hisi_acc_vfio_pci_open_device(struct vfio_device *core_vdev) static void hisi_acc_vfio_pci_close_device(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev); struct hisi_qm *vf_qm = &hisi_acc_vdev->vf_qm; iounmap(vf_qm->io_base); @@ -1320,8 +1322,7 @@ static const struct vfio_migration_ops hisi_acc_vfio_pci_migrn_state_ops = { static int hisi_acc_vfio_pci_migrn_init_dev(struct vfio_device *core_vdev) { - struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(core_vdev, - struct hisi_acc_vf_core_device, core_device.vdev); + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_get_vf_dev(core_vdev); struct pci_dev *pdev = to_pci_dev(core_vdev->dev); struct hisi_qm *pf_qm = hisi_acc_get_pf_qm(pdev); -- 2.24.0