Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1112176lqd; Thu, 25 Apr 2024 06:29:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV6IQq9OIO+MXlGKY84mgMWrd7HYirlTfAxajd16JnZDXl2UE62lmSXAtoxDz8jkDk+yzTiex7bcz6LmxL1CAVPl4zd94bj14LyqXB2yg== X-Google-Smtp-Source: AGHT+IFUrR2UjRCpm6lvdhEoi5XvhmPxQkqre4bvRt2AYsuR1FloF5m0ClmSp1wVP2+pjTpD0g6u X-Received: by 2002:a17:902:ce88:b0:1e5:868a:94b5 with SMTP id f8-20020a170902ce8800b001e5868a94b5mr7037642plg.37.1714051777063; Thu, 25 Apr 2024 06:29:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714051777; cv=pass; d=google.com; s=arc-20160816; b=yy22yQ/WrdSB8bHN+G+jxOJ0bWeIllGIFKjodT7JzV9FmNUKAvPaTCDz+KU4zcsVm+ Yq6vNe/AMcqWE7f6nSxGs/32ROb18SEfD8Ld80Ylz5mgEMQgQVLgRg6p7g+cn5k3Ij7I 7Th65Dy+De32jnyTMDtMiSSrUR87k9vn5A7Wn1JSsrr8DzfVkievFdCJHvW9SWe+c2Js NleRKuaBcgTT6ZdchNPPWkc7spwFWNGDo79ErgP1PN9Wb46dJ55b6UCVkocM3IawibIC vhaQYvib3+R3Xf4Qws5vTYkvGX2cskyLsibj6C3Jk0fM09B/4OzvrrScS+bRyDUG7Y2A vOog== 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=tqez4Frai4zMzwE4NsVLhbqeOn1V+hIRt9gEffK0AM6TFbA8J49H8GoKviXr9QTAkP 01FFJMFRuZ3JLIyofTMIT1XPabGfsXiyIwcY6w7BOXeF9eP6pL2y8N20NHnlwsD92zfF DYNDziHVnLKzypf7/WrI4TjCDFZmYuC0h2N8J/jLyynqqreDAsM/qg/gndeIHLRVR3Qz /OLJbCTfbnBS3pQd/skvHRws3+nMSH7ggVa2IH3b6+yAoZf7wLWS1PM5ghsDmhxGZeHp qVFuNB4v3AKILSTX/khrkiX3MrKAW1lSIFtXY98RGOVwm0xXkCq/1pfoJorRu+KpW0Nx bpCQ==; 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-158597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158597-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 im15-20020a170902bb0f00b001dcfaf5bfefsi13402691plb.573.2024.04.25.06.29.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 06:29:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158597-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-158597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158597-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 C8741286A89 for ; Thu, 25 Apr 2024 13:29:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4410F149C70; Thu, 25 Apr 2024 13:29:00 +0000 (UTC) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (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 C7CAA149C58; Thu, 25 Apr 2024 13:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714051739; cv=none; b=KrtcORWvTs+2ai5fnsb56caQvJCKlDx6zRn+vfGL+AAhAAPb8bZAkY9O+JJ7AgZc27ucislVzbCn/F58+TbLxS66mJB59QEkHMz4KQucX9pDUvNvMyF6lHRy+s6EET25TAMf2QgwB2Rq2/jpKiLEkZWTQ5pmK2ybzPfWSolfsp4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714051739; c=relaxed/simple; bh=8bcsrA2Lq0ga4FH436fKGxyE6fNRzCVVCCyK4htyjZY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FyQvdyZHrYZtAQt2Iq17en9g9qoHGzyPT2KBhjfyxA00aeFFTdelfjER0nwjUpMwCoojP0yH0JmAqCJTLqhi4TijcP52zxVahfw7AA0BwHxSxU5rsbzSF4gcplFbc7f2r9iMRRkMj6pCeSW97plcleeINzhrypqMpjgDeUttxHg= 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.255 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.162.254]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4VQGnq4kGPz1R5Vs; Thu, 25 Apr 2024 21:25:51 +0800 (CST) Received: from kwepemm600005.china.huawei.com (unknown [7.193.23.191]) by mail.maildlp.com (Postfix) with ESMTPS id 9EA5A1800AA; Thu, 25 Apr 2024 21:28:54 +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; Thu, 25 Apr 2024 21:28:54 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v6 1/5] hisi_acc_vfio_pci: extract public functions for container_of Date: Thu, 25 Apr 2024 21:23:18 +0800 Message-ID: <20240425132322.12041-2-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20240425132322.12041-1-liulongfang@huawei.com> References: <20240425132322.12041-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: dggems704-chm.china.huawei.com (10.3.19.181) 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