Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp282965lqd; Wed, 24 Apr 2024 02:03:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUTxHkfspaQtVR0cFAwAhEE8n8gaQEIb08RQPiIbkhUJaEncY4j/BxZRVtYWxss7/xIYxAuI/OKigPBZZRMSoZCKqBLhiegMQiVWv7fxA== X-Google-Smtp-Source: AGHT+IEcK/Ed/gwCnsWbsxzCxPhBXMXvxA8MrBC4dJbFbAnjHmT3P51NGQQzkm8OA9muaEBbgRY5 X-Received: by 2002:a05:620a:1911:b0:78f:4799:6ecf with SMTP id bj17-20020a05620a191100b0078f47996ecfmr2632187qkb.11.1713949388340; Wed, 24 Apr 2024 02:03:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713949388; cv=pass; d=google.com; s=arc-20160816; b=P3JX98fxKJz3419500u4fDN0CVETSfonJ6eppy+e7NX8jAdFhUelHCq9f7qQUMoJYp 8ra23W9lumxhjM3PptR33zqSVLxAxDW/xIzWDLJWC2eQd+dz5qCu51YUMqSOZHCw6kR2 NYbWRcBVxhiqx5EJpyaOqzFjAqtHbtpH0Za42yjeQ0DssHPbZFzv0bik0v2vGljwRiNf r8APZz1tfo+QY89VKSSsLSxTsH6tovAVXQdQFDA3sC6K1OJBjdpzfFGZ6CJPDaZfpJj9 JM+1dPubzwxgyJ7485rf00DUhUIvDUs3qFZuTa8f6uQxaNhiAReB+iTb6EdHr4J5nMVk YyqA== 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=DEoCMmLxovNMvdmxKfKhepfE2YVNYSNPhbA+3raXQHJ39w5LWdtiXYjeoGrJzZaOh6 nQdNzMRuPX10wFpS39DpaZeOMCuimJloyLV5t6cXAA3QU0SjZox3LKgHC+kxuwf39GsE 3XrMwEkQA3rjQ0+CwOXQUdhAg0Ry9VhCPqFEnM5vn4GZON7tDw7gnmCxhcD1+BV2s7EH 5fZWaDR7LHrUHet5j10YNHrDHtqnLGnrZn8jqzdml68bVCINazmd2chDAiA6GVPNkqFg bJjGZhFqZ/BpZMhw5tW6w5ct28nyeuF6JwUfIFRz9TW8IVW09+yD3Cd+XzF9uvw9R1dV VhNw==; 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-156588-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156588-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id wg22-20020a05620a569600b0078f11dacf56si13821635qkn.89.2024.04.24.02.03.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 02:03:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156588-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-156588-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156588-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EB5A41C22FCB for ; Wed, 24 Apr 2024 09:03:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E317C158A3A; Wed, 24 Apr 2024 09:03:00 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 52D6A1581FC; Wed, 24 Apr 2024 09:02:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713949380; cv=none; b=T3dLYCoglOQ0Vw6VoxziniT/DpGG4X0JGth6X9ls9qf4ua/E2/+Czpj04CbDo2ZcCLL5JkbiQqz2IPbevzlFWTRy8FbNalVqEhfGWBLFqIJy5eHOeCqFKP+VPD3uY3C8fQNEAN3fD3zX06RyWzRPVxqpBuLLJDr6CW2u0ALMwho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713949380; c=relaxed/simple; bh=8bcsrA2Lq0ga4FH436fKGxyE6fNRzCVVCCyK4htyjZY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h4O6NGa/PXJ4GBPGs6vVmO5LSGuoKicZZt+eu1/1ERJ30bAuOuo/xnd/OFb2OnR9pCk16kVhArfYKAZXJ5K7axqYGusYERpptZbL2ZqQkdAmOAa5fnMy0qHkindUToE8FCviNOl3mbQ9PiX+V/4wrdBNHSmJzOd7dN4ED+Llp2U= 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.187 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.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VPXxM1mVCzvPwf; Wed, 24 Apr 2024 16:59:51 +0800 (CST) Received: from kwepemm600005.china.huawei.com (unknown [7.193.23.191]) by mail.maildlp.com (Postfix) with ESMTPS id D21F01403D4; Wed, 24 Apr 2024 17:02:52 +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; Wed, 24 Apr 2024 17:02:52 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v5 1/5] hisi_acc_vfio_pci: extract public functions for container_of Date: Wed, 24 Apr 2024 16:57:17 +0800 Message-ID: <20240424085721.12760-2-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20240424085721.12760-1-liulongfang@huawei.com> References: <20240424085721.12760-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