Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp14210625rwb; Sun, 27 Nov 2022 20:00:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf5DWGkbLKHLpMDdZab/1MsnqujI4ikQfIQfNWQJADrriSYfyvtf8h6OJhyrJ4qBYMclfWke X-Received: by 2002:aa7:9f0d:0:b0:56b:e16d:b08 with SMTP id g13-20020aa79f0d000000b0056be16d0b08mr30059918pfr.70.1669608015445; Sun, 27 Nov 2022 20:00:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669608015; cv=none; d=google.com; s=arc-20160816; b=ZFzVNKJt3smo/RwEWkM2baaN16P8e1B91EpqNqhAiMpkp51XYIZ8Vf6RUpXGdBL6HU HFUXLY9yaLTd6n7fnTnGGgvzM+m9yMa8DNYTJtTIW/ZLbMn/E8GcIGfte2YZmqyCLGqg POL7Ro3NpH6H0pXHgLIqJdTPFoTHoF5lgSZZ0S2e2eClH2WiFElGvRjBCUjQd4f0yVL3 MuTlnzkm1w8UVM1jIjYGQRVeXGxNi4LrB5Gd7Uq32T6ue9v3w1FpuJeQYH0y0bWvb8Yg DWhQJ0r0Mma6eVegQjoT99fdgO4TQ2Y5Papr7BliGvx8QDvT6K61H2gN8Tk7Som6KU/e JRDg== 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=Tz5EiGH6bbvQXU8AvJDJ8hSytM44Mmz9Z7k9tNZV+II=; b=Plh2gxNRshawDUQDVbJUyIR+ek1pGJscKaF51b4QgAvCED62pJ1kF658htPQmU5bqL to4AHRYzpeh7ysANtsrwaAlNLp2wRQdt8dtFaUFMMK898UcZ3IBRgX5ShrayFHMGirns z19Pwj8oA/N5M28zsLqA1muUTy+Pb9RPxrykx88Rrie2MVS7q6mq/byZsDiPaTRtXnyh HgEOmlZKgzI8oY7dgFLxSgl6Dd2Dktu9K4loL5eSqCxjqqnE5PSJMi3sZLLwloFjq6xt nMJYo91kTAC6tk4A0EGbql37Xxb8+mxrRmaTw0iai59uWHVFbQz5p3HIdBWE+j7xKwtr oPEQ== 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-20020a6384c6000000b0045d60c88ad2si10520728pgd.164.2022.11.27.20.00.04; Sun, 27 Nov 2022 20:00:15 -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 S229792AbiK1DOI (ORCPT + 84 others); Sun, 27 Nov 2022 22:14:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbiK1DOG (ORCPT ); Sun, 27 Nov 2022 22:14:06 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A01FCE10 for ; Sun, 27 Nov 2022 19:14:06 -0800 (PST) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NL9XM5kjKzHw6l; Mon, 28 Nov 2022 11:13:23 +0800 (CST) Received: from kwepemm600005.china.huawei.com (7.193.23.191) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 28 Nov 2022 11:14:04 +0800 Received: from huawei.com (10.67.164.66) 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.31; Mon, 28 Nov 2022 11:14:03 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v3 2/5] hisi_acc_vfio_pci: extract public functions for container_of Date: Mon, 28 Nov 2022 11:11:57 +0800 Message-ID: <20221128031200.11017-3-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20221128031200.11017-1-liulongfang@huawei.com> References: <20221128031200.11017-1-liulongfang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.164.66] 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 0c0c0c7f0521..eb18edffbd5f 100644 --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c @@ -633,6 +633,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. @@ -927,8 +933,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; @@ -969,8 +974,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; @@ -1186,8 +1190,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; @@ -1210,8 +1213,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); @@ -1226,8 +1228,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