Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2068407rwb; Thu, 19 Jan 2023 20:30:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXuwgDm4lEXZ3JIOFcjrWmbG6mjVXNoajo5uK1oWHtcL4TIyPoN9Iu/2zWFAR0hBjKlSY61u X-Received: by 2002:a17:906:c008:b0:859:1d78:765 with SMTP id e8-20020a170906c00800b008591d780765mr9698213ejz.11.1674189005911; Thu, 19 Jan 2023 20:30:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674189005; cv=none; d=google.com; s=arc-20160816; b=EyqiDvTJCICB4moX9lDZOqfSucCqyPCE62yUsEWSWuuFQKS/hnQb+RY55IE/j72dTV HUN9y90/6yZWP17FsW6hpgy8OmlXrrqJ36bCtbqQVgJtOjpDJBveTTnB6EY6+PnIvBee FcrOsA2D/E8o1OKgezlqFriTUO4yMaNqqbFui3vuN5KCURKBAQ9R8gR+lBXoBys7wNcX wkoAJLoh/jP2SDaGPxd9ReH1VyIYhowpG7WezEqWMhJqU1kHk/B/l9yLVt3gDGtr0y9I sHaXxOT/R0KwIUQG3O5EyAIQGh5eiwkd3/+Voe1yKHiwf4+eyDA8BNzLU8zhhnglJ62I vDWg== 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=aZEe5aVazb/rF+fJuIVMBbWiiVB11cOKc/FM8rxt+As=; b=Bd6S94o01aSRq87lEWg7+MPdqumwLjcVZRWceLhtpos/QHior3RFa72ExPIsKlFQVg wWNVPbf6omIhphDDCsqZgjnA/lSyanczAeipSqXkPfvNFDiGo32vpJ/7yn075TvrGXii e4WuHCuCpwzD2f98jjj/mJXm01/iuwFXM3/3prtdgNl4CTbS7rX/tW2bUE4qoYZl8o5s KKZdpVtOI3z4s9/ccLEoOjTt/KkSqOtpptPJmHjbSCcgSYLU+OicpkgOA4gtlLJrqZV5 S14FIb/2UnR7S3pVmQ9XTRlyhAP4v5H92MaXQpiPkDEnKCVK4RvH3g0lqBFV7GYYtR/B QiXg== 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 cr12-20020a170906d54c00b0084e3dc3d9bbsi21279113ejc.132.2023.01.19.20.29.54; Thu, 19 Jan 2023 20:30:05 -0800 (PST) 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 S229908AbjATDb3 (ORCPT + 46 others); Thu, 19 Jan 2023 22:31:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229701AbjATDbK (ORCPT ); Thu, 19 Jan 2023 22:31:10 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59FB2B1EE5 for ; Thu, 19 Jan 2023 19:31:08 -0800 (PST) Received: from kwepemm600005.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NylKP6LGtzJqB0; Fri, 20 Jan 2023 11:26:49 +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.2375.34; Fri, 20 Jan 2023 11:31:06 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v7 2/5] hisi_acc_vfio_pci: extract public functions for container_of Date: Fri, 20 Jan 2023 11:29:27 +0800 Message-ID: <20230120032930.43608-3-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20230120032930.43608-1-liulongfang@huawei.com> References: <20230120032930.43608-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: dggems704-chm.china.huawei.com (10.3.19.181) 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, SPF_HELO_NONE,SPF_PASS 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 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 --- .../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 51941bb4f31f..6a219b01c965 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