diff mbox series

[net] net: hso: bail out on interrupt URB allocation failure

Message ID 20210519124717.31144-1-johan@kernel.org (mailing list archive)
State Accepted
Commit 4d52ebc7ace491d58f96d1f4a1cb9070c506b2e7
Delegated to: Netdev Maintainers
Headers show
Series [net] net: hso: bail out on interrupt URB allocation failure | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/cc_maintainers warning 4 maintainers not CCed: mail@anirudhrb.com kernel@esmil.dk gregkh@linuxfoundation.org oneukum@suse.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 21 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 5 this patch: 5
netdev/header_inline success Link

Commit Message

Johan Hovold May 19, 2021, 12:47 p.m. UTC
Commit 31db0dbd7244 ("net: hso: check for allocation failure in
hso_create_bulk_serial_device()") recently started returning an error
when the driver fails to allocate resources for the interrupt endpoint
and tiocmget functionality.

For consistency let's bail out from probe also if the URB allocation
fails.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/usb/hso.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Dan Carpenter May 19, 2021, 1:23 p.m. UTC | #1
On Wed, May 19, 2021 at 02:47:17PM +0200, Johan Hovold wrote:
> Commit 31db0dbd7244 ("net: hso: check for allocation failure in
> hso_create_bulk_serial_device()") recently started returning an error
> when the driver fails to allocate resources for the interrupt endpoint
> and tiocmget functionality.
> 
> For consistency let's bail out from probe also if the URB allocation
> fails.
> 
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/net/usb/hso.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
> index 260f850d69eb..b48b2a25210c 100644
> --- a/drivers/net/usb/hso.c
> +++ b/drivers/net/usb/hso.c
> @@ -2635,14 +2635,14 @@ static struct hso_device *hso_create_bulk_serial_device(
>  		}
>  
>  		tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL);
> -		if (tiocmget->urb) {
> -			mutex_init(&tiocmget->mutex);
> -			init_waitqueue_head(&tiocmget->waitq);
> -		} else
> -			hso_free_tiomget(serial);

Thanks!  The original code works, but it's so suspicious looking because
you would think hso_free_tiomget() lead to a use after free later.

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter
patchwork-bot+netdevbpf@kernel.org May 19, 2021, 8:20 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Wed, 19 May 2021 14:47:17 +0200 you wrote:
> Commit 31db0dbd7244 ("net: hso: check for allocation failure in
> hso_create_bulk_serial_device()") recently started returning an error
> when the driver fails to allocate resources for the interrupt endpoint
> and tiocmget functionality.
> 
> For consistency let's bail out from probe also if the URB allocation
> fails.
> 
> [...]

Here is the summary with links:
  - [net] net: hso: bail out on interrupt URB allocation failure
    https://git.kernel.org/netdev/net/c/4d52ebc7ace4

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 260f850d69eb..b48b2a25210c 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -2635,14 +2635,14 @@  static struct hso_device *hso_create_bulk_serial_device(
 		}
 
 		tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL);
-		if (tiocmget->urb) {
-			mutex_init(&tiocmget->mutex);
-			init_waitqueue_head(&tiocmget->waitq);
-		} else
-			hso_free_tiomget(serial);
-	}
-	else
+		if (!tiocmget->urb)
+			goto exit;
+
+		mutex_init(&tiocmget->mutex);
+		init_waitqueue_head(&tiocmget->waitq);
+	} else {
 		num_urbs = 1;
+	}
 
 	if (hso_serial_common_create(serial, num_urbs, BULK_URB_RX_SIZE,
 				     BULK_URB_TX_SIZE))