kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next v2] samples: vfio-mdev: fix error handing in mdpy_fb_probe()
@ 2021-05-20 13:36 Wei Yongjun
  2021-05-24 19:49 ` Alex Williamson
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Yongjun @ 2021-05-20 13:36 UTC (permalink / raw)
  To: weiyongjun1, Gerd Hoffmann, Kirti Wankhede, Alex Williamson,
	Dan Carpenter
  Cc: kvm, kernel-janitors, Hulk Robot

Fix to return a negative error code from the framebuffer_alloc() error
handling case instead of 0, also release regions in some error handing
cases.

Fixes: cacade1946a4 ("sample: vfio mdev display - guest driver")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
v1 -> v2: add missing regions release.
---
 samples/vfio-mdev/mdpy-fb.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/samples/vfio-mdev/mdpy-fb.c b/samples/vfio-mdev/mdpy-fb.c
index 21dbf63d6e41..9ec93d90e8a5 100644
--- a/samples/vfio-mdev/mdpy-fb.c
+++ b/samples/vfio-mdev/mdpy-fb.c
@@ -117,22 +117,27 @@ static int mdpy_fb_probe(struct pci_dev *pdev,
 	if (format != DRM_FORMAT_XRGB8888) {
 		pci_err(pdev, "format mismatch (0x%x != 0x%x)\n",
 			format, DRM_FORMAT_XRGB8888);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_release_regions;
 	}
 	if (width < 100	 || width > 10000) {
 		pci_err(pdev, "width (%d) out of range\n", width);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_release_regions;
 	}
 	if (height < 100 || height > 10000) {
 		pci_err(pdev, "height (%d) out of range\n", height);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_release_regions;
 	}
 	pci_info(pdev, "mdpy found: %dx%d framebuffer\n",
 		 width, height);
 
 	info = framebuffer_alloc(sizeof(struct mdpy_fb_par), &pdev->dev);
-	if (!info)
+	if (!info) {
+		ret = -ENOMEM;
 		goto err_release_regions;
+	}
 	pci_set_drvdata(pdev, info);
 	par = info->par;
 


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH -next v2] samples: vfio-mdev: fix error handing in mdpy_fb_probe()
  2021-05-20 13:36 [PATCH -next v2] samples: vfio-mdev: fix error handing in mdpy_fb_probe() Wei Yongjun
@ 2021-05-24 19:49 ` Alex Williamson
  2021-05-25 19:02   ` Christophe JAILLET
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Williamson @ 2021-05-24 19:49 UTC (permalink / raw)
  To: Wei Yongjun
  Cc: Gerd Hoffmann, Kirti Wankhede, Dan Carpenter, kvm,
	kernel-janitors, Hulk Robot

On Thu, 20 May 2021 13:36:41 +0000
Wei Yongjun <weiyongjun1@huawei.com> wrote:

> Fix to return a negative error code from the framebuffer_alloc() error
> handling case instead of 0, also release regions in some error handing
> cases.
> 
> Fixes: cacade1946a4 ("sample: vfio mdev display - guest driver")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
> v1 -> v2: add missing regions release.
> ---
>  samples/vfio-mdev/mdpy-fb.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/samples/vfio-mdev/mdpy-fb.c b/samples/vfio-mdev/mdpy-fb.c
> index 21dbf63d6e41..9ec93d90e8a5 100644
> --- a/samples/vfio-mdev/mdpy-fb.c
> +++ b/samples/vfio-mdev/mdpy-fb.c
> @@ -117,22 +117,27 @@ static int mdpy_fb_probe(struct pci_dev *pdev,
>  	if (format != DRM_FORMAT_XRGB8888) {
>  		pci_err(pdev, "format mismatch (0x%x != 0x%x)\n",
>  			format, DRM_FORMAT_XRGB8888);
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto err_release_regions;
>  	}
>  	if (width < 100	 || width > 10000) {
>  		pci_err(pdev, "width (%d) out of range\n", width);
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto err_release_regions;
>  	}
>  	if (height < 100 || height > 10000) {
>  		pci_err(pdev, "height (%d) out of range\n", height);
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto err_release_regions;
>  	}
>  	pci_info(pdev, "mdpy found: %dx%d framebuffer\n",
>  		 width, height);
>  
>  	info = framebuffer_alloc(sizeof(struct mdpy_fb_par), &pdev->dev);
> -	if (!info)
> +	if (!info) {
> +		ret = -ENOMEM;
>  		goto err_release_regions;
> +	}
>  	pci_set_drvdata(pdev, info);
>  	par = info->par;
>  
> 

Thanks for adding the extra error cases.  Applied to vfio for-linus
branch for v5.13.  Thanks,

Alex


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH -next v2] samples: vfio-mdev: fix error handing in mdpy_fb_probe()
  2021-05-24 19:49 ` Alex Williamson
@ 2021-05-25 19:02   ` Christophe JAILLET
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2021-05-25 19:02 UTC (permalink / raw)
  To: Alex Williamson, Wei Yongjun
  Cc: Gerd Hoffmann, Kirti Wankhede, Dan Carpenter, kvm,
	kernel-janitors, Hulk Robot

Le 24/05/2021 à 21:49, Alex Williamson a écrit :
> On Thu, 20 May 2021 13:36:41 +0000
> Wei Yongjun <weiyongjun1@huawei.com> wrote:
> 
>> Fix to return a negative error code from the framebuffer_alloc() error
>> handling case instead of 0, also release regions in some error handing
>> cases.
>>
>> Fixes: cacade1946a4 ("sample: vfio mdev display - guest driver")
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
>> ---
>> v1 -> v2: add missing regions release.
>> ---
>>   samples/vfio-mdev/mdpy-fb.c | 13 +++++++++----
>>   1 file changed, 9 insertions(+), 4 deletions(-)
>>
>> diff --git a/samples/vfio-mdev/mdpy-fb.c b/samples/vfio-mdev/mdpy-fb.c
>> index 21dbf63d6e41..9ec93d90e8a5 100644
>> --- a/samples/vfio-mdev/mdpy-fb.c
>> +++ b/samples/vfio-mdev/mdpy-fb.c
>> @@ -117,22 +117,27 @@ static int mdpy_fb_probe(struct pci_dev *pdev,
>>   	if (format != DRM_FORMAT_XRGB8888) {
>>   		pci_err(pdev, "format mismatch (0x%x != 0x%x)\n",
>>   			format, DRM_FORMAT_XRGB8888);
>> -		return -EINVAL;
>> +		ret = -EINVAL;
>> +		goto err_release_regions;
>>   	}
>>   	if (width < 100	 || width > 10000) {
>>   		pci_err(pdev, "width (%d) out of range\n", width);
>> -		return -EINVAL;
>> +		ret = -EINVAL;
>> +		goto err_release_regions;
>>   	}
>>   	if (height < 100 || height > 10000) {
>>   		pci_err(pdev, "height (%d) out of range\n", height);
>> -		return -EINVAL;
>> +		ret = -EINVAL;
>> +		goto err_release_regions;
>>   	}
>>   	pci_info(pdev, "mdpy found: %dx%d framebuffer\n",
>>   		 width, height);
>>   
>>   	info = framebuffer_alloc(sizeof(struct mdpy_fb_par), &pdev->dev);
>> -	if (!info)
>> +	if (!info) {
>> +		ret = -ENOMEM;
>>   		goto err_release_regions;
>> +	}
>>   	pci_set_drvdata(pdev, info);
>>   	par = info->par;
>>   
>>
> 
> Thanks for adding the extra error cases.  Applied to vfio for-linus
> branch for v5.13.  Thanks,
> 
> Alex
> 
> 

Hi,
doesn't the initial pci_enable_device also requires a corresponding 
pci_disable_device, both in the error handling path, and in the remove 
function?

just my 2c,

CJ


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-25 19:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 13:36 [PATCH -next v2] samples: vfio-mdev: fix error handing in mdpy_fb_probe() Wei Yongjun
2021-05-24 19:49 ` Alex Williamson
2021-05-25 19:02   ` Christophe JAILLET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).