Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp889442rwb; Fri, 28 Jul 2023 01:04:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlEFlHd/10gxf6dwtE+c66nphFHlIPl+oXJSt9ICy8fa5lUbYBeHhRZ9pKoA6/DvyNPvKMKl X-Received: by 2002:a17:90a:e657:b0:260:a8da:536c with SMTP id ep23-20020a17090ae65700b00260a8da536cmr1499547pjb.23.1690531484678; Fri, 28 Jul 2023 01:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690531484; cv=none; d=google.com; s=arc-20160816; b=e1UlBJwDAJAaH8nCp+/cOmfrOL4duMvxkLrG/lQQMwPqxaai+XTWVZKgnErBiy96/H a3kaIZKcyqHWcNxa0fS4hPiH8Q++zkomv3HZ6FMwbz5HF8wFVp/Vrcv0vVjTvIimmNMF ZqoQ5BVNvQieMNRlB8xsfQiiKo5NL2OF43Gq7phbUYjZL6ONrjpIcc8CCSahzTK0dGZE MFNU6+8gnXbMyid0bIwwkJm7PBmsvaXmklUM1HV/GqNKCOq5tWmeom/ZV3HmistSl6py +jZLrVH8rdTo+e0iVLq9GQX+8a9O0/ja0AEeX+7vxAWnbvh/5thFBcxWqL0i4vO1h04b HwnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=NZxS5+vhJzFdWKZROkOONdVWyK1nILKwRYrYE+29cDo=; fh=p3Am84eky8JnrvU8V3qjJSb/r882u1KpK1t+PYxZV0c=; b=OnMHVzMGsPLuV/2PZs68siBEkjEEzZt5YKnKqAXyiL9Ud6O4N6iym0/7TI0xO7S7Ap uWwicfAyM4fAszo4qlywlj0Msl2JuWe0UeWyFogr39W+6aF/Dx1ZeK8whqnXH/GL60YL lGq0f3Ysd8bzERLtSpJsMQHGeotuNjfoX/BN0+rMpk0RH/HfgBBye0Zu5e2wsmowjZp6 BZ+Jshwxzc9eqJ1d8/Y2dGNkY00P8ga5Q8r6Mo4eZviMlzdkdIAXMgNEC+4wbnZ43liI PIHcbNhK2YmTQe8TvTtIXAeadhGWYAben3dJ0JGbbV3tc2LixlywpJ/OhITKWHn/X6uQ iZew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k189-20020a6384c6000000b00542ad648fbasi2634601pgd.188.2023.07.28.01.04.32; Fri, 28 Jul 2023 01:04:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234171AbjG1HYR (ORCPT + 99 others); Fri, 28 Jul 2023 03:24:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234172AbjG1HYO (ORCPT ); Fri, 28 Jul 2023 03:24:14 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA8162736 for ; Fri, 28 Jul 2023 00:24:13 -0700 (PDT) Received: from kwepemm600005.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RBzZ80M0hzNmTG; Fri, 28 Jul 2023 15:20:48 +0800 (CST) Received: from huawei.com (10.50.163.32) 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.27; Fri, 28 Jul 2023 15:24:11 +0800 From: liulongfang To: , , , CC: , , , Subject: [PATCH v12 2/4] hisi_acc_vfio_pci: extract public functions for container_of Date: Fri, 28 Jul 2023 15:21:02 +0800 Message-ID: <20230728072104.64834-3-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20230728072104.64834-1-liulongfang@huawei.com> References: <20230728072104.64834-1-liulongfang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Longfang Liu 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 b2f9778c8366..242ad319932a 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); +} + /* * This function is called in all state_mutex unlock cases to * handle a 'deferred_reset' if exists. @@ -1042,8 +1048,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; @@ -1084,8 +1089,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; @@ -1301,8 +1305,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; @@ -1325,8 +1328,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); @@ -1341,8 +1343,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