mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Bo Liu <liubo03@inspur.com>
Cc: <cohuck@redhat.com>, <kvm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] vfio: check vfio_register_iommu_driver() return value
Date: Tue, 21 Jun 2022 11:32:21 -0600	[thread overview]
Message-ID: <20220621113221.5d28623e.alex.williamson@redhat.com> (raw)
In-Reply-To: <20220621062112.5771-1-liubo03@inspur.com>

On Tue, 21 Jun 2022 02:21:12 -0400
Bo Liu <liubo03@inspur.com> wrote:

> As vfio_register_iommu_driver() can fail, we should check the return value.
> 
> Signed-off-by: Bo Liu <liubo03@inspur.com>
> ---
>  drivers/vfio/vfio.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index 61e71c1154be..7d4b6dfafd27 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -2159,10 +2159,16 @@ static int __init vfio_init(void)
>  	pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");

If we're going to acknowledge that the below can fail, then we should
move the pr_info so that we only advertise that vfio has loaded after
all potential failure points.

>  
>  #ifdef CONFIG_VFIO_NOIOMMU
> -	vfio_register_iommu_driver(&vfio_noiommu_ops);
> +	ret = vfio_register_iommu_driver(&vfio_noiommu_ops);
> +	if (ret)
> +		goto err_driver_register;
>  #endif

We could move this #endif above the ret test so that the goto exists
outside of the #ifdef, then we don't need to wrap the goto target in
#ifdefs below.  Thanks,

Alex

>  	return 0;
>  
> +#ifdef CONFIG_VFIO_NOIOMMU
> +err_driver_register:
> +	unregister_chrdev_region(vfio.group_devt, MINORMASK + 1);
> +#endif
>  err_alloc_chrdev:
>  	class_destroy(vfio.class);
>  	vfio.class = NULL;


      reply	other threads:[~2022-06-21 17:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21  6:21 Bo Liu
2022-06-21 17:32 ` Alex Williamson [this message]

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=20220621113221.5d28623e.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liubo03@inspur.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

all inboxes | Powered by JetHome®