Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1603980rdb; Thu, 25 Jan 2024 00:00:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpLPvcJO2vgp/ivY+3xIcbEeFX0xgh7GLOqtW5+4yuLXz4djTJZxoEf/DcmXj9sSakIvR2 X-Received: by 2002:a17:90a:9a6:b0:290:6c93:1e2a with SMTP id 35-20020a17090a09a600b002906c931e2amr263933pjo.51.1706169630905; Thu, 25 Jan 2024 00:00:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706169630; cv=pass; d=google.com; s=arc-20160816; b=1KjU3RkwTj4APMFY+TgtikjLaKyFhaAFEDU1rmF6WlZz53/8IwZbxgjiKFWrwuZJuD wUVkAhhTTEpuQtrZzSLbV4XCcHrD14VNlxVLPbBs1gsyz0HFYx6Jryzk0ziNFkE9DQOM 576xOoEmHTcNLXxF00to0tnZmFY0kx5kVWOnEPF8DHGPR3fDt46U35FvYqljiv4zu7Vj E6u194EvtN7dFxqMZV5tFznRqox1+AQSdAekwqJEoi8Duz1S5V2+faTVS4h1zsJk/6W8 0cPLuQ05pYS+fo/xJYAhaWT/SzQtN1PLhxnpuEl3yrUhB74viDUYKoxnCbOTf+eFrOhP QfYg== 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=IKRyAk8NNF+/rpPVyEtfs99HKxor6nfqNdD3PLVY3dU=; fh=lW6MHi1ma+bdiE1he+iHyx9lPKntUb1s0946rN3rfJM=; b=EtXRwOsjFcVHNgDh2MqV3o3eqmRgGFBcSNTV+RUuMIK/xLL7Blo6y11rrUTjEGjy9O jJsVEFg3AI6ZTd/8s1blGjCjQ+F7i85v4Rk58gTerdczT0Y3smGJveLKb9Ar6muyGrS/ ShsQrILl0Oh8Nnh+Cc9Sga4rpihmiN6r6UnStPBSN8NQT6fa+6WCrVhOsMDf5gETjL1q AMWNBDD0sDKFl6KGBwTxTMjXxgE1EZqOlZYTvlBKIrRmzOt2+K2pwV0ds36cklc1sHA0 emTj9ROJgGwoxrnar0MapL2p33mgi5z83bfvOtle+6LnRrC9cFYFTeucoC3WmWz1yiRa r8jw== 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-38120-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38120-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 2-20020a17090a08c200b00290cd55e19esi912993pjn.74.2024.01.25.00.00.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 00:00:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38120-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-38120-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38120-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8BE1F286A82 for ; Thu, 25 Jan 2024 08:00:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D02F17BB9; Thu, 25 Jan 2024 08:00:04 +0000 (UTC) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 479B3179A7; Thu, 25 Jan 2024 08:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706169603; cv=none; b=dFGzTMIIBtMz/D5Gb8sh8a674DTTCSfa47egJqNbWuLrg0uHDyMLF536VxHpPDwgIa25ZUwnHnfbacA16RTS/Rip/QD7Wp/9sWuc8WMzT81srxszVqgtX/j06IbFGV9Rw5OBUP2sbjF9CBA7PiLdtRZXqaseJ229foEAdWwn+EI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706169603; c=relaxed/simple; bh=6MBZvyvG0uylaHBZGJpIBIc5j4//nK/ODP3oENGdIwE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=G0GZnO/EbO8VSngBoRWpQ1IthBDkQN8dmTBRN4gbpsuyU+1VU4RiIzKUp2VPqGINcPX/x636ubdAEiuu7pX+yuvJ4V+7gNmanH6n7Dq7htP6mvw5HkbG8kdM18JT7WeXyltOtjleYA/IM9V4P3O9NwEnA7y6NLOsSTQZTn1JXjg= 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.191 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 szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TLCqm6PP5z1gy3X; Thu, 25 Jan 2024 15:58:12 +0800 (CST) Received: from kwepemm600005.china.huawei.com (unknown [7.193.23.191]) by mail.maildlp.com (Postfix) with ESMTPS id BB2C41A0172; Thu, 25 Jan 2024 15:59:57 +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_128_GCM_SHA256) id 15.1.2507.35; Thu, 25 Jan 2024 15:59:57 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH 1/3] hisi_acc_vfio_pci: extract public functions for container_of Date: Thu, 25 Jan 2024 15:55:23 +0800 Message-ID: <20240125075525.42168-2-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20240125075525.42168-1-liulongfang@huawei.com> References: <20240125075525.42168-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: dggems703-chm.china.huawei.com (10.3.19.180) 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, I extracted a public function to replace it. Signed-off-by: Longfang Liu Reviewed-by: Jason Gunthorpe --- .../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 f4b38a243aa7..5f6e01571a7b 100644 --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c @@ -641,6 +641,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); +} + /* * This function is called in all state_mutex unlock cases to * handle a 'deferred_reset' if exists. @@ -1064,8 +1070,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; @@ -1106,8 +1111,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; @@ -1323,8 +1327,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; @@ -1347,8 +1350,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); @@ -1363,8 +1365,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