diff mbox series

[07/26] firmware: avoid pointless reference count bump

Message ID 20241124-work-cred-v1-7-f352241c3970@kernel.org (mailing list archive)
State New
Headers show
Series [01/26] tree-wide: s/override_creds()/override_creds_light(get_new_cred())/g | expand

Commit Message

Christian Brauner Nov. 24, 2024, 1:43 p.m. UTC
The creds are allocated via prepare_kernel_cred() which has already
taken a reference.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 drivers/base/firmware_loader/main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Amir Goldstein Nov. 24, 2024, 2:56 p.m. UTC | #1
On Sun, Nov 24, 2024 at 2:44 PM Christian Brauner <brauner@kernel.org> wrote:
>
> The creds are allocated via prepare_kernel_cred() which has already
> taken a reference.
>
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
>  drivers/base/firmware_loader/main.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
> index 96a2c3011ca82148b4ba547764a1f92e252dbf5f..740ef6223a62ca37e776d1558f840f09c7c46c95 100644
> --- a/drivers/base/firmware_loader/main.c
> +++ b/drivers/base/firmware_loader/main.c
> @@ -912,7 +912,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
>                 ret = -ENOMEM;
>                 goto out;
>         }
> -       old_cred = override_creds(get_new_cred(kern_cred));
> +       old_cred = override_creds(kern_cred);
>
>         ret = fw_get_filesystem_firmware(device, fw->priv, "", NULL);
>
> @@ -945,7 +945,6 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
>                 ret = assign_fw(fw, device);
>
>         put_cred(revert_creds(old_cred));
> -       put_cred(kern_cred);

This may seem like nit picking, but I think that:
        revert_creds(old_cred));
        put_cred(kern_cred);

Is nicer. It is more balanced and it is more consistent with the majority of
patches in this series which in a balanced manner remove both the
get_new_cred from the override_creds line and the put_cred from the
revert_creds line.

If someone wanted to, both old_cred and kern_cred could be converted
to use scoped cleanup handlers. This is more apparent when the cleanup
is explicit on the local kern_cred var.

The same comment applies to a few other patches in this series.

Thanks,
Amir.
diff mbox series

Patch

diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
index 96a2c3011ca82148b4ba547764a1f92e252dbf5f..740ef6223a62ca37e776d1558f840f09c7c46c95 100644
--- a/drivers/base/firmware_loader/main.c
+++ b/drivers/base/firmware_loader/main.c
@@ -912,7 +912,7 @@  _request_firmware(const struct firmware **firmware_p, const char *name,
 		ret = -ENOMEM;
 		goto out;
 	}
-	old_cred = override_creds(get_new_cred(kern_cred));
+	old_cred = override_creds(kern_cred);
 
 	ret = fw_get_filesystem_firmware(device, fw->priv, "", NULL);
 
@@ -945,7 +945,6 @@  _request_firmware(const struct firmware **firmware_p, const char *name,
 		ret = assign_fw(fw, device);
 
 	put_cred(revert_creds(old_cred));
-	put_cred(kern_cred);
 
 out:
 	if (ret < 0) {