From: Guenter Roeck <linux@roeck-us.net>
To: "Krzysztof Kozlowski" <krzysztof.kozlowski@linaro.org>,
"Pali Rohár" <pali@kernel.org>,
"Jean Delvare" <jdelvare@suse.com>,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hwmon: (dell-smm) Simplify with cleanup.h
Date: Wed, 3 Jul 2024 11:52:14 -0700 [thread overview]
Message-ID: <982dc693-dbb2-41a7-ae0d-3b3c05c28117@roeck-us.net> (raw)
In-Reply-To: <20240703083129.95955-1-krzysztof.kozlowski@linaro.org>
On 7/3/24 01:31, Krzysztof Kozlowski wrote:
> Allocate memory, which is being freed at end of the scope, to make the
> code a bit simpler.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
> drivers/hwmon/dell-smm-hwmon.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c
> index 0362a13f6525..e72e26db6e10 100644
> --- a/drivers/hwmon/dell-smm-hwmon.c
> +++ b/drivers/hwmon/dell-smm-hwmon.c
> @@ -14,6 +14,7 @@
>
> #include <linux/acpi.h>
> #include <linux/capability.h>
> +#include <linux/cleanup.h>
> #include <linux/cpu.h>
> #include <linux/ctype.h>
> #include <linux/delay.h>
> @@ -1095,9 +1096,9 @@ static int dell_smm_init_cdev(struct device *dev, u8 fan_num)
> struct thermal_cooling_device *cdev;
> struct dell_smm_cooling_data *cdata;
> int ret = 0;
> - char *name;
>
> - name = kasprintf(GFP_KERNEL, "dell-smm-fan%u", fan_num + 1);
> + char *name __free(kfree) = kasprintf(GFP_KERNEL, "dell-smm-fan%u",
> + fan_num + 1);
> if (!name)
> return -ENOMEM;
>
> @@ -1115,8 +1116,6 @@ static int dell_smm_init_cdev(struct device *dev, u8 fan_num)
> ret = -ENOMEM;
> }
>
> - kfree(name);
> -
> return ret;
> }
>
If you really want to clean this up, just use
char name[32];
...
snprintf(name, sizeof(name), "dell-smm-fan%u", fan_num + 1);
I don't see the point of all this complexity.
Guenter
next prev parent reply other threads:[~2024-07-03 18:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-03 8:31 Krzysztof Kozlowski
2024-07-03 18:03 ` Christophe JAILLET
2024-07-03 18:52 ` Guenter Roeck [this message]
2024-07-03 19:16 ` Pali Rohár
2024-07-03 21:56 ` Guenter Roeck
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=982dc693-dbb2-41a7-ae0d-3b3c05c28117@roeck-us.net \
--to=linux@roeck-us.net \
--cc=jdelvare@suse.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pali@kernel.org \
/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®