* [PATCH] crypto: ccp: Use scoped guard for mutex
@ 2024-11-09 2:00 Mario Limonciello
2024-11-10 9:25 ` Markus Elfring
2024-11-11 14:28 ` Tom Lendacky
0 siblings, 2 replies; 3+ messages in thread
From: Mario Limonciello @ 2024-11-09 2:00 UTC (permalink / raw)
To: Tom Lendacky, John Allen, Herbert Xu
Cc: linux-crypto, linux-kernel, Mario Limonciello
From: Mario Limonciello <mario.limonciello@amd.com>
Using a scoped guard simplifies the cleanup handling.
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/crypto/ccp/dbc.c | 48 +++++++++++++++-------------------------
1 file changed, 18 insertions(+), 30 deletions(-)
diff --git a/drivers/crypto/ccp/dbc.c b/drivers/crypto/ccp/dbc.c
index 5b105a23f6997..3617e6eabab14 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,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;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: ccp: Use scoped guard for mutex
2024-11-09 2:00 [PATCH] crypto: ccp: Use scoped guard for mutex Mario Limonciello
@ 2024-11-10 9:25 ` Markus Elfring
2024-11-11 14:28 ` Tom Lendacky
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-11-10 9:25 UTC (permalink / raw)
To: Mario Limonciello, linux-crypto, Herbert Xu, John Allen,
Tom Lendacky
Cc: Mario Limonciello, LKML
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: ccp: Use scoped guard for mutex
2024-11-09 2:00 [PATCH] crypto: ccp: Use scoped guard for mutex Mario Limonciello
2024-11-10 9:25 ` Markus Elfring
@ 2024-11-11 14:28 ` Tom Lendacky
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lendacky @ 2024-11-11 14:28 UTC (permalink / raw)
To: Mario Limonciello, John Allen, Herbert Xu
Cc: linux-crypto, linux-kernel, Mario Limonciello
On 11/8/24 20:00, Mario Limonciello wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
>
> Using a scoped guard simplifies the cleanup handling.
>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> drivers/crypto/ccp/dbc.c | 48 +++++++++++++++-------------------------
> 1 file changed, 18 insertions(+), 30 deletions(-)
>
> default:
> 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
>
> }
> -unlock:
> - mutex_unlock(&dbc_dev->ioctl_mutex);
>
> return ret;
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-11 14:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-09 2:00 [PATCH] crypto: ccp: Use scoped guard for mutex Mario Limonciello
2024-11-10 9:25 ` Markus Elfring
2024-11-11 14:28 ` Tom Lendacky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox