lkml.org 
[lkml]   [2013]   [Sep]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 5/7] staging: usbip: Add encryption support to kernel
On Thu, Sep 19, 2013 at 04:11:57PM +0200, Dominik Paulus wrote:
> +int usbip_init_crypto(struct usbip_device *ud, unsigned char *sendkey, unsigned
> + char *recvkey)
> +{
> + int ret;
> +
> + ud->use_crypto = 1;
> +
> + ud->tfm_recv = crypto_alloc_aead("gcm(aes)", 0, 0);
> + if (IS_ERR(ud->tfm_recv))
> + return -PTR_ERR(ud->tfm_recv);
> + ud->tfm_send = crypto_alloc_aead("gcm(aes)", 0, 0);
> + if (IS_ERR(ud->tfm_send)) {
> + crypto_free_aead(ud->tfm_recv);
> + return -PTR_ERR(ud->tfm_send);
> + }
> + ret = kfifo_alloc(&ud->recv_queue, RECVQ_SIZE, GFP_KERNEL);
> + if (ret) {
> + crypto_free_aead(ud->tfm_recv);
> + crypto_free_aead(ud->tfm_send);
> + return ret;
> + }
> +
> + if (crypto_aead_setkey(ud->tfm_send, sendkey, USBIP_KEYSIZE) != 0 ||
> + crypto_aead_setkey(ud->tfm_recv, recvkey,
> + USBIP_KEYSIZE) != 0 ||
> + crypto_aead_setauthsize(ud->tfm_send,
> + USBIP_AUTHSIZE) != 0 ||
> + crypto_aead_setauthsize(ud->tfm_recv,
> + USBIP_AUTHSIZE)) {
> + crypto_free_aead(ud->tfm_recv);
> + crypto_free_aead(ud->tfm_send);
> + kfifo_free(&ud->recv_queue);
> + }

This returns success on error instead of failure.

The indenting is messed up. There are three places which check " != 0"
and doesn't. Please leave off the "!= 0" throughout the whole patch.
It should look like:

if (crypto_aead_setkey(ud->tfm_send, sendkey, USBIP_KEYSIZE) ||
crypto_aead_setkey(ud->tfm_recv, recvkey, USBIP_KEYSIZE) ||
crypto_aead_setauthsize(ud->tfm_send, USBIP_AUTHSIZE) ||
crypto_aead_setauthsize(ud->tfm_recv, USBIP_AUTHSIZE)) {
ret = -EINVAL;
goto err_free_fifo;
}

Notice how the label name is chosen based on the label location and not
the goto location.

The end of the function should look like:

return 0;

err_free_fifo:
kfifo_free(&ud->recv_queue);
err_free_send:
crypto_free_aead(ud->tfm_send);
err_free_recv:
crypto_free_aead(ud->tfm_recv);

return ret;

regards,
dan carpenter



\
 
 \ /
  Last update: 2013-09-23 13:01    [W:0.125 / U:5.552 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site