Re: [PATCH] firmware_loader: introduce __free() cleanup hanler

From: Luis Chamberlain
Date: Thu Jan 25 2024 - 10:49:16 EST


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@xxxxxxxxx>

Acked-by: Luis Chamberalin <mcgrof@xxxxxxxxxx>

Luis