2017-09-10 12:04:58

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH] media: v4l2-pci-skeleton: Fix error handling path in 'skeleton_probe()'

If this memory allocation fails, we must release some resources, as
already done in the code below and above.

Signed-off-by: Christophe JAILLET <[email protected]>
---
samples/v4l/v4l2-pci-skeleton.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/samples/v4l/v4l2-pci-skeleton.c b/samples/v4l/v4l2-pci-skeleton.c
index 483e9bca9444..f520e3aef9c6 100644
--- a/samples/v4l/v4l2-pci-skeleton.c
+++ b/samples/v4l/v4l2-pci-skeleton.c
@@ -772,8 +772,10 @@ static int skeleton_probe(struct pci_dev *pdev, const struct pci_device_id *ent)

/* Allocate a new instance */
skel = devm_kzalloc(&pdev->dev, sizeof(struct skeleton), GFP_KERNEL);
- if (!skel)
- return -ENOMEM;
+ if (!skel) {
+ ret = -ENOMEM;
+ goto disable_pci;
+ }

/* Allocate the interrupt */
ret = devm_request_irq(&pdev->dev, pdev->irq,
--
2.11.0


2017-09-11 07:21:39

by Hans Verkuil (hansverk)

[permalink] [raw]
Subject: Re: [PATCH] media: v4l2-pci-skeleton: Fix error handling path in 'skeleton_probe()'

On 09/10/2017 01:53 PM, Christophe JAILLET wrote:
> If this memory allocation fails, we must release some resources, as
> already done in the code below and above.
>
> Signed-off-by: Christophe JAILLET <[email protected]>

Please repost and add the linux-media mailinglist to the CC list. That way it ends up
in our patchwork system and it won't be forgotten.

Regards,

Hans

> ---
> samples/v4l/v4l2-pci-skeleton.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/samples/v4l/v4l2-pci-skeleton.c b/samples/v4l/v4l2-pci-skeleton.c
> index 483e9bca9444..f520e3aef9c6 100644
> --- a/samples/v4l/v4l2-pci-skeleton.c
> +++ b/samples/v4l/v4l2-pci-skeleton.c
> @@ -772,8 +772,10 @@ static int skeleton_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>
> /* Allocate a new instance */
> skel = devm_kzalloc(&pdev->dev, sizeof(struct skeleton), GFP_KERNEL);
> - if (!skel)
> - return -ENOMEM;
> + if (!skel) {
> + ret = -ENOMEM;
> + goto disable_pci;
> + }
>
> /* Allocate the interrupt */
> ret = devm_request_irq(&pdev->dev, pdev->irq,
>