mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Mario Limonciello <mario.limonciello@amd.com>,
	Herbert Xu <herbert@gondor.apana.org.au>
Cc: John Allen <john.allen@amd.com>,
	"open list:AMD CRYPTOGRAPHIC COPROCESSOR (CCP) DRIVER - DB..."
	<linux-crypto@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] crypto: ccp: Use scoped guard for mutex
Date: Mon, 2 Dec 2024 08:43:00 -0600	[thread overview]
Message-ID: <06162594-21e8-e850-a179-cc42ac5a4c53@amd.com> (raw)
In-Reply-To: <20241130135836.338-1-mario.limonciello@amd.com>

On 11/30/24 07:58, Mario Limonciello wrote:
> Use a scoped guard to simplify the cleanup handling.
> 
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> v2:
>  * return immediately in default case
> ---
>  drivers/crypto/ccp/dbc.c | 53 ++++++++++++++--------------------------
>  1 file changed, 19 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/dbc.c b/drivers/crypto/ccp/dbc.c
> index 5b105a23f6997..a3c6822b3829a 100644
> --- a/drivers/crypto/ccp/dbc.c
> +++ b/drivers/crypto/ccp/dbc.c
> @@ -7,6 +7,8 @@
>   * Author: Mario Limonciello <mario.limonciello@amd.com>
>   */
>  
> +#include <linux/mutex.h>
> +
>  #include "dbc.h"
>  
>  #define DBC_DEFAULT_TIMEOUT		(10 * MSEC_PER_SEC)
> @@ -137,64 +139,47 @@ static long dbc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  		return -ENODEV;
>  	dbc_dev = psp_master->dbc_data;
>  
> -	mutex_lock(&dbc_dev->ioctl_mutex);
> +	guard(mutex)(&dbc_dev->ioctl_mutex);
>  
>  	switch (cmd) {
>  	case DBCIOCNONCE:
> -		if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_nonce))) {
> -			ret = -EFAULT;
> -			goto unlock;
> -		}
> +		if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_nonce)))
> +			return -EFAULT;
>  
>  		ret = send_dbc_nonce(dbc_dev);
>  		if (ret)
> -			goto unlock;
> +			return ret;
>  
> -		if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_nonce))) {
> -			ret = -EFAULT;
> -			goto unlock;
> -		}
> +		if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_nonce)))
> +			return -EFAULT;
>  		break;
>  	case DBCIOCUID:
> -		if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_setuid))) {
> -			ret = -EFAULT;
> -			goto unlock;
> -		}
> +		if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_setuid)))
> +			return -EFAULT;
>  
>  		*dbc_dev->payload_size = dbc_dev->header_size + sizeof(struct dbc_user_setuid);
>  		ret = send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_SET_UID);
>  		if (ret)
> -			goto unlock;
> +			return ret;
>  
> -		if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_setuid))) {
> -			ret = -EFAULT;
> -			goto unlock;
> -		}
> +		if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_setuid)))
> +			return -EFAULT;
>  		break;
>  	case DBCIOCPARAM:
> -		if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_param))) {
> -			ret = -EFAULT;
> -			goto unlock;
> -		}
> +		if (copy_from_user(dbc_dev->payload, argp, sizeof(struct dbc_user_param)))
> +			return -EFAULT;
>  
>  		*dbc_dev->payload_size = dbc_dev->header_size + sizeof(struct dbc_user_param);
>  		ret = send_dbc_parameter(dbc_dev);
>  		if (ret)
> -			goto unlock;
> +			return ret;
>  
> -		if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_param)))  {
> -			ret = -EFAULT;
> -			goto unlock;
> -		}
> +		if (copy_to_user(argp, dbc_dev->payload, sizeof(struct dbc_user_param)))
> +			return -EFAULT;
>  		break;
> -	default:
> -		ret = -EINVAL;
> -
>  	}
> -unlock:
> -	mutex_unlock(&dbc_dev->ioctl_mutex);
>  
> -	return ret;
> +	return -EINVAL;

Hmmm... not quite what I said when I said to put a return -EINVAL in the
default case. You now return -EINVAL for every successful case.

Thanks,
Tom

>  }
>  
>  static const struct file_operations dbc_fops = {

      reply	other threads:[~2024-12-02 14:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-30 13:58 Mario Limonciello
2024-12-02 14:43 ` Tom Lendacky [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=06162594-21e8-e850-a179-cc42ac5a4c53@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=john.allen@amd.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®