diff mbox series

[09/26] target_core_configfs: avoid pointless cred reference count bump

Message ID 20241124-work-cred-v1-9-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/target/target_core_configfs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Al Viro Nov. 24, 2024, 6:26 p.m. UTC | #1
On Sun, Nov 24, 2024 at 02:43:55PM +0100, Christian Brauner wrote:
> The creds are allocated via prepare_kernel_cred() which has already
> taken a reference.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
>  drivers/target/target_core_configfs.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
> index ec7a5598719397da5cadfed12a05ca8eb81e46a9..d102ab79c56dd7977465f7455749e6e7a2c9fba1 100644
> --- a/drivers/target/target_core_configfs.c
> +++ b/drivers/target/target_core_configfs.c
> @@ -3756,10 +3756,9 @@ static int __init target_core_init_configfs(void)
>  		ret = -ENOMEM;
>  		goto out;
>  	}
> -	old_cred = override_creds(get_new_cred(kern_cred));
> +	old_cred = override_creds(kern_cred);
>  	target_init_dbroot();
>  	put_cred(revert_creds(old_cred));
> -	put_cred(kern_cred);

FWIW, I agree with Amir - 
 	revert_creds(old_cred);
	put_cred(kern_cred);
might be easier to follow.  In effect, you have two scopes here -
from prepare_kernel_cred() to put_cred() and, nested in it,
from override_creds() to revert_creds().

I'm not saying that __cleanup() is the right tool in those cases,
but the closing brackets of those scopes would be better off
separated.
Christian Brauner Nov. 25, 2024, 11:31 a.m. UTC | #2
On Sun, Nov 24, 2024 at 06:26:12PM +0000, Al Viro wrote:
> On Sun, Nov 24, 2024 at 02:43:55PM +0100, Christian Brauner wrote:
> > The creds are allocated via prepare_kernel_cred() which has already
> > taken a reference.
> > 
> > Signed-off-by: Christian Brauner <brauner@kernel.org>
> > ---
> >  drivers/target/target_core_configfs.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
> > index ec7a5598719397da5cadfed12a05ca8eb81e46a9..d102ab79c56dd7977465f7455749e6e7a2c9fba1 100644
> > --- a/drivers/target/target_core_configfs.c
> > +++ b/drivers/target/target_core_configfs.c
> > @@ -3756,10 +3756,9 @@ static int __init target_core_init_configfs(void)
> >  		ret = -ENOMEM;
> >  		goto out;
> >  	}
> > -	old_cred = override_creds(get_new_cred(kern_cred));
> > +	old_cred = override_creds(kern_cred);
> >  	target_init_dbroot();
> >  	put_cred(revert_creds(old_cred));
> > -	put_cred(kern_cred);
> 
> FWIW, I agree with Amir - 
>  	revert_creds(old_cred);
> 	put_cred(kern_cred);

Ok, done.
diff mbox series

Patch

diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index ec7a5598719397da5cadfed12a05ca8eb81e46a9..d102ab79c56dd7977465f7455749e6e7a2c9fba1 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -3756,10 +3756,9 @@  static int __init target_core_init_configfs(void)
 		ret = -ENOMEM;
 		goto out;
 	}
-	old_cred = override_creds(get_new_cred(kern_cred));
+	old_cred = override_creds(kern_cred);
 	target_init_dbroot();
 	put_cred(revert_creds(old_cred));
-	put_cred(kern_cred);
 
 	return 0;