diff mbox

[V6,7/8] vfio: platform: check reset call return code during open

Message ID 1464472878-27176-8-git-send-email-okaya@codeaurora.org (mailing list archive)
State New, archived
Headers show

Commit Message

Sinan Kaya May 28, 2016, 10:01 p.m. UTC
Open call is ignoring the return code from reset call and can
potentially continue even though reset call failed.

If reset_required module parameter is set, this patch is going
to validate the return code and will abort open if reset fails.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
---
 drivers/vfio/platform/vfio_platform_common.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Eric Auger June 7, 2016, 8:21 p.m. UTC | #1
Hi Sinan,
Le 29/05/2016 à 00:01, Sinan Kaya a écrit :
> Open call is ignoring the return code from reset call and can
> potentially continue even though reset call failed.
> 
> If reset_required module parameter is set, this patch is going
> to validate the return code and will abort open if reset fails.
> 
> Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
> ---
>  drivers/vfio/platform/vfio_platform_common.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
> index e87ceab..962cfb1 100644
> --- a/drivers/vfio/platform/vfio_platform_common.c
> +++ b/drivers/vfio/platform/vfio_platform_common.c
> @@ -264,6 +264,8 @@ static int vfio_platform_open(void *device_data)
>  	mutex_lock(&driver_lock);
>  
>  	if (!vdev->refcnt) {
> +		const char *extra_dbg = NULL;
> +
>  		ret = vfio_platform_regions_init(vdev);
>  		if (ret)
>  			goto err_reg;
> @@ -272,7 +274,12 @@ static int vfio_platform_open(void *device_data)
>  		if (ret)
>  			goto err_irq;
>  
> -		vfio_platform_call_reset(vdev, NULL);
> +		ret = vfio_platform_call_reset(vdev, &extra_dbg);
> +		if (ret && vdev->reset_required) {
> +			dev_warn(vdev->device, "reset driver is required and reset call failed in open (%d) %s\n",
> +				 ret, extra_dbg ? extra_dbg : "");
> +			goto err_irq;
I am afraid you need to tear down the resources allocated by vfio_platform_irq_init. 

Best Regards

Eric
> +		}
>  	}
>  
>  	vdev->refcnt++;
>
Sinan Kaya June 13, 2016, 3:12 a.m. UTC | #2
On 6/7/2016 4:21 PM, Auger Eric wrote:
>> -		vfio_platform_call_reset(vdev, NULL);
>> > +		ret = vfio_platform_call_reset(vdev, &extra_dbg);
>> > +		if (ret && vdev->reset_required) {
>> > +			dev_warn(vdev->device, "reset driver is required and reset call failed in open (%d) %s\n",
>> > +				 ret, extra_dbg ? extra_dbg : "");
>> > +			goto err_irq;
> I am afraid you need to tear down the resources allocated by vfio_platform_irq_init. 
> 
> Best Regards
> 
> Eric

I added this to the error path and replaced the goto above with err_rst.

+err_rst:
+        vfio_platform_irq_cleanup(vdev);
err_irq:
        vfio_platform_regions_cleanup(vdev);
diff mbox

Patch

diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
index e87ceab..962cfb1 100644
--- a/drivers/vfio/platform/vfio_platform_common.c
+++ b/drivers/vfio/platform/vfio_platform_common.c
@@ -264,6 +264,8 @@  static int vfio_platform_open(void *device_data)
 	mutex_lock(&driver_lock);
 
 	if (!vdev->refcnt) {
+		const char *extra_dbg = NULL;
+
 		ret = vfio_platform_regions_init(vdev);
 		if (ret)
 			goto err_reg;
@@ -272,7 +274,12 @@  static int vfio_platform_open(void *device_data)
 		if (ret)
 			goto err_irq;
 
-		vfio_platform_call_reset(vdev, NULL);
+		ret = vfio_platform_call_reset(vdev, &extra_dbg);
+		if (ret && vdev->reset_required) {
+			dev_warn(vdev->device, "reset driver is required and reset call failed in open (%d) %s\n",
+				 ret, extra_dbg ? extra_dbg : "");
+			goto err_irq;
+		}
 	}
 
 	vdev->refcnt++;