crypto: ccp: Use scoped guard for mutex
Subsystems (3)
PATCH 1/1 crypto: ccp: Use scoped guard for mutex
From: Mario Limonciello <[email protected]>
Using a scoped guard simplifies the cleanup handling.
Signed-off-by Mario Limonciello <[email protected]>
--- drivers/crypto/ccp/dbc.c | 48 +++++++++++++++------------------------- 1 file changed, 18 insertions(+), 30 deletions(-)
drivers/crypto/ccp/dbc.c +18 -30
@@ -7,6 +7,8 @@* Author: Mario Limonciello <[email protected]> */ +#include <linux/mutex.h> +#include "dbc.h" #define DBC_DEFAULT_TIMEOUT (10 * MSEC_PER_SEC)
@@ -137,62 +139,48 @@ 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; }
Signature · 1 line
2.43.0
Quoted 1 line
Using a scoped guard simplifies the cleanup handling.
Will another imperative wording become helpful for an improved change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.12-rc6#n94
Regards,
Markus
Tom Lendacky
maintainerdrivers/crypto/ccp/dbc.c static long dbc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 181
Quoted 12 lines · Mario Limonciello
From: Mario Limonciello <[email protected]>
Using a scoped guard simplifies the cleanup handling.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/crypto/ccp/dbc.c | 48 +++++++++++++++------------------------- 1 file changed, 18 insertions(+), 30 deletions(-)drivers/crypto/ccp/dbc.c +0
-0default : ret = -EINVAL ;
Might as well make this a return -EINVAL and get rid of the return ret at the end of the function, too.
Thanks,
Tom
Quoted 7 lines
drivers/crypto/ccp/dbc.c +0
-2} -unlock: -mutex_unlock (&dbc_dev->ioctl_mutex);return ret; }