* [PATCH v1 1/2] s390/zcrtpt: Don't leak memory if dev_set_name() fails
@ 2023-08-31 10:59 Andy Shevchenko
2023-08-31 11:00 ` [PATCH v1 2/2] s390/zcrypt: Utilize dev_set_name() ability to use a formatted string Andy Shevchenko
2023-09-04 7:20 ` [PATCH v1 1/2] s390/zcrtpt: Don't leak memory if dev_set_name() fails Harald Freudenberger
0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2023-08-31 10:59 UTC (permalink / raw)
To: Harald Freudenberger, linux-s390, linux-kernel
Cc: Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger, Sven Schnelle, Andy Shevchenko
When dev_set_name() fails, the zcdn_create() doesn't free
the newly allocated resources. Do it.
Fixes: 00fab2350e6b ("s390/zcrypt: multiple zcrypt device nodes support")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/s390/crypto/zcrypt_api.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index 4b23c9f7f3e5..6b99f7dd0643 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -413,6 +413,7 @@ static int zcdn_create(const char *name)
ZCRYPT_NAME "_%d", (int)MINOR(devt));
nodename[sizeof(nodename) - 1] = '\0';
if (dev_set_name(&zcdndev->device, nodename)) {
+ kfree(zcdndev);
rc = -EINVAL;
goto unlockout;
}
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v1 2/2] s390/zcrypt: Utilize dev_set_name() ability to use a formatted string
2023-08-31 10:59 [PATCH v1 1/2] s390/zcrtpt: Don't leak memory if dev_set_name() fails Andy Shevchenko
@ 2023-08-31 11:00 ` Andy Shevchenko
2023-09-04 7:20 ` [PATCH v1 1/2] s390/zcrtpt: Don't leak memory if dev_set_name() fails Harald Freudenberger
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2023-08-31 11:00 UTC (permalink / raw)
To: Harald Freudenberger, linux-s390, linux-kernel
Cc: Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger, Sven Schnelle, Andy Shevchenko
With the dev_set_name() prototype it's not obvious that it takes
a formatted string as a parameter. Use its facility instead of
duplicating the same with strncpy()/snprintf() calls.
With this, also prevent return error code to be shadowed.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/s390/crypto/zcrypt_api.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index 6b99f7dd0643..ce04caa7913f 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -366,7 +366,6 @@ static int zcdn_create(const char *name)
{
dev_t devt;
int i, rc = 0;
- char nodename[ZCDN_MAX_NAME];
struct zcdn_device *zcdndev;
if (mutex_lock_interruptible(&ap_perms_mutex))
@@ -407,14 +406,11 @@ static int zcdn_create(const char *name)
zcdndev->device.devt = devt;
zcdndev->device.groups = zcdn_dev_attr_groups;
if (name[0])
- strncpy(nodename, name, sizeof(nodename));
+ rc = dev_set_name(&zcdndev->device, "%s", name);
else
- snprintf(nodename, sizeof(nodename),
- ZCRYPT_NAME "_%d", (int)MINOR(devt));
- nodename[sizeof(nodename) - 1] = '\0';
- if (dev_set_name(&zcdndev->device, nodename)) {
+ rc = dev_set_name(&zcdndev->device, ZCRYPT_NAME "_%d", (int)MINOR(devt));
+ if (rc) {
kfree(zcdndev);
- rc = -EINVAL;
goto unlockout;
}
rc = device_register(&zcdndev->device);
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v1 1/2] s390/zcrtpt: Don't leak memory if dev_set_name() fails
2023-08-31 10:59 [PATCH v1 1/2] s390/zcrtpt: Don't leak memory if dev_set_name() fails Andy Shevchenko
2023-08-31 11:00 ` [PATCH v1 2/2] s390/zcrypt: Utilize dev_set_name() ability to use a formatted string Andy Shevchenko
@ 2023-09-04 7:20 ` Harald Freudenberger
1 sibling, 0 replies; 3+ messages in thread
From: Harald Freudenberger @ 2023-09-04 7:20 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-s390, linux-kernel, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, Sven Schnelle
On 2023-08-31 12:59, Andy Shevchenko wrote:
> When dev_set_name() fails, the zcdn_create() doesn't free
> the newly allocated resources. Do it.
>
> Fixes: 00fab2350e6b ("s390/zcrypt: multiple zcrypt device nodes
> support")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/s390/crypto/zcrypt_api.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/s390/crypto/zcrypt_api.c
> b/drivers/s390/crypto/zcrypt_api.c
> index 4b23c9f7f3e5..6b99f7dd0643 100644
> --- a/drivers/s390/crypto/zcrypt_api.c
> +++ b/drivers/s390/crypto/zcrypt_api.c
> @@ -413,6 +413,7 @@ static int zcdn_create(const char *name)
> ZCRYPT_NAME "_%d", (int)MINOR(devt));
> nodename[sizeof(nodename) - 1] = '\0';
> if (dev_set_name(&zcdndev->device, nodename)) {
> + kfree(zcdndev);
> rc = -EINVAL;
> goto unlockout;
> }
Thanks Andy, I picked this patch and forwarded it into the s390
subsystem.
This will be visible in Linus' kernel tree with the next merge.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-04 7:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-31 10:59 [PATCH v1 1/2] s390/zcrtpt: Don't leak memory if dev_set_name() fails Andy Shevchenko
2023-08-31 11:00 ` [PATCH v1 2/2] s390/zcrypt: Utilize dev_set_name() ability to use a formatted string Andy Shevchenko
2023-09-04 7:20 ` [PATCH v1 1/2] s390/zcrtpt: Don't leak memory if dev_set_name() fails Harald Freudenberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox