[media] sta2x11_vip: fix error return code in sta2x11_vip_init_one()

Message ID CAPgLHd8UFD4p=PAK+Ukno8qvmvaxVxvSrrZw=qpUtERCyP7hpg@mail.gmail.com (mailing list archive)
State Changes Requested, archived
Delegated to: Hans Verkuil
Headers

Commit Message

Wei Yongjun May 13, 2013, 5:59 a.m. UTC
  From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Fix to return a negative error code from the error handling
case instead of 0, as done elsewhere in this function.

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 drivers/media/pci/sta2x11/sta2x11_vip.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  

Comments

Federico Vaga May 13, 2013, 12:19 p.m. UTC | #1
Hello,

I agree with the content of the patch, but I disagree with the commit message. 
From the commit message it seems that you fixed a bug about the error code, 
but the aim of this patch is to uniform the code style. I suggest something 
like: "uniform code style in sta2x11_vip_init_one()"

On Monday 13 May 2013 13:59:45 Wei Yongjun wrote:
> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> Fix to return a negative error code from the error handling
> case instead of 0, as done elsewhere in this function.
> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> ---
>  drivers/media/pci/sta2x11/sta2x11_vip.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c
> b/drivers/media/pci/sta2x11/sta2x11_vip.c index 7005695..77edc11 100644
> --- a/drivers/media/pci/sta2x11/sta2x11_vip.c
> +++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
> @@ -1047,7 +1047,8 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
>  	ret = sta2x11_vip_init_controls(vip);
>  	if (ret)
>  		goto free_mem;
> -	if (v4l2_device_register(&pdev->dev, &vip->v4l2_dev))
> +	ret = v4l2_device_register(&pdev->dev, &vip->v4l2_dev);
> +	if (ret)
>  		goto free_mem;
> 
>  	dev_dbg(&pdev->dev, "BAR #0 at 0x%lx 0x%lx irq %d\n",
  
Wei Yongjun May 13, 2013, 12:40 p.m. UTC | #2
On 05/13/2013 08:19 PM, Federico Vaga wrote:
> Hello,
>
> I agree with the content of the patch, but I disagree with the commit message. 
> >From the commit message it seems that you fixed a bug about the error code, 
> but the aim of this patch is to uniform the code style. I suggest something 
> like: "uniform code style in sta2x11_vip_init_one()"

The orig code will release all the resources if v4l2_device_register()
failed and return 0.
But what we need in this case is to return an negative error code
to let the caller known we are failed. So the patch save the return
value of v4l2_device_register() to 'ret' and return it when error.


>
> On Monday 13 May 2013 13:59:45 Wei Yongjun wrote:
>> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>>
>> Fix to return a negative error code from the error handling
>> case instead of 0, as done elsewhere in this function.
>>
>> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>> ---
>>  drivers/media/pci/sta2x11/sta2x11_vip.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c
>> b/drivers/media/pci/sta2x11/sta2x11_vip.c index 7005695..77edc11 100644
>> --- a/drivers/media/pci/sta2x11/sta2x11_vip.c
>> +++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
>> @@ -1047,7 +1047,8 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
>>  	ret = sta2x11_vip_init_controls(vip);
>>  	if (ret)
>>  		goto free_mem;
>> -	if (v4l2_device_register(&pdev->dev, &vip->v4l2_dev))
>> +	ret = v4l2_device_register(&pdev->dev, &vip->v4l2_dev);
>> +	if (ret)
>>  		goto free_mem;
>>
>>  	dev_dbg(&pdev->dev, "BAR #0 at 0x%lx 0x%lx irq %d\n",


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  
Federico Vaga May 13, 2013, 12:46 p.m. UTC | #3
On Monday 13 May 2013 20:40:33 Wei Yongjun wrote:
> On 05/13/2013 08:19 PM, Federico Vaga wrote:
> > Hello,
> > 
> > I agree with the content of the patch, but I disagree with the commit
> > message.> 
> > >From the commit message it seems that you fixed a bug about the error
> > >code,
> > 
> > but the aim of this patch is to uniform the code style. I suggest
> > something
> > like: "uniform code style in sta2x11_vip_init_one()"
> 
> The orig code will release all the resources if v4l2_device_register()
> failed and return 0.
> But what we need in this case is to return an negative error code
> to let the caller known we are failed. So the patch save the return
> value of v4l2_device_register() to 'ret' and return it when error.

Oh sure, you are right :)
I did not understand it immediately from the commit message. Can you put this 
answer as commit message? It is perfectly clear where is the bug now.

Thank you
  

Patch

diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index 7005695..77edc11 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -1047,7 +1047,8 @@  static int sta2x11_vip_init_one(struct pci_dev *pdev,
 	ret = sta2x11_vip_init_controls(vip);
 	if (ret)
 		goto free_mem;
-	if (v4l2_device_register(&pdev->dev, &vip->v4l2_dev))
+	ret = v4l2_device_register(&pdev->dev, &vip->v4l2_dev);
+	if (ret)
 		goto free_mem;
 
 	dev_dbg(&pdev->dev, "BAR #0 at 0x%lx 0x%lx irq %d\n",