mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Longfang Liu <liulongfang@huawei.com>
Cc: <jgg@nvidia.com>, <shameerali.kolothum.thodi@huawei.com>,
	<jonathan.cameron@huawei.com>, <cohuck@redhat.com>,
	<linux-kernel@vger.kernel.org>, <linuxarm@openeuler.org>
Subject: Re: [PATCH v8 2/5] hisi_acc_vfio_pci: extract public functions for container_of
Date: Fri, 10 Mar 2023 16:40:10 -0700	[thread overview]
Message-ID: <20230310164010.3428141f.alex.williamson@redhat.com> (raw)
In-Reply-To: <20230217084831.35783-3-liulongfang@huawei.com>

On Fri, 17 Feb 2023 16:48:28 +0800
Longfang Liu <liulongfang@huawei.com> wrote:

> 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 <liulongfang@huawei.com>
> ---
>  .../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 a117eaf21c14..a1589947e721 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 type of function is often named to_foo_bar(), ex. to_pci_dev(),
and often macros.  Perhaps:

#define to_hisi_acc_dev(n) container_of(n, \
	struct hisi_acc_vf_core_device, core_device,vdev)

Thanks,
Alex

> +
>  /*
>   * 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);
>  


  parent reply	other threads:[~2023-03-10 23:41 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17  8:48 [PATCH v8 0/5] add debugfs to migration driver Longfang Liu
2023-02-17  8:48 ` [PATCH v8 1/5] vfio/migration: Add debugfs to live " Longfang Liu
2023-03-10 17:12   ` Jason Gunthorpe
2023-03-14  9:32     ` liulongfang
2023-03-14 11:31       ` liulongfang
2023-03-10 23:40   ` Alex Williamson
2023-03-14  9:42     ` liulongfang
2023-02-17  8:48 ` [PATCH v8 2/5] hisi_acc_vfio_pci: extract public functions for container_of Longfang Liu
2023-03-10 17:18   ` Jason Gunthorpe
2023-03-10 23:40   ` Alex Williamson [this message]
2023-03-14 10:34     ` liulongfang
2023-02-17  8:48 ` [PATCH v8 3/5] hisi_acc_vfio_pci: register debugfs for hisilicon migration driver Longfang Liu
2023-03-10 17:22   ` Jason Gunthorpe
2023-03-14 10:35     ` liulongfang
2023-03-10 23:40   ` Alex Williamson
2023-03-14 11:04     ` liulongfang
2023-03-14 11:21       ` liulongfang
2023-03-14 15:17         ` Alex Williamson
2023-03-18  9:07           ` liulongfang
2023-03-18 14:38             ` Alex Williamson
2023-02-17  8:48 ` [PATCH v8 4/5] Documentation: add debugfs description for vfio Longfang Liu
2023-03-10 23:39   ` Alex Williamson
2023-03-14 10:56     ` liulongfang
2023-02-17  8:48 ` [PATCH v8 5/5] vfio: update live migration device status Longfang Liu
2023-03-10  8:27 ` [PATCH v8 0/5] add debugfs to migration driver liulongfang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230310164010.3428141f.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@openeuler.org \
    --cc=liulongfang@huawei.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome