# \[patch -next\] HID: unlock on error path in hid\_device\_probe()

- Subsystems: HID CORE LAYER, THE REST
- Maintainers: Jiri Kosina, Benjamin Tissoires, Linus Torvalds
- List: linux-input
- 3 messages, 3 authors
- Page: https://ratatoskr.run/linux-input/2011/08/8917574/t

## \[patch -next\] HID: unlock on error path in hid\_device\_probe()

- From: Dan Carpenter \<hidden\>
- Date: 2011-08-24 11:30:04 
- Message: https://ratatoskr.run/linux-input/2011/08/8917574.md

```text
We recently introduced locking into this function, but we missed an
error path which needs an unlock.

Signed-off-by: Dan Carpenter <redacted>

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 582be00..ed0cd09 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1643,8 +1643,10 @@ static int hid_device_probe(struct device *dev)
 
 	if (!hdev->driver) {
 		id = hid_match_device(hdev, hdrv);
-		if (id == NULL)
-			return -ENODEV;
+		if (id == NULL) {
+			ret = -ENODEV;
+			goto unlock;
+		}
 
 		hdev->driver = hdrv;
 		if (hdrv->probe) {
@@ -1657,7 +1659,7 @@ static int hid_device_probe(struct device *dev)
 		if (ret)
 			hdev->driver = NULL;
 	}
-
+unlock:
 	up(&hdev->driver_lock);
 	return ret;
 }
```

## Re: \[patch -next\] HID: unlock on error path in hid\_device\_probe()

- From: David Herrmann \<hidden\>
- Date: 2011-08-24 12:26:35 
- Message: https://ratatoskr.run/linux-input/2011/08/8917575.md

```text
On Wed, Aug 24, 2011 at 1:27 PM, Dan Carpenter [ref] wrote:
> We recently introduced locking into this function, but we missed an
> error path which needs an unlock.
>
> Signed-off-by: Dan Carpenter <redacted>
>
> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index 582be00..ed0cd09 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -1643,8 +1643,10 @@ static int hid_device_probe(struct device *dev)
>
>        if (!hdev->driver) {
>                id = hid_match_device(hdev, hdrv);
> -               if (id == NULL)
> -                       return -ENODEV;
> +               if (id == NULL) {
> +                       ret = -ENODEV;
> +                       goto unlock;
> +               }
>
>                hdev->driver = hdrv;
>                if (hdrv->probe) {
> @@ -1657,7 +1659,7 @@ static int hid_device_probe(struct device *dev)
>                if (ret)
>                        hdev->driver = NULL;
>        }
> -
> +unlock:
>        up(&hdev->driver_lock);
>        return ret;
>  }
>

How could I miss that... Thanks. I tested this locking patch only with
one driver so this problem did not occur. However, using two HID
devices will deadlock the drivers. Nice catch.
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
```

## Re: \[patch -next\] HID: unlock on error path in hid\_device\_probe()

- From: Jiri Kosina \<hidden\>
- Date: 2011-08-24 14:40:13 
- Message: https://ratatoskr.run/linux-input/2011/08/8917576.md

```text
On Wed, 24 Aug 2011, Dan Carpenter wrote:

> We recently introduced locking into this function, but we missed an
> error path which needs an unlock.
> 
> Signed-off-by: Dan Carpenter <redacted>
> 
> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index 582be00..ed0cd09 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -1643,8 +1643,10 @@ static int hid_device_probe(struct device *dev)
>  
>  	if (!hdev->driver) {
>  		id = hid_match_device(hdev, hdrv);
> -		if (id == NULL)
> -			return -ENODEV;
> +		if (id == NULL) {
> +			ret = -ENODEV;
> +			goto unlock;
> +		}
>  
>  		hdev->driver = hdrv;
>  		if (hdrv->probe) {
> @@ -1657,7 +1659,7 @@ static int hid_device_probe(struct device *dev)
>  		if (ret)
>  			hdev->driver = NULL;
>  	}
> -
> +unlock:
>  	up(&hdev->driver_lock);
>  	return ret;
>  }

Good catch Dan, thanks. Applied.

-- 
Jiri Kosina
SUSE Labs
```
