* [PATCH] firmware_loader: introduce __free() cleanup hanler
@ 2024-01-17 8:33 Dmitry Torokhov
2024-01-25 15:48 ` Luis Chamberlain
0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Torokhov @ 2024-01-17 8:33 UTC (permalink / raw)
To: Luis Chamberlain; +Cc: Russ Weight, linux-kernel
Define cleanup handler using facilities from linux/cleanup.h to simplify
error handling in code using firmware loader. This will allow writing code
like this:
int driver_update_firmware(...)
{
const struct firmware *fw_entry __free(firmware) = NULL;
int error;
...
error = request_firmware(&fw_entry, fw_name, dev);
if (error) {
dev_err(dev, "failed to request firmware %s: %d",
fw_name, error);
return error;
}
error = check_firmware_valid(fw_entry);
if (error)
return error;
guard(mutex)(&instance->lock);
error = use_firmware(instance, fw);
if (error)
return error;
return 0;
}
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
If this is acceptable sticking it into an immutable branch would be very
helpful. Thanks!
include/linux/firmware.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/linux/firmware.h b/include/linux/firmware.h
index de7fea3bca51..2035a0d9cc86 100644
--- a/include/linux/firmware.h
+++ b/include/linux/firmware.h
@@ -4,6 +4,7 @@
#include <linux/types.h>
#include <linux/compiler.h>
+#include <linux/cleanup.h>
#include <linux/gfp.h>
#define FW_ACTION_NOUEVENT 0
@@ -196,4 +197,6 @@ static inline void firmware_upload_unregister(struct fw_upload *fw_upload)
int firmware_request_cache(struct device *device, const char *name);
+DEFINE_FREE(firmware, struct firmware *, release_firmware(_T))
+
#endif
--
2.43.0.381.gb435a96ce8-goog
--
Dmitry
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] firmware_loader: introduce __free() cleanup hanler
2024-01-17 8:33 [PATCH] firmware_loader: introduce __free() cleanup hanler Dmitry Torokhov
@ 2024-01-25 15:48 ` Luis Chamberlain
0 siblings, 0 replies; 2+ messages in thread
From: Luis Chamberlain @ 2024-01-25 15:48 UTC (permalink / raw)
To: Dmitry Torokhov, Greg Kroah-Hartman; +Cc: Russ Weight, linux-kernel
On Wed, Jan 17, 2024 at 12:33:07AM -0800, Dmitry Torokhov wrote:
> Define cleanup handler using facilities from linux/cleanup.h to simplify
> error handling in code using firmware loader. This will allow writing code
> like this:
>
> int driver_update_firmware(...)
> {
> const struct firmware *fw_entry __free(firmware) = NULL;
> int error;
>
> ...
> error = request_firmware(&fw_entry, fw_name, dev);
> if (error) {
> dev_err(dev, "failed to request firmware %s: %d",
> fw_name, error);
> return error;
> }
>
> error = check_firmware_valid(fw_entry);
> if (error)
> return error;
>
> guard(mutex)(&instance->lock);
>
> error = use_firmware(instance, fw);
> if (error)
> return error;
>
> return 0;
> }
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: Luis Chamberalin <mcgrof@kernel.org>
Luis
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-25 15:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-17 8:33 [PATCH] firmware_loader: introduce __free() cleanup hanler Dmitry Torokhov
2024-01-25 15:48 ` Luis Chamberlain
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.