diff mbox series

[18/26] ovl: avoid pointless cred reference count bump

Message ID 20241124-work-cred-v1-18-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:44 p.m. UTC
No need for the extra reference count bump.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/overlayfs/copy_up.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Amir Goldstein Nov. 24, 2024, 2:59 p.m. UTC | #1
On Sun, Nov 24, 2024 at 2:44 PM Christian Brauner <brauner@kernel.org> wrote:
>
> No need for the extra reference count bump.
>
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
>  fs/overlayfs/copy_up.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
> index 439bd9a5ceecc4d2f4dc5dfda7cea14c3d9411ba..39f08531abc7e99c32e709a46988939f072a9abe 100644
> --- a/fs/overlayfs/copy_up.c
> +++ b/fs/overlayfs/copy_up.c
> @@ -741,17 +741,15 @@ static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)
>                 return err;
>
>         if (cc->new)
> -               cc->old = override_creds(get_new_cred(cc->new));
> +               cc->old = override_creds(cc->new);
>
>         return 0;
>  }
>
>  static void ovl_revert_cu_creds(struct ovl_cu_creds *cc)
>  {
> -       if (cc->new) {
> +       if (cc->new)
>                 put_cred(revert_creds(cc->old));
> -               put_cred(cc->new);
> -       }

Same comment here, I think this will read more clearly as
               revert_creds(cc->old));
               put_cred(cc->new);

and better reflects the counterpart of ovl_prep_cu_creds().

Thanks,
Amir.
Christian Brauner Nov. 25, 2024, 11:30 a.m. UTC | #2
On Sun, Nov 24, 2024 at 03:59:40PM +0100, Amir Goldstein wrote:
> On Sun, Nov 24, 2024 at 2:44 PM Christian Brauner <brauner@kernel.org> wrote:
> >
> > No need for the extra reference count bump.
> >
> > Signed-off-by: Christian Brauner <brauner@kernel.org>
> > ---
> >  fs/overlayfs/copy_up.c | 6 ++----
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
> > index 439bd9a5ceecc4d2f4dc5dfda7cea14c3d9411ba..39f08531abc7e99c32e709a46988939f072a9abe 100644
> > --- a/fs/overlayfs/copy_up.c
> > +++ b/fs/overlayfs/copy_up.c
> > @@ -741,17 +741,15 @@ static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)
> >                 return err;
> >
> >         if (cc->new)
> > -               cc->old = override_creds(get_new_cred(cc->new));
> > +               cc->old = override_creds(cc->new);
> >
> >         return 0;
> >  }
> >
> >  static void ovl_revert_cu_creds(struct ovl_cu_creds *cc)
> >  {
> > -       if (cc->new) {
> > +       if (cc->new)
> >                 put_cred(revert_creds(cc->old));
> > -               put_cred(cc->new);
> > -       }
> 
> Same comment here, I think this will read more clearly as
>                revert_creds(cc->old));
>                put_cred(cc->new);
> 
> and better reflects the counterpart of ovl_prep_cu_creds().

Ok, done.
diff mbox series

Patch

diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index 439bd9a5ceecc4d2f4dc5dfda7cea14c3d9411ba..39f08531abc7e99c32e709a46988939f072a9abe 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -741,17 +741,15 @@  static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)
 		return err;
 
 	if (cc->new)
-		cc->old = override_creds(get_new_cred(cc->new));
+		cc->old = override_creds(cc->new);
 
 	return 0;
 }
 
 static void ovl_revert_cu_creds(struct ovl_cu_creds *cc)
 {
-	if (cc->new) {
+	if (cc->new)
 		put_cred(revert_creds(cc->old));
-		put_cred(cc->new);
-	}
 }
 
 /*