Skip to content

Commit

Permalink
media: ttusb-dec: cleanup an error handling logic
Browse files Browse the repository at this point in the history
Simplify the logic at ttusb_dec_send_command().

Besides avoiding some code duplication, as a side effect,
this could remove this false positive return with spatch:

	drivers/media/usb/ttusb-dec/ttusb_dec.c:380 ttusb_dec_send_command() warn: inconsistent returns '&dec->usb_mutex'.
	  Locked on  : 330
	  Unlocked on: 354,365,380

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
  • Loading branch information
mchehab committed Jun 17, 2021
1 parent 5368b1e commit dba328b
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions drivers/media/usb/ttusb-dec/ttusb_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
if (!b)
return -ENOMEM;

if ((result = mutex_lock_interruptible(&dec->usb_mutex))) {
kfree(b);
result = mutex_lock_interruptible(&dec->usb_mutex);
if (result) {
printk("%s: Failed to lock usb mutex.\n", __func__);
return result;
goto err;
}

b[0] = 0xaa;
Expand All @@ -349,9 +349,7 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
if (result) {
printk("%s: command bulk message failed: error %d\n",
__func__, result);
mutex_unlock(&dec->usb_mutex);
kfree(b);
return result;
goto err;
}

result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
Expand All @@ -360,9 +358,7 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
mutex_unlock(&dec->usb_mutex);
kfree(b);
return result;
goto err;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
Expand All @@ -373,12 +369,13 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
*result_length = b[3];
if (cmd_result && b[3] > 0)
memcpy(cmd_result, &b[4], b[3]);
}

mutex_unlock(&dec->usb_mutex);
err:
mutex_unlock(&dec->usb_mutex);

kfree(b);
return 0;
}
kfree(b);
return result;
}

static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
Expand Down

0 comments on commit dba328b

Please sign in to comment.