Message ID | 20180704124137.13396-6-s.hauer@pengutronix.de |
---|---|
State | Superseded |
Delegated to: | Richard Weinberger |
Headers | show |
Series | UBIFS authentication support | expand |
On Wed, Jul 04, 2018 at 02:41:17PM +0200, Sascha Hauer wrote: > ubifs_lpt_lookup() starts by looking up the nth pnode in the LPT. We > already have this functionality in ubifs_pnode_lookup(). Use this > function rather than open coding its functionality. > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> > --- > fs/ubifs/lpt.c | 20 ++------------------ > 1 file changed, 2 insertions(+), 18 deletions(-) > > diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c > index 6cd6f23d4512..cde7b9484157 100644 > --- a/fs/ubifs/lpt.c > +++ b/fs/ubifs/lpt.c > @@ -1478,27 +1478,11 @@ struct ubifs_pnode *ubifs_pnode_lookup(struct ubifs_info *c, int i) > */ > struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum) > { > - int err, i, h, iip, shft; > - struct ubifs_nnode *nnode; > + int i, iip; > struct ubifs_pnode *pnode; > > - if (!c->nroot) { > - err = ubifs_read_nnode(c, NULL, 0); > - if (err) > - return ERR_PTR(err); > - } > - nnode = c->nroot; > i = lnum - c->main_first; > - shft = c->lpt_hght * UBIFS_LPT_FANOUT_SHIFT; > - for (h = 1; h < c->lpt_hght; h++) { > - iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1)); > - shft -= UBIFS_LPT_FANOUT_SHIFT; > - nnode = ubifs_get_nnode(c, nnode, iip); > - if (IS_ERR(nnode)) > - return ERR_CAST(nnode); > - } > - iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1)); > - pnode = ubifs_get_pnode(c, nnode, iip); > + pnode = ubifs_pnode_lookup(c, i); This should be ubifs_pnode_lookup(c, i >> UBIFS_LPT_FANOUT_SHIFT); Sascha
Am Montag, 13. August 2018, 08:31:27 CEST schrieb Sascha Hauer: > On Wed, Jul 04, 2018 at 02:41:17PM +0200, Sascha Hauer wrote: > > ubifs_lpt_lookup() starts by looking up the nth pnode in the LPT. We > > already have this functionality in ubifs_pnode_lookup(). Use this > > function rather than open coding its functionality. > > > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> > > --- > > fs/ubifs/lpt.c | 20 ++------------------ > > 1 file changed, 2 insertions(+), 18 deletions(-) > > > > diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c > > index 6cd6f23d4512..cde7b9484157 100644 > > --- a/fs/ubifs/lpt.c > > +++ b/fs/ubifs/lpt.c > > @@ -1478,27 +1478,11 @@ struct ubifs_pnode *ubifs_pnode_lookup(struct ubifs_info *c, int i) > > */ > > struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum) > > { > > - int err, i, h, iip, shft; > > - struct ubifs_nnode *nnode; > > + int i, iip; > > struct ubifs_pnode *pnode; > > > > - if (!c->nroot) { > > - err = ubifs_read_nnode(c, NULL, 0); > > - if (err) > > - return ERR_PTR(err); > > - } > > - nnode = c->nroot; > > i = lnum - c->main_first; > > - shft = c->lpt_hght * UBIFS_LPT_FANOUT_SHIFT; > > - for (h = 1; h < c->lpt_hght; h++) { > > - iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1)); > > - shft -= UBIFS_LPT_FANOUT_SHIFT; > > - nnode = ubifs_get_nnode(c, nnode, iip); > > - if (IS_ERR(nnode)) > > - return ERR_CAST(nnode); > > - } > > - iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1)); > > - pnode = ubifs_get_pnode(c, nnode, iip); > > + pnode = ubifs_pnode_lookup(c, i); > > This should be > > ubifs_pnode_lookup(c, i >> UBIFS_LPT_FANOUT_SHIFT); Can you please add a helper function for that? These shift games are always confusing and not easy to spot. Thanks, //richard
On Mon, Aug 13, 2018 at 08:34:00AM +0200, Richard Weinberger wrote: > Am Montag, 13. August 2018, 08:31:27 CEST schrieb Sascha Hauer: > > On Wed, Jul 04, 2018 at 02:41:17PM +0200, Sascha Hauer wrote: > > > ubifs_lpt_lookup() starts by looking up the nth pnode in the LPT. We > > > already have this functionality in ubifs_pnode_lookup(). Use this > > > function rather than open coding its functionality. > > > > > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> > > > --- > > > fs/ubifs/lpt.c | 20 ++------------------ > > > 1 file changed, 2 insertions(+), 18 deletions(-) > > > > > > diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c > > > index 6cd6f23d4512..cde7b9484157 100644 > > > --- a/fs/ubifs/lpt.c > > > +++ b/fs/ubifs/lpt.c > > > @@ -1478,27 +1478,11 @@ struct ubifs_pnode *ubifs_pnode_lookup(struct ubifs_info *c, int i) > > > */ > > > struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum) > > > { > > > - int err, i, h, iip, shft; > > > - struct ubifs_nnode *nnode; > > > + int i, iip; > > > struct ubifs_pnode *pnode; > > > > > > - if (!c->nroot) { > > > - err = ubifs_read_nnode(c, NULL, 0); > > > - if (err) > > > - return ERR_PTR(err); > > > - } > > > - nnode = c->nroot; > > > i = lnum - c->main_first; > > > - shft = c->lpt_hght * UBIFS_LPT_FANOUT_SHIFT; > > > - for (h = 1; h < c->lpt_hght; h++) { > > > - iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1)); > > > - shft -= UBIFS_LPT_FANOUT_SHIFT; > > > - nnode = ubifs_get_nnode(c, nnode, iip); > > > - if (IS_ERR(nnode)) > > > - return ERR_CAST(nnode); > > > - } > > > - iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1)); > > > - pnode = ubifs_get_pnode(c, nnode, iip); > > > + pnode = ubifs_pnode_lookup(c, i); > > > > This should be > > > > ubifs_pnode_lookup(c, i >> UBIFS_LPT_FANOUT_SHIFT); > > Can you please add a helper function for that? These shift games are > always confusing and not easy to spot. Do you have a suggestion for a helper function? lpt.c is full of rather non obvious arithmetic operations and I couldn't find a helper function that could be reused at least once in the code. I tried with: static int lnum_to_pnode_num(struct ubifs_info *c, int lnum) { return (lnum - c->main_first) >> UBIFS_LPT_FANOUT_SHIFT; } But I am not sure this really improves things Sascha
Am Montag, 13. August 2018, 10:12:38 CEST schrieb Sascha Hauer: > > Can you please add a helper function for that? These shift games are > > always confusing and not easy to spot. > > Do you have a suggestion for a helper function? lpt.c is full of rather > non obvious arithmetic operations and I couldn't find a helper function > that could be reused at least once in the code. > > I tried with: > > static int lnum_to_pnode_num(struct ubifs_info *c, int lnum) > { > return (lnum - c->main_first) >> UBIFS_LPT_FANOUT_SHIFT; > } > > But I am not sure this really improves things I had exactly such helpers in mind. The lpt code translates often LEB numbers in both direction. So, the helpers should have more than one user. Long story short, I don't force you to add such helper and such. Just thought while you are here you can try to make the code more readable. I think we both agree that lpt.c is not really review friendly. ;) Thanks, //richard
On Mon, Aug 13, 2018 at 8:31 AM Sascha Hauer <s.hauer@pengutronix.de> wrote: > > On Wed, Jul 04, 2018 at 02:41:17PM +0200, Sascha Hauer wrote: > > ubifs_lpt_lookup() starts by looking up the nth pnode in the LPT. We > > already have this functionality in ubifs_pnode_lookup(). Use this > > function rather than open coding its functionality. > > > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> > > --- > > fs/ubifs/lpt.c | 20 ++------------------ > > 1 file changed, 2 insertions(+), 18 deletions(-) > > > > diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c > > index 6cd6f23d4512..cde7b9484157 100644 > > --- a/fs/ubifs/lpt.c > > +++ b/fs/ubifs/lpt.c > > @@ -1478,27 +1478,11 @@ struct ubifs_pnode *ubifs_pnode_lookup(struct ubifs_info *c, int i) > > */ > > struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum) > > { > > - int err, i, h, iip, shft; > > - struct ubifs_nnode *nnode; > > + int i, iip; > > struct ubifs_pnode *pnode; > > > > - if (!c->nroot) { > > - err = ubifs_read_nnode(c, NULL, 0); > > - if (err) > > - return ERR_PTR(err); > > - } > > - nnode = c->nroot; > > i = lnum - c->main_first; > > - shft = c->lpt_hght * UBIFS_LPT_FANOUT_SHIFT; > > - for (h = 1; h < c->lpt_hght; h++) { > > - iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1)); > > - shft -= UBIFS_LPT_FANOUT_SHIFT; > > - nnode = ubifs_get_nnode(c, nnode, iip); > > - if (IS_ERR(nnode)) > > - return ERR_CAST(nnode); > > - } > > - iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1)); > > - pnode = ubifs_get_pnode(c, nnode, iip); > > + pnode = ubifs_pnode_lookup(c, i); > > This should be > > ubifs_pnode_lookup(c, i >> UBIFS_LPT_FANOUT_SHIFT); FWIW, I've rebased the whole series to Linus as of today, the merge window introduced some minor conflicts. http://git.infradead.org/users/rw/linux.git/shortlog/refs/heads/ubifs_auth_wip The above fix is included. Thanks, //richard
diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c index 6cd6f23d4512..cde7b9484157 100644 --- a/fs/ubifs/lpt.c +++ b/fs/ubifs/lpt.c @@ -1478,27 +1478,11 @@ struct ubifs_pnode *ubifs_pnode_lookup(struct ubifs_info *c, int i) */ struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum) { - int err, i, h, iip, shft; - struct ubifs_nnode *nnode; + int i, iip; struct ubifs_pnode *pnode; - if (!c->nroot) { - err = ubifs_read_nnode(c, NULL, 0); - if (err) - return ERR_PTR(err); - } - nnode = c->nroot; i = lnum - c->main_first; - shft = c->lpt_hght * UBIFS_LPT_FANOUT_SHIFT; - for (h = 1; h < c->lpt_hght; h++) { - iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1)); - shft -= UBIFS_LPT_FANOUT_SHIFT; - nnode = ubifs_get_nnode(c, nnode, iip); - if (IS_ERR(nnode)) - return ERR_CAST(nnode); - } - iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1)); - pnode = ubifs_get_pnode(c, nnode, iip); + pnode = ubifs_pnode_lookup(c, i); if (IS_ERR(pnode)) return ERR_CAST(pnode); iip = (i & (UBIFS_LPT_FANOUT - 1));
ubifs_lpt_lookup() starts by looking up the nth pnode in the LPT. We already have this functionality in ubifs_pnode_lookup(). Use this function rather than open coding its functionality. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> --- fs/ubifs/lpt.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-)