Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp364430lqi; Wed, 6 Mar 2024 22:09:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVM6l6PuMy+ZdhJWq7GneMgkbola/1sqImgo2+T53VL7YTUQyUau4v+xB2Njst+YXHv+fdGvxxa2cN93YnP1p9IJmvB7mNCivVGjC+N+Q== X-Google-Smtp-Source: AGHT+IG9WC6NUrWzMUlut3wmYAudEU3uZ5zKmx+sR1DKas+FhTueHTNQPkPDvEfFo/xaX1Dad1Rt X-Received: by 2002:a17:906:7187:b0:a45:a2cc:eb93 with SMTP id h7-20020a170906718700b00a45a2cceb93mr453932ejk.4.1709791749061; Wed, 06 Mar 2024 22:09:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709791749; cv=pass; d=google.com; s=arc-20160816; b=VzI57At+iAYF0oFn0+zOwnXcSkgHHBhF47Xw6nKfkPgHk3Prj96ectUEPsM4UcNqgu hyaG52wEbvCDTjOwvje/HRLcYqE4r5WjwotLa9IgMNWocVp4/DcsOltsm9rsaFuiJ6GQ DalIK6V5QNSVdld+vKhG/mPY/hLx1o98BGNWAz0wcLzcCaTu1SxvUi8CHBPb2utJ76Ap zVPcf120wf3FU4i5o55Zi6qjPPXytQCY4L/Jriy+FPZy3Nc7M4BrDdB6BwIcWRm//X7n SJhBgh8CS9A5qoKk6qO0+LQh/E4HFLmmDGmFTM3Ra3t6N3QhKINXClLPF/K1xWSkzvqi rxYQ== 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=zw1hkkEZmkN44i+67N3wv+kHEswI9mgNQjACYR/XzEMpUAQeoDqyEEJ8aUeXag6LrM PTJO5HXuXIVRm2X8UvDsWQW41b21Y89RVhn+sDiyrpXURAIQOxOie4kEqlzOHkLLIT3a FLN/yqVqrX40w3VM1SDB5nSvbeVo0cMG6LDjcNkaRyLgXd8/vJmKFU0NuIilJjXEQ4xj GjN7KSd88aMfsA9vUDv0kjNVx1vAyIZ7XRk6FQXanm+b1piE2ANU8d1mylRsa3XM52qW 5x5LuUkU3UJkolN2P5UuPnJal1iKWc1/Noqj7FmzSEvW1cc2d4xjDiuWM2rW35VJMP7O chSg==; 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-94995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94995-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r26-20020a1709067fda00b00a45a018c310si2420560ejs.115.2024.03.06.22.09.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 22:09:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-94995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94995-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C7EDD1F23079 for ; Thu, 7 Mar 2024 06:09:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03E411BF50; Thu, 7 Mar 2024 06:08:59 +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 CDCBC1BDE6; Thu, 7 Mar 2024 06:08:55 +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=1709791738; cv=none; b=mSQS1uLJmnFhc0S+2GtIEBmvWd4dOd06XW0P9IQiICKh5fWhRTaL5NWhZuCaB+rIcOgDWJ9YPe3vwrmltzSXdW4/wq3mwkUPjCdGH6IrQXb3cP6qtJldzM2vg9gHmxIso6e1Ay9PKMNPT5GHtRpgjA5FpEck1dfX2C8ooQRKWbw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709791738; c=relaxed/simple; bh=8bcsrA2Lq0ga4FH436fKGxyE6fNRzCVVCCyK4htyjZY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ebPPAENX544weioKXZ4YxI2oyDEmYrSuISA76hVlXEAMbknMXrYZVEHkQP1Dma1xRD2YxWGRqv6G+GcDJPMFucTkXyduXRTRzSYIc2uKRSx6oHhZ69UXkU2wec72hAtw72boKudiu40JgsAtLRhZI7aCa6Jy41HWQqHDOA21E08= 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.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TqzQ41BWGz1FLx5; Thu, 7 Mar 2024 14:08:44 +0800 (CST) Received: from kwepemm600005.china.huawei.com (unknown [7.193.23.191]) by mail.maildlp.com (Postfix) with ESMTPS id 274CB1402CE; Thu, 7 Mar 2024 14:08:53 +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, 7 Mar 2024 14:08:52 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v3 1/4] hisi_acc_vfio_pci: extract public functions for container_of Date: Thu, 7 Mar 2024 14:03:50 +0800 Message-ID: <20240307060353.16095-2-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20240307060353.16095-1-liulongfang@huawei.com> References: <20240307060353.16095-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: dggems706-chm.china.huawei.com (10.3.19.183) 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