[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ec4902a2-e4ab-9f74-9f61-8c1bab549746@amd.com>
Date: Wed, 11 Dec 2024 10:08:05 -0600
From: Tom Lendacky <thomas.lendacky@....com>
To: Mario Limonciello <mario.limonciello@....com>,
Herbert Xu <herbert@...dor.apana.org.au>
Cc: John Allen <john.allen@....com>,
"open list:AMD CRYPTOGRAPHIC COPROCESSOR (CCP) DRIVER - DB..."
<linux-crypto@...r.kernel.org>, open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3] crypto: ccp: Use scoped guard for mutex
On 12/3/24 10:22, Mario Limonciello wrote:
> Use a scoped guard to simplify the cleanup handling.
>
> Signed-off-by: Mario Limonciello <mario.limonciello@....com>
Reviewed-by: Tom Lendacky <thomas.lendacky@....com>
> ---
> v3:
> * Fix logic error
> ---
> drivers/crypto/ccp/dbc.c | 53 +++++++++++++++-------------------------
> 1 file changed, 20 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/crypto/ccp/dbc.c b/drivers/crypto/ccp/dbc.c
> index 5b105a23f6997..410084a9039c9 100644
> --- a/drivers/crypto/ccp/dbc.c
> +++ b/drivers/crypto/ccp/dbc.c
> @@ -7,6 +7,8 @@
> * Author: Mario Limonciello <mario.limonciello@....com>
> */
>
> +#include <linux/mutex.h>
> +
> #include "dbc.h"
>
> #define DBC_DEFAULT_TIMEOUT (10 * MSEC_PER_SEC)
> @@ -137,64 +139,49 @@ 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;
> -
> + return -EINVAL;
> }
> -unlock:
> - mutex_unlock(&dbc_dev->ioctl_mutex);
>
> - return ret;
> + return 0;
> }
>
> static const struct file_operations dbc_fops = {
>
> base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37
Powered by blists - more mailing lists